Search in sources :

Example 1 with AggregationQuery

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

the class AbstractGeoWaveBasicVectorIT method testQuery.

protected void testQuery(final URL savedFilterResource, final URL[] expectedResultsResources, final Pair<String, String> optimalCqlQueryGeometryAndTimeFields, final Index index, final String queryDescription, final CoordinateReferenceSystem crs, final boolean countDuplicates) throws IOException {
    LOGGER.info("querying " + queryDescription);
    final DataStore geowaveStore = getDataStorePluginOptions().createDataStore();
    // this file is the filtered dataset (using the previous file as a
    // filter) so use it to ensure the query worked
    final QueryConstraints constraints = TestUtils.resourceToQuery(savedFilterResource, optimalCqlQueryGeometryAndTimeFields, true);
    QueryBuilder<?, ?> bldr = QueryBuilder.newBuilder();
    if (index != null) {
        bldr = bldr.indexName(index.getName());
    }
    try (final CloseableIterator<?> actualResults = geowaveStore.query(bldr.constraints(constraints).build())) {
        final ExpectedResults expectedResults = TestUtils.getExpectedResults(expectedResultsResources, crs);
        int totalResults = 0;
        final List<Long> actualCentroids = new ArrayList<>();
        while (actualResults.hasNext()) {
            final Object obj = actualResults.next();
            if (obj instanceof SimpleFeature) {
                final SimpleFeature result = (SimpleFeature) obj;
                final long actualHashCentroid = TestUtils.hashCentroid((Geometry) result.getDefaultGeometry());
                Assert.assertTrue("Actual result '" + result.toString() + "' not found in expected result set", expectedResults.hashedCentroids.contains(actualHashCentroid));
                actualCentroids.add(actualHashCentroid);
                totalResults++;
            } else {
                TestUtils.deleteAll(getDataStorePluginOptions());
                Assert.fail("Actual result '" + obj.toString() + "' is not of type Simple Feature.");
            }
        }
        for (final long l : actualCentroids) {
            expectedResults.hashedCentroids.remove(l);
        }
        for (final long l : expectedResults.hashedCentroids) {
            LOGGER.error("Missing expected hashed centroid: " + l);
        }
        if (expectedResults.count != totalResults) {
            TestUtils.deleteAll(getDataStorePluginOptions());
        }
        Assert.assertEquals(expectedResults.count, totalResults);
        final PersistentAdapterStore adapterStore = getDataStorePluginOptions().createAdapterStore();
        long statisticsResult = 0;
        int duplicates = 0;
        final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
        for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
            AggregationQueryBuilder<?, Long, ?, ?> aggBldr = AggregationQueryBuilder.newBuilder();
            if (index != null) {
                aggBldr = aggBldr.indexName(index.getName());
            }
            aggBldr = aggBldr.constraints(constraints);
            if (countDuplicates) {
                aggBldr.aggregate(internalDataAdapter.getTypeName(), (Aggregation) new DuplicateCountAggregation());
                final DuplicateCount countResult = (DuplicateCount) geowaveStore.aggregate((AggregationQuery) aggBldr.build());
                if (countResult != null) {
                    duplicates += countResult.count;
                }
            }
            aggBldr.count(internalDataAdapter.getTypeName());
            final Long countResult = geowaveStore.aggregate(aggBldr.build());
            // results should already be aggregated, there should be
            // exactly one value in this iterator
            Assert.assertNotNull(countResult);
            statisticsResult += countResult;
        }
        Assert.assertEquals(expectedResults.count, statisticsResult - duplicates);
    }
}
Also used : AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) ArrayList(java.util.ArrayList) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpectedResults(org.locationtech.geowave.test.TestUtils.ExpectedResults) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter)

Example 2 with AggregationQuery

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

the class ExpressionQueryIT method assertBestIndex.

private QueryConstraints assertBestIndex(final InternalDataAdapter<?> adapter, final Index bestIndex, final BaseQuery<?, ?> query, final PersistentAdapterStore adapterStore, final InternalAdapterStore internalAdapterStore, final AdapterIndexMappingStore aimStore, final IndexStore indexStore, final DataStatisticsStore statsStore) {
    assertTrue(query.getQueryConstraints() instanceof OptimalExpressionQuery);
    final OptimalExpressionQuery queryConstraints = (OptimalExpressionQuery) query.getQueryConstraints();
    @SuppressWarnings("rawtypes") List<Pair<Index, List<InternalDataAdapter<?>>>> optimalIndices = queryConstraints.determineBestIndices(query instanceof Query ? new BaseQueryOptions((Query) query, adapterStore, internalAdapterStore) : new BaseQueryOptions((AggregationQuery) query, adapterStore, internalAdapterStore), new InternalDataAdapter<?>[] { adapter }, aimStore, indexStore, statsStore);
    assertEquals(1, optimalIndices.size());
    final Pair<Index, List<InternalDataAdapter<?>>> indexAdapterPair = optimalIndices.get(0);
    assertEquals(bestIndex, indexAdapterPair.getKey());
    assertEquals(1, indexAdapterPair.getValue().size());
    assertEquals(adapter, indexAdapterPair.getValue().get(0));
    final QueryConstraints retVal = queryConstraints.createQueryConstraints(adapter, bestIndex, aimStore.getMapping(adapter.getAdapterId(), bestIndex.getName()));
    return retVal;
}
Also used : OptimalExpressionQuery(org.locationtech.geowave.core.store.query.constraints.OptimalExpressionQuery) BaseQuery(org.locationtech.geowave.core.store.query.BaseQuery) Query(org.locationtech.geowave.core.store.api.Query) AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) ExplicitFilteredQuery(org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery) FilteredEverythingQuery(org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery) OptimalExpressionQuery(org.locationtech.geowave.core.store.query.constraints.OptimalExpressionQuery) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) BaseQueryOptions(org.locationtech.geowave.core.store.base.BaseQueryOptions) Index(org.locationtech.geowave.core.store.api.Index) List(java.util.List) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)2 AggregationQuery (org.locationtech.geowave.core.store.api.AggregationQuery)2 QueryConstraints (org.locationtech.geowave.core.store.query.constraints.QueryConstraints)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Pair (org.apache.commons.lang3.tuple.Pair)1 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 Query (org.locationtech.geowave.core.store.api.Query)1 BaseQueryOptions (org.locationtech.geowave.core.store.base.BaseQueryOptions)1 BaseQuery (org.locationtech.geowave.core.store.query.BaseQuery)1 CustomQueryConstraints (org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints)1 ExplicitFilteredQuery (org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery)1 FilteredEverythingQuery (org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery)1 OptimalExpressionQuery (org.locationtech.geowave.core.store.query.constraints.OptimalExpressionQuery)1 ExpectedResults (org.locationtech.geowave.test.TestUtils.ExpectedResults)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1