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);
}
}
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;
}
Aggregations