Search in sources :

Example 1 with ColumnSelector

use of org.locationtech.geowave.core.store.query.gwql.ColumnSelector 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()));
    }
}
Also used : Arrays(java.util.Arrays) AggregationSelector(org.locationtech.geowave.core.store.query.gwql.AggregationSelector) ColumnSelector(org.locationtech.geowave.core.store.query.gwql.ColumnSelector) DataStore(org.locationtech.geowave.core.store.api.DataStore) AggregationQueryBuilder(org.locationtech.geowave.core.store.api.AggregationQueryBuilder) Set(java.util.Set) PersistableList(org.locationtech.geowave.core.index.persist.PersistableList) Sets(com.google.common.collect.Sets) AggregationFunction(org.locationtech.geowave.core.store.query.gwql.function.aggregation.AggregationFunction) List(java.util.List) ResultSet(org.locationtech.geowave.core.store.query.gwql.ResultSet) SingletonResultSet(org.locationtech.geowave.core.store.query.gwql.SingletonResultSet) Selector(org.locationtech.geowave.core.store.query.gwql.Selector) Lists(com.google.common.collect.Lists) SelectorType(org.locationtech.geowave.core.store.query.gwql.Selector.SelectorType) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) GWQLExtensionRegistry(org.locationtech.geowave.core.store.query.gwql.GWQLExtensionRegistry) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) AdapterEntryResultSet(org.locationtech.geowave.core.store.query.gwql.AdapterEntryResultSet) CompositeAggregation(org.locationtech.geowave.core.store.query.aggregate.CompositeAggregation) Nullable(javax.annotation.Nullable) AggregationSelector(org.locationtech.geowave.core.store.query.gwql.AggregationSelector) CompositeAggregation(org.locationtech.geowave.core.store.query.aggregate.CompositeAggregation) AdapterEntryResultSet(org.locationtech.geowave.core.store.query.gwql.AdapterEntryResultSet) PersistableList(org.locationtech.geowave.core.index.persist.PersistableList) ColumnSelector(org.locationtech.geowave.core.store.query.gwql.ColumnSelector) PersistableList(org.locationtech.geowave.core.index.persist.PersistableList) List(java.util.List) SingletonResultSet(org.locationtech.geowave.core.store.query.gwql.SingletonResultSet) AggregationSelector(org.locationtech.geowave.core.store.query.gwql.AggregationSelector) ColumnSelector(org.locationtech.geowave.core.store.query.gwql.ColumnSelector) Selector(org.locationtech.geowave.core.store.query.gwql.Selector)

Aggregations

Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 PersistableList (org.locationtech.geowave.core.index.persist.PersistableList)1 AggregationQueryBuilder (org.locationtech.geowave.core.store.api.AggregationQueryBuilder)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 DataTypeAdapter (org.locationtech.geowave.core.store.api.DataTypeAdapter)1 QueryBuilder (org.locationtech.geowave.core.store.api.QueryBuilder)1 CompositeAggregation (org.locationtech.geowave.core.store.query.aggregate.CompositeAggregation)1 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)1 AdapterEntryResultSet (org.locationtech.geowave.core.store.query.gwql.AdapterEntryResultSet)1 AggregationSelector (org.locationtech.geowave.core.store.query.gwql.AggregationSelector)1 ColumnSelector (org.locationtech.geowave.core.store.query.gwql.ColumnSelector)1 GWQLExtensionRegistry (org.locationtech.geowave.core.store.query.gwql.GWQLExtensionRegistry)1 ResultSet (org.locationtech.geowave.core.store.query.gwql.ResultSet)1 Selector (org.locationtech.geowave.core.store.query.gwql.Selector)1 SelectorType (org.locationtech.geowave.core.store.query.gwql.Selector.SelectorType)1