use of org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery in project geowave by locationtech.
the class GeoWaveVisibilityIT method testQuery.
public static void testQuery(final DataStore store, final DataStatisticsStore statsStore, final short internalAdapterId, final String[] auths, final boolean spatial, final int expectedResultCount, final int expectedNonNullFieldCount) {
try (CloseableIterator<SimpleFeature> it = (CloseableIterator) store.query(QueryBuilder.newBuilder().setAuthorizations(auths).constraints(spatial ? new ExplicitSpatialQuery(new GeometryFactory().toGeometry(new Envelope(-1, 1, -1, 1))) : null).build())) {
int resultCount = 0;
int nonNullFieldsCount = 0;
while (it.hasNext()) {
final SimpleFeature feature = it.next();
for (int a = 0; a < feature.getAttributeCount(); a++) {
if (feature.getAttribute(a) != null) {
nonNullFieldsCount++;
}
}
resultCount++;
}
Assert.assertEquals("Unexpected result count for " + (spatial ? "spatial query" : "full table scan") + " with auths " + Arrays.toString(auths), expectedResultCount, resultCount);
Assert.assertEquals("Unexpected non-null field count for " + (spatial ? "spatial query" : "full table scan") + " with auths " + Arrays.toString(auths), expectedNonNullFieldCount, nonNullFieldsCount);
}
final Long count = (Long) store.aggregate(AggregationQueryBuilder.newBuilder().count(getType().getTypeName()).setAuthorizations(auths).constraints(spatial ? new ExplicitSpatialQuery(new GeometryFactory().toGeometry(new Envelope(-1, 1, -1, 1))) : null).build());
Assert.assertEquals("Unexpected aggregation result count for " + (spatial ? "spatial query" : "full table scan") + " with auths " + Arrays.toString(auths), expectedResultCount, count.intValue());
final CountValue countStat = store.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(getType().getTypeName()).authorizations(auths).build());
assertNotNull(countStat);
Assert.assertEquals("Unexpected stats result count for " + (spatial ? "spatial query" : "full table scan") + " with auths " + Arrays.toString(auths), expectedResultCount, countStat.getValue().intValue());
}
use of org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery in project geowave by locationtech.
the class GeoWaveSparkIngestIT method testBasicSparkIngest.
@Test
public void testBasicSparkIngest() throws Exception {
// ingest test points
TestUtils.testSparkIngest(dataStore, DimensionalityType.SPATIAL, S3URL, GDELT_INPUT_FILES, "gdelt");
final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
final FeatureDataAdapter adapter = (FeatureDataAdapter) internalDataAdapter.getAdapter();
// query by the full bounding box, make sure there is more than
// 0 count and make sure the count matches the number of results
final BoundingBoxValue bboxValue = InternalStatisticsHelper.getFieldStatistic(statsStore, BoundingBoxStatistic.STATS_TYPE, adapter.getTypeName(), adapter.getFeatureType().getGeometryDescriptor().getLocalName());
final CountValue count = InternalStatisticsHelper.getDataTypeStatistic(statsStore, CountStatistic.STATS_TYPE, adapter.getTypeName());
// then query it
final GeometryFactory factory = new GeometryFactory();
final Envelope env = new Envelope(bboxValue.getMinX(), bboxValue.getMaxX(), bboxValue.getMinY(), bboxValue.getMaxY());
final Geometry spatialFilter = factory.toGeometry(env);
final QueryConstraints query = new ExplicitSpatialQuery(spatialFilter);
final int resultCount = testQuery(adapter, query);
assertTrue("'" + adapter.getTypeName() + "' adapter must have at least one element in its statistic", count.getValue() > 0);
assertEquals("'" + adapter.getTypeName() + "' adapter should have the same results from a spatial query of '" + env + "' as its total count statistic", count.getValue().intValue(), resultCount);
assertEquals("'" + adapter.getTypeName() + "' adapter entries ingested does not match expected count", new Integer(GDELT_COUNT), new Integer(resultCount));
}
// Clean up
TestUtils.deleteAll(dataStore);
}
use of org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery in project geowave by locationtech.
the class BasicKafkaIT method testBasicIngestGpx.
@Test
public void testBasicIngestGpx() throws Exception {
KafkaTestUtils.testKafkaStage(OSM_GPX_INPUT_DIR);
KafkaTestUtils.testKafkaIngest(dataStorePluginOptions, false, OSM_GPX_INPUT_DIR);
final DataStatisticsStore statsStore = dataStorePluginOptions.createDataStatisticsStore();
final PersistentAdapterStore adapterStore = dataStorePluginOptions.createAdapterStore();
int adapterCount = 0;
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
final FeatureDataAdapter adapter = (FeatureDataAdapter) internalDataAdapter.getAdapter();
final BoundingBoxValue bboxValue = InternalStatisticsHelper.getFieldStatistic(statsStore, BoundingBoxStatistic.STATS_TYPE, adapter.getTypeName(), adapter.getFeatureType().getGeometryDescriptor().getLocalName());
final CountValue count = InternalStatisticsHelper.getDataTypeStatistic(statsStore, CountStatistic.STATS_TYPE, adapter.getTypeName());
// then query it
final GeometryFactory factory = new GeometryFactory();
final Envelope env = new Envelope(bboxValue.getMinX(), bboxValue.getMaxX(), bboxValue.getMinY(), bboxValue.getMaxY());
final Geometry spatialFilter = factory.toGeometry(env);
final QueryConstraints query = new ExplicitSpatialQuery(spatialFilter);
final int resultCount = testQuery(adapter, query);
assertTrue("'" + adapter.getTypeName() + "' adapter must have at least one element in its statistic", count.getValue() > 0);
assertEquals("'" + adapter.getTypeName() + "' adapter should have the same results from a spatial query of '" + env + "' as its total count statistic", count.getValue().intValue(), resultCount);
assertEquals("'" + adapter.getTypeName() + "' adapter entries ingested does not match expected count", EXPECTED_COUNT_PER_ADAPTER_ID.get(adapter.getTypeName()), new Integer(resultCount));
adapterCount++;
}
assertTrue("There should be exactly two adapters", (adapterCount == 2));
}
use of org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery in project geowave by locationtech.
the class DBScanIT method testDBScan.
@Test
public void testDBScan() {
dataGenerator.setIncludePolygons(false);
try {
ingest(dataStorePluginOptions.createDataStore());
} catch (final IOException e1) {
e1.printStackTrace();
TestUtils.deleteAll(dataStorePluginOptions);
Assert.fail("Unable to ingest data in DBScanIT");
}
try {
runScan(new ExplicitSpatialQuery(dataGenerator.getBoundingRegion()));
} catch (final Exception e) {
e.printStackTrace();
TestUtils.deleteAll(dataStorePluginOptions);
Assert.fail("Exception during scan of DBScanIT");
}
TestUtils.deleteAll(dataStorePluginOptions);
}
use of org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery in project geowave by locationtech.
the class GeoWaveBasicURLIngestIT method testBasicURLIngest.
@Test
public void testBasicURLIngest() throws Exception {
TestUtils.testS3LocalIngest(dataStore, DimensionalityType.SPATIAL, S3URL, GDELT_INPUT_FILE_URL, "gdelt", 4);
final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
final DataStore ds = dataStore.createDataStore();
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
final FeatureDataAdapter adapter = (FeatureDataAdapter) internalDataAdapter.getAdapter();
// query by the full bounding box, make sure there is more than
// 0 count and make sure the count matches the number of results
final BoundingBoxValue bbox = ds.aggregateStatistics(StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).typeName(internalDataAdapter.getTypeName()).fieldName(adapter.getFeatureType().getGeometryDescriptor().getLocalName()).build());
assertNotNull(bbox);
final CountValue count = ds.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).typeName(internalDataAdapter.getTypeName()).build());
assertNotNull(count);
// then query it
final GeometryFactory factory = new GeometryFactory();
final Envelope env = new Envelope(bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY());
final Geometry spatialFilter = factory.toGeometry(env);
final QueryConstraints query = new ExplicitSpatialQuery(spatialFilter);
final int resultCount = testQuery(adapter, query);
assertTrue("'" + adapter.getTypeName() + "' adapter must have at least one element in its statistic", count.getValue() > 0);
assertEquals("'" + adapter.getTypeName() + "' adapter should have the same results from a spatial query of '" + env + "' as its total count statistic", count.getValue().intValue(), resultCount);
assertEquals("'" + adapter.getTypeName() + "' adapter entries ingested does not match expected count", new Integer(GDELT_URL_COUNT), new Integer(resultCount));
}
// Clean up
TestUtils.deleteAll(dataStore);
}
Aggregations