use of org.locationtech.geowave.core.store.api.AggregationQueryBuilder in project geowave by locationtech.
the class SelectStatement method execute.
@Override
public ResultSet execute(final String... authorizations) {
final String typeName = adapter.getTypeName();
if (isAggregation()) {
final AggregationQueryBuilder<PersistableList, List<Object>, T, ?> bldr = AggregationQueryBuilder.newBuilder();
bldr.setAuthorizations(authorizations);
if (filter != null) {
bldr.filter(filter);
}
if (limit != null) {
bldr.limit(limit);
}
final CompositeAggregation<T> composite = new CompositeAggregation<>();
final List<String> columnNames = Lists.newArrayListWithCapacity(selectors.size());
final List<Class<?>> columnTypes = Lists.newArrayListWithCapacity(selectors.size());
for (final Selector selector : selectors) {
final AggregationSelector aggregation = (AggregationSelector) selector;
final AggregationFunction<?> function = GWQLExtensionRegistry.instance().getAggregationFunction(aggregation.functionName());
if (function == null) {
throw new RuntimeException("No aggregation function called '" + aggregation.functionName() + "' was found.");
}
composite.add(function.getAggregation(adapter, aggregation.functionArgs()));
columnNames.add(selector.name());
columnTypes.add(function.getReturnType());
}
bldr.aggregate(typeName, composite);
return new SingletonResultSet(columnNames, columnTypes, dataStore.aggregate(bldr.build()));
} else {
final QueryBuilder<T, ?> bldr = QueryBuilder.newBuilder(adapter.getDataClass()).addTypeName(typeName);
bldr.setAuthorizations(authorizations);
if (filter != null) {
bldr.filter(filter);
}
if ((selectors != null) && !selectors.isEmpty()) {
final Set<String> usedAttributes = Sets.newHashSet();
selectors.forEach(s -> usedAttributes.add(((ColumnSelector) s).columnName()));
if (filter != null) {
filter.addReferencedFields(usedAttributes);
}
for (final String attribute : usedAttributes) {
if (adapter.getFieldDescriptor(attribute) == null) {
throw new RuntimeException("No column named " + attribute + " was found in " + typeName);
}
}
bldr.subsetFields(typeName, usedAttributes.toArray(new String[usedAttributes.size()]));
} else {
selectors = Lists.transform(Arrays.asList(adapter.getFieldDescriptors()), f -> new ColumnSelector(f.fieldName()));
}
if (limit != null) {
bldr.limit(limit);
}
return new AdapterEntryResultSet<>(selectors, adapter, dataStore.query(bldr.build()));
}
}
Aggregations