Search in sources :

Example 1 with QueryBuilder

use of org.locationtech.geowave.core.store.api.QueryBuilder in project geowave by locationtech.

the class GeoWaveEnumIndexIT method getResults.

private void getResults(final EnumSearch search) {
    final DataStore ds = dataStoreOptions.createDataStore();
    final Set<String> expectedResults = new HashSet<>();
    final QueryBuilder queryBldr = QueryBuilder.newBuilder().addTypeName(TYPE_NAME);
    // query everything and apply manual filtering
    final AtomicInteger everythingResults = new AtomicInteger(0);
    try (final CloseableIterator<SimpleFeature> it = ds.query((Query) queryBldr.build())) {
        it.forEachRemaining(f -> {
            final String timezone = f.getAttribute(TIMEZONE_ATTR_NAME).toString();
            if (search.getSearchTerm().equals(timezone)) {
                expectedResults.add(f.getID());
            }
            everythingResults.incrementAndGet();
        });
    }
    // ensure that the full set of results exceeds the expected results (ie. that we successfully
    // queried everything in the previous step)
    Assert.assertTrue(everythingResults.get() > expectedResults.size());
    LOGGER.info("Expecting '" + expectedResults.size() + "' in timezone " + search.getSearchTerm());
    queryBldr.indexName(TEST_ENUM_INDEX_NAME);
    try (final CloseableIterator<SimpleFeature> it = ds.query((Query) queryBldr.constraints(queryBldr.constraintsFactory().customConstraints(search)).build())) {
        it.forEachRemaining(f -> {
            final String timezone = f.getAttribute(TIMEZONE_ATTR_NAME).toString();
            Assert.assertEquals(search.getSearchTerm(), timezone);
            expectedResults.remove(f.getID());
        });
    }
    Assert.assertTrue(expectedResults.isEmpty());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataStore(org.locationtech.geowave.core.store.api.DataStore) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature) HashSet(java.util.HashSet)

Example 2 with QueryBuilder

use of org.locationtech.geowave.core.store.api.QueryBuilder in project geowave by locationtech.

the class BaseDataStore method copyTo.

@Override
public void copyTo(final DataStore other, final Query<?> query) {
    // check for 'everything' query
    if (query == null) {
        copyTo(other);
        return;
    }
    final String[] typeNames = query.getDataTypeQueryOptions().getTypeNames();
    final String indexName = query.getIndexQueryOptions().getIndexName();
    final boolean isAllIndices = query.getIndexQueryOptions().isAllIndices();
    final List<DataTypeAdapter<?>> typesToCopy;
    // if typeNames are not specified, then it means 'everything' as well
    if (((typeNames == null) || (typeNames.length == 0))) {
        if ((query.getQueryConstraints() == null) || (query.getQueryConstraints() instanceof EverythingQuery)) {
            copyTo(other);
            return;
        } else {
            typesToCopy = Arrays.asList(getTypes());
        }
    } else {
        // make sure the types requested exist in the source store (this)
        // before trying to copy!
        final DataTypeAdapter<?>[] sourceTypes = getTypes();
        typesToCopy = new ArrayList<>();
        for (int i = 0; i < typeNames.length; i++) {
            boolean found = false;
            for (int k = 0; k < sourceTypes.length; k++) {
                if (sourceTypes[k].getTypeName().compareTo(typeNames[i]) == 0) {
                    found = true;
                    typesToCopy.add(sourceTypes[k]);
                    break;
                }
            }
            if (!found) {
                throw new IllegalArgumentException("Some type names specified in the query do not exist in the source database and thus cannot be copied.");
            }
        }
    }
    // if there is an index requested in the query, make sure it exists in
    // the source store before trying to copy as well!
    final Index[] sourceIndices = getIndices();
    Index indexToCopy = null;
    if (!isAllIndices) {
        // just add the one index specified by the query
        // first make sure source index exists though
        boolean found = false;
        for (int i = 0; i < sourceIndices.length; i++) {
            if (sourceIndices[i].getName().compareTo(indexName) == 0) {
                found = true;
                indexToCopy = sourceIndices[i];
                break;
            }
        }
        if (!found) {
            throw new IllegalArgumentException("The index specified in the query does not exist in the source database and thus cannot be copied.");
        }
        // also make sure the types/index mapping for the query are legit
        for (int i = 0; i < typeNames.length; i++) {
            final short adapterId = internalAdapterStore.getAdapterId(typeNames[i]);
            final AdapterToIndexMapping[] indexMappings = indexMappingStore.getIndicesForAdapter(adapterId);
            found = false;
            for (int k = 0; k < indexMappings.length; k++) {
                if (indexMappings[k].getIndexName().compareTo(indexName) == 0) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new IllegalArgumentException("The index " + indexName + " and the type " + typeNames[i] + " specified by the query are not associated in the source database");
            }
        }
    }
    // add all the types that the destination store doesn't have yet
    final DataTypeAdapter<?>[] destTypes = other.getTypes();
    for (int i = 0; i < typesToCopy.size(); i++) {
        boolean found = false;
        for (int k = 0; k < destTypes.length; k++) {
            if (destTypes[k].getTypeName().compareTo(typesToCopy.get(i).getTypeName()) == 0) {
                found = true;
                break;
            }
        }
        if (!found) {
            other.addType(typesToCopy.get(i));
        }
    }
    // add all the indices that the destination store doesn't have yet
    if (isAllIndices) {
        // in this case, all indices from the types requested by the query
        for (int i = 0; i < typesToCopy.size(); i++) {
            final String typeName = typesToCopy.get(i).getTypeName();
            final short adapterId = internalAdapterStore.getAdapterId(typeName);
            final AdapterToIndexMapping[] indexMappings = indexMappingStore.getIndicesForAdapter(adapterId);
            final Index[] indices = Arrays.stream(indexMappings).map(mapping -> mapping.getIndex(indexStore)).toArray(Index[]::new);
            other.addIndex(typeName, indices);
            final QueryBuilder<?, ?> qb = QueryBuilder.newBuilder().addTypeName(typeName).constraints(query.getQueryConstraints());
            try (CloseableIterator<?> it = query(qb.build())) {
                try (Writer<Object> writer = other.createWriter(typeName)) {
                    while (it.hasNext()) {
                        writer.write(it.next());
                    }
                }
            }
        }
    } else {
        // query
        for (int i = 0; i < typesToCopy.size(); i++) {
            other.addIndex(typesToCopy.get(i).getTypeName(), indexToCopy);
        }
        // we can write appropriately
        for (int k = 0; k < typesToCopy.size(); k++) {
            final InternalDataAdapter<?> adapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(typesToCopy.get(k).getTypeName()));
            final QueryBuilder<?, ?> qb = QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(indexToCopy.getName()).constraints(query.getQueryConstraints());
            try (CloseableIterator<?> it = query(qb.build())) {
                try (Writer<Object> writer = other.createWriter(adapter.getTypeName())) {
                    while (it.hasNext()) {
                        writer.write(it.next());
                    }
                }
            }
        }
    }
}
Also used : FieldVisibilityCountValue(org.locationtech.geowave.core.store.statistics.index.FieldVisibilityCountStatistic.FieldVisibilityCountValue) Arrays(java.util.Arrays) MemoryPersistentAdapterStore(org.locationtech.geowave.core.store.memory.MemoryPersistentAdapterStore) Maps(com.beust.jcommander.internal.Maps) IndexDependentDataAdapter(org.locationtech.geowave.core.store.adapter.IndexDependentDataAdapter) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) PrefixIdQuery(org.locationtech.geowave.core.store.query.constraints.PrefixIdQuery) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) DataIndexReaderParamsBuilder(org.locationtech.geowave.core.store.operations.DataIndexReaderParamsBuilder) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Persistable(org.locationtech.geowave.core.index.persist.Persistable) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) DataStoreUtils(org.locationtech.geowave.core.store.util.DataStoreUtils) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) Query(org.locationtech.geowave.core.store.api.Query) StatisticQuery(org.locationtech.geowave.core.store.api.StatisticQuery) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) Set(java.util.Set) ByteArrayConstraints(org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints) IngestCallbackList(org.locationtech.geowave.core.store.callback.IngestCallbackList) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) StatisticUpdateCallback(org.locationtech.geowave.core.store.statistics.StatisticUpdateCallback) InternalStatisticsHelper(org.locationtech.geowave.core.store.statistics.InternalStatisticsHelper) IndexStatisticQuery(org.locationtech.geowave.core.store.statistics.query.IndexStatisticQuery) DeleteOtherIndicesCallback(org.locationtech.geowave.core.store.callback.DeleteOtherIndicesCallback) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) ByteArray(org.locationtech.geowave.core.index.ByteArray) DataStoreProperty(org.locationtech.geowave.core.store.DataStoreProperty) StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) DeleteCallbackList(org.locationtech.geowave.core.store.callback.DeleteCallbackList) BinConstraints(org.locationtech.geowave.core.store.api.BinConstraints) GeoWaveRowIteratorTransformer(org.locationtech.geowave.core.store.entities.GeoWaveRowIteratorTransformer) AdapterAndIndexBasedAggregation(org.locationtech.geowave.core.store.query.aggregate.AdapterAndIndexBasedAggregation) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) PropertyStore(org.locationtech.geowave.core.store.PropertyStore) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) DataStore(org.locationtech.geowave.core.store.api.DataStore) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) IOException(java.io.IOException) MemoryAdapterIndexMappingStore(org.locationtech.geowave.core.store.memory.MemoryAdapterIndexMappingStore) DataStoreOptions(org.locationtech.geowave.core.store.DataStoreOptions) Writer(org.locationtech.geowave.core.store.api.Writer) IndexCompositeWriter(org.locationtech.geowave.core.store.index.writer.IndexCompositeWriter) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) DedupeFilter(org.locationtech.geowave.core.store.query.filter.DedupeFilter) DifferingVisibilityCountValue(org.locationtech.geowave.core.store.statistics.index.DifferingVisibilityCountStatistic.DifferingVisibilityCountValue) LoggerFactory(org.slf4j.LoggerFactory) Aggregation(org.locationtech.geowave.core.store.api.Aggregation) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) ResultSet(org.locationtech.geowave.core.store.query.gwql.ResultSet) GeoWaveRowMergingTransform(org.locationtech.geowave.core.store.entities.GeoWaveRowMergingTransform) DataIdRangeQuery(org.locationtech.geowave.core.store.query.constraints.DataIdRangeQuery) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatisticQuery(org.locationtech.geowave.core.store.statistics.query.FieldStatisticQuery) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) BaseDataStoreIngestDriver(org.locationtech.geowave.core.store.ingest.BaseDataStoreIngestDriver) GWQLParser(org.locationtech.geowave.core.store.query.gwql.parse.GWQLParser) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) RowReader(org.locationtech.geowave.core.store.operations.RowReader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Collectors(java.util.stream.Collectors) ScanCallback(org.locationtech.geowave.core.store.callback.ScanCallback) DataTypeStatisticQuery(org.locationtech.geowave.core.store.statistics.query.DataTypeStatisticQuery) IndependentAdapterIndexWriter(org.locationtech.geowave.core.store.index.writer.IndependentAdapterIndexWriter) Sets(com.google.common.collect.Sets) List(java.util.List) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) Entry(java.util.Map.Entry) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) DataIndexUtils(org.locationtech.geowave.core.store.base.dataidx.DataIndexUtils) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) InsertionIdQuery(org.locationtech.geowave.core.store.query.constraints.InsertionIdQuery) NativeEntryIteratorWrapper(org.locationtech.geowave.core.store.util.NativeEntryIteratorWrapper) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) Index(org.locationtech.geowave.core.store.api.Index) Logger(org.slf4j.Logger) IngestOptions(org.locationtech.geowave.core.store.api.IngestOptions) IngestCallback(org.locationtech.geowave.core.store.callback.IngestCallback) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DuplicateDeletionCallback(org.locationtech.geowave.core.store.callback.DuplicateDeletionCallback) Closeable(java.io.Closeable) TypeConstraintQuery(org.locationtech.geowave.core.store.query.constraints.TypeConstraintQuery) AdapterAndIndexBasedQueryConstraints(org.locationtech.geowave.core.store.query.constraints.AdapterAndIndexBasedQueryConstraints) EverythingQuery(org.locationtech.geowave.core.store.query.constraints.EverythingQuery) Collections(java.util.Collections) EverythingQuery(org.locationtech.geowave.core.store.query.constraints.EverythingQuery) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index)

Example 3 with QueryBuilder

use of org.locationtech.geowave.core.store.api.QueryBuilder in project geowave by locationtech.

the class BaseDataStore method copyTo.

@Override
public void copyTo(final DataStore other) {
    if (other instanceof BaseDataStore) {
        // efficiently copy underlying GeoWaveRow and GeoWaveMetadata
        for (final MetadataType metadataType : MetadataType.values()) {
            try (MetadataWriter writer = ((BaseDataStore) other).baseOperations.createMetadataWriter(metadataType)) {
                final MetadataReader reader = baseOperations.createMetadataReader(metadataType);
                try (CloseableIterator<GeoWaveMetadata> it = reader.query(new MetadataQuery())) {
                    while (it.hasNext()) {
                        writer.write(it.next());
                    }
                }
            } catch (final Exception e) {
                LOGGER.error("Unable to write metadata on copy", e);
            }
        }
        final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
        for (final InternalDataAdapter<?> adapter : adapters) {
            final AdapterToIndexMapping[] mappings = indexMappingStore.getIndicesForAdapter(adapter.getAdapterId());
            for (final AdapterToIndexMapping mapping : mappings) {
                final Index index = mapping.getIndex(indexStore);
                final boolean rowMerging = BaseDataStoreUtils.isRowMerging(adapter);
                final ReaderParamsBuilder<GeoWaveRow> bldr = new ReaderParamsBuilder<>(index, adapterStore, indexMappingStore, internalAdapterStore, rowMerging ? new GeoWaveRowMergingTransform(BaseDataStoreUtils.getRowMergingAdapter(adapter), adapter.getAdapterId()) : GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER);
                bldr.adapterIds(new short[] { adapter.getAdapterId() });
                bldr.isClientsideRowMerging(rowMerging);
                try (RowReader<GeoWaveRow> reader = baseOperations.createReader(bldr.build())) {
                    try (RowWriter writer = ((BaseDataStore) other).baseOperations.createWriter(index, adapter)) {
                        while (reader.hasNext()) {
                            writer.write(reader.next());
                        }
                    }
                } catch (final Exception e) {
                    LOGGER.error("Unable to write metadata on copy", e);
                }
            }
        }
    } else {
        final DataTypeAdapter<?>[] sourceTypes = getTypes();
        // add all the types that the destination store doesn't have yet
        final DataTypeAdapter<?>[] destTypes = other.getTypes();
        for (int i = 0; i < sourceTypes.length; i++) {
            boolean found = false;
            for (int k = 0; k < destTypes.length; k++) {
                if (destTypes[k].getTypeName().compareTo(sourceTypes[i].getTypeName()) == 0) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                other.addType(sourceTypes[i]);
            }
        }
        // add the indices for each type
        for (int i = 0; i < sourceTypes.length; i++) {
            final String typeName = sourceTypes[i].getTypeName();
            final short adapterId = internalAdapterStore.getAdapterId(typeName);
            final AdapterToIndexMapping[] indexMappings = indexMappingStore.getIndicesForAdapter(adapterId);
            final Index[] indices = Arrays.stream(indexMappings).map(mapping -> mapping.getIndex(indexStore)).toArray(Index[]::new);
            other.addIndex(typeName, indices);
            final QueryBuilder<?, ?> qb = QueryBuilder.newBuilder().addTypeName(typeName);
            try (CloseableIterator<?> it = query(qb.build())) {
                try (final Writer<Object> writer = other.createWriter(typeName)) {
                    while (it.hasNext()) {
                        writer.write(it.next());
                    }
                }
            }
        }
    }
}
Also used : FieldVisibilityCountValue(org.locationtech.geowave.core.store.statistics.index.FieldVisibilityCountStatistic.FieldVisibilityCountValue) Arrays(java.util.Arrays) MemoryPersistentAdapterStore(org.locationtech.geowave.core.store.memory.MemoryPersistentAdapterStore) Maps(com.beust.jcommander.internal.Maps) IndexDependentDataAdapter(org.locationtech.geowave.core.store.adapter.IndexDependentDataAdapter) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) PrefixIdQuery(org.locationtech.geowave.core.store.query.constraints.PrefixIdQuery) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) DataIndexReaderParamsBuilder(org.locationtech.geowave.core.store.operations.DataIndexReaderParamsBuilder) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Persistable(org.locationtech.geowave.core.index.persist.Persistable) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) DataStoreUtils(org.locationtech.geowave.core.store.util.DataStoreUtils) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) Query(org.locationtech.geowave.core.store.api.Query) StatisticQuery(org.locationtech.geowave.core.store.api.StatisticQuery) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) Set(java.util.Set) ByteArrayConstraints(org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints) IngestCallbackList(org.locationtech.geowave.core.store.callback.IngestCallbackList) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) StatisticUpdateCallback(org.locationtech.geowave.core.store.statistics.StatisticUpdateCallback) InternalStatisticsHelper(org.locationtech.geowave.core.store.statistics.InternalStatisticsHelper) IndexStatisticQuery(org.locationtech.geowave.core.store.statistics.query.IndexStatisticQuery) DeleteOtherIndicesCallback(org.locationtech.geowave.core.store.callback.DeleteOtherIndicesCallback) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) ByteArray(org.locationtech.geowave.core.index.ByteArray) DataStoreProperty(org.locationtech.geowave.core.store.DataStoreProperty) StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) DeleteCallbackList(org.locationtech.geowave.core.store.callback.DeleteCallbackList) BinConstraints(org.locationtech.geowave.core.store.api.BinConstraints) GeoWaveRowIteratorTransformer(org.locationtech.geowave.core.store.entities.GeoWaveRowIteratorTransformer) AdapterAndIndexBasedAggregation(org.locationtech.geowave.core.store.query.aggregate.AdapterAndIndexBasedAggregation) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) PropertyStore(org.locationtech.geowave.core.store.PropertyStore) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) DataStore(org.locationtech.geowave.core.store.api.DataStore) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) IOException(java.io.IOException) MemoryAdapterIndexMappingStore(org.locationtech.geowave.core.store.memory.MemoryAdapterIndexMappingStore) DataStoreOptions(org.locationtech.geowave.core.store.DataStoreOptions) Writer(org.locationtech.geowave.core.store.api.Writer) IndexCompositeWriter(org.locationtech.geowave.core.store.index.writer.IndexCompositeWriter) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) DedupeFilter(org.locationtech.geowave.core.store.query.filter.DedupeFilter) DifferingVisibilityCountValue(org.locationtech.geowave.core.store.statistics.index.DifferingVisibilityCountStatistic.DifferingVisibilityCountValue) LoggerFactory(org.slf4j.LoggerFactory) Aggregation(org.locationtech.geowave.core.store.api.Aggregation) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) ResultSet(org.locationtech.geowave.core.store.query.gwql.ResultSet) GeoWaveRowMergingTransform(org.locationtech.geowave.core.store.entities.GeoWaveRowMergingTransform) DataIdRangeQuery(org.locationtech.geowave.core.store.query.constraints.DataIdRangeQuery) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatisticQuery(org.locationtech.geowave.core.store.statistics.query.FieldStatisticQuery) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) BaseDataStoreIngestDriver(org.locationtech.geowave.core.store.ingest.BaseDataStoreIngestDriver) GWQLParser(org.locationtech.geowave.core.store.query.gwql.parse.GWQLParser) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) RowReader(org.locationtech.geowave.core.store.operations.RowReader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Collectors(java.util.stream.Collectors) ScanCallback(org.locationtech.geowave.core.store.callback.ScanCallback) DataTypeStatisticQuery(org.locationtech.geowave.core.store.statistics.query.DataTypeStatisticQuery) IndependentAdapterIndexWriter(org.locationtech.geowave.core.store.index.writer.IndependentAdapterIndexWriter) Sets(com.google.common.collect.Sets) List(java.util.List) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) Entry(java.util.Map.Entry) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) DataIndexUtils(org.locationtech.geowave.core.store.base.dataidx.DataIndexUtils) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) InsertionIdQuery(org.locationtech.geowave.core.store.query.constraints.InsertionIdQuery) NativeEntryIteratorWrapper(org.locationtech.geowave.core.store.util.NativeEntryIteratorWrapper) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) Index(org.locationtech.geowave.core.store.api.Index) Logger(org.slf4j.Logger) IngestOptions(org.locationtech.geowave.core.store.api.IngestOptions) IngestCallback(org.locationtech.geowave.core.store.callback.IngestCallback) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DuplicateDeletionCallback(org.locationtech.geowave.core.store.callback.DuplicateDeletionCallback) Closeable(java.io.Closeable) TypeConstraintQuery(org.locationtech.geowave.core.store.query.constraints.TypeConstraintQuery) AdapterAndIndexBasedQueryConstraints(org.locationtech.geowave.core.store.query.constraints.AdapterAndIndexBasedQueryConstraints) EverythingQuery(org.locationtech.geowave.core.store.query.constraints.EverythingQuery) Collections(java.util.Collections) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) Index(org.locationtech.geowave.core.store.api.Index) RowWriter(org.locationtech.geowave.core.store.operations.RowWriter) DataIndexReaderParamsBuilder(org.locationtech.geowave.core.store.operations.DataIndexReaderParamsBuilder) ReaderParamsBuilder(org.locationtech.geowave.core.store.operations.ReaderParamsBuilder) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) IOException(java.io.IOException) MetadataWriter(org.locationtech.geowave.core.store.operations.MetadataWriter) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) GeoWaveRowMergingTransform(org.locationtech.geowave.core.store.entities.GeoWaveRowMergingTransform)

Example 4 with QueryBuilder

use of org.locationtech.geowave.core.store.api.QueryBuilder 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)

Example 5 with QueryBuilder

use of org.locationtech.geowave.core.store.api.QueryBuilder in project geowave by locationtech.

the class GeoWaveTextIndexIT method getResults.

private Set<String> getResults(final TextSearch search) {
    final DataStore ds = dataStoreOptions.createDataStore();
    final Set<String> results = new HashSet<>();
    final QueryBuilder queryBldr = QueryBuilder.newBuilder().addTypeName(TYPE_NAME).indexName(TEST_TEXT_INDEX_NAME);
    try (final CloseableIterator<SimpleFeature> it = ds.query((Query) queryBldr.constraints(queryBldr.constraintsFactory().customConstraints(search)).build())) {
        it.forEachRemaining(f -> {
            final String cityName = f.getAttribute(CITY_ATTR_NAME).toString();
            Assert.assertFalse(results.contains(cityName));
            results.add(cityName);
        });
    }
    return results;
}
Also used : DataStore(org.locationtech.geowave.core.store.api.DataStore) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) SimpleFeature(org.opengis.feature.simple.SimpleFeature) HashSet(java.util.HashSet)

Aggregations

DataStore (org.locationtech.geowave.core.store.api.DataStore)5 QueryBuilder (org.locationtech.geowave.core.store.api.QueryBuilder)5 HashSet (java.util.HashSet)4 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Set (java.util.Set)3 Maps (com.beust.jcommander.internal.Maps)2 Iterators (com.google.common.collect.Iterators)2 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2