Search in sources :

Example 1 with FilteredEverythingQuery

use of org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery in project geowave by locationtech.

the class ExpressionQueryIT method testSpatialExpressionQueries.

@Test
public void testSpatialExpressionQueries() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    ds.addType(adapter, spatialIndex);
    final Index altIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ALTERNATE_GEOMETRY_FIELD));
    final Index polyIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, POLYGON_FIELD));
    ds.addIndex(TYPE_NAME, altIndex, polyIndex);
    final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore aimStore = dataStore.createAdapterIndexMappingStore();
    final IndexStore indexStore = dataStore.createIndexStore();
    final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
    final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(TYPE_NAME));
    final Polygon boxPoly = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-20.5, -20.5), new Coordinate(-20.5, 20.5), new Coordinate(20.5, 20.5), new Coordinate(20.5, -20.5), new Coordinate(-20.5, -20.5) });
    final Polygon boxPoly2 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-20, -20), new Coordinate(-20, 20), new Coordinate(20, 20), new Coordinate(20, -20), new Coordinate(-20, -20) });
    // Large diagonal line
    final LineString line = GeometryUtils.GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(-20.5, -20.5), new Coordinate(20.5, 20.5) });
    // Ingest data
    ingestData(ds);
    // ///////////////////////////////////////////////////
    // Basic BBOX
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 64.5, 64.5)).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    ExplicitFilteredQuery constraints = (ExplicitFilteredQuery) queryConstraints;
    List<QueryFilter> filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof BBox);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 - 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose BBOX
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bboxLoose(0.5, 0.5, 64.5, 64.5)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 - 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Intersects
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.intersects(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Intersects);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(20, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose Intersects
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.intersectsLoose(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(20, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Disjoint
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.disjoint(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    FilteredEverythingQuery everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Disjoint);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose Disjoint
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.disjointLoose(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Disjoint);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Crosses
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.crosses(line)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Crosses);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(43, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Overlaps
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.overlaps(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Overlaps);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        // it overlaps 2 polygons in each corner
        assertEquals(4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.contains(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialContains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertFalse(iterator.hasNext());
    }
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(SpatialLiteral.of(boxPoly).contains(GEOM)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialContains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Touches
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.touches(boxPoly2)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Touches);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Within
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.within(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Within);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(41, Iterators.size(iterator));
    }
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(SpatialLiteral.of(boxPoly).within(GEOM)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Within);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertFalse(iterator.hasNext());
    }
    // ///////////////////////////////////////////////////
    // EqualTo
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.isEqualTo(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialEqualTo);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // NotEqualTo
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.isNotEqualTo(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialNotEqualTo);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 1, Iterators.size(iterator));
    }
}
Also used : TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Index(org.locationtech.geowave.core.store.api.Index) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) DataStore(org.locationtech.geowave.core.store.api.DataStore) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) FilteredEverythingQuery(org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery) Polygon(org.locationtech.jts.geom.Polygon) ExplicitFilteredQuery(org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) SpatialNotEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialNotEqualTo) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Example 2 with FilteredEverythingQuery

use of org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery in project geowave by locationtech.

the class ExpressionQueryIT method testTextExpressionQueries.

@Test
public void testTextExpressionQueries() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    ds.addType(adapter, spatialIndex);
    final Index commentIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, COMMENT_FIELD));
    final Index idIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ID_FIELD));
    ds.addIndex(TYPE_NAME, commentIndex, idIndex);
    final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore aimStore = dataStore.createAdapterIndexMappingStore();
    final IndexStore indexStore = dataStore.createIndexStore();
    final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
    final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(TYPE_NAME));
    // Ingest data
    ingestData(ds);
    // ///////////////////////////////////////////////////
    // Starts With
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.startsWith("Br")).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    CustomQueryConstraints<?> customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    List<QueryFilter> filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Starts With (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.startsWith("br", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Ends With
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.endsWith("phA")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Ends With (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.endsWith("pha", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.contains("lph")).build();
    // Spatial index will be selected since contains is a full scan
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    FilteredEverythingQuery everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Contains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.contains("al", true)).build();
    // Spatial index will be selected since contains is a full scan
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Contains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Between
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isBetween("A", "C")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Between);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Between (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isBetween("alpha", "bravo", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Between);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThan("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThan("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThan("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Less than can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThan("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Less than can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than Or Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThanOrEqualTo("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Greater than or equal to can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than Or Equal To (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThanOrEqualTo("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Greater than or equal to can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than Or Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThanOrEqualTo("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than Or Equal To (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThanOrEqualTo("bravo", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
}
Also used : ComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.ComparisonOperator) Index(org.locationtech.geowave.core.store.api.Index) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) FilteredEverythingQuery(org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Between(org.locationtech.geowave.core.store.query.filter.expression.Between) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)2 SpatialContains (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains)2 AdapterIndexMappingStore (org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore)2 InternalAdapterStore (org.locationtech.geowave.core.store.adapter.InternalAdapterStore)2 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 Index (org.locationtech.geowave.core.store.api.Index)2 AttributeIndexOptions (org.locationtech.geowave.core.store.index.AttributeIndexOptions)2 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)2 CustomQueryConstraints (org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints)2 FilteredEverythingQuery (org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery)2 QueryConstraints (org.locationtech.geowave.core.store.query.constraints.QueryConstraints)2 ExpressionQueryFilter (org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter)2 QueryFilter (org.locationtech.geowave.core.store.query.filter.QueryFilter)2 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)2 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 BBox (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox)1 Crosses (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses)1