Search in sources :

Example 1 with DuringOrAfter

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter in project geowave by locationtech.

the class ExpressionQueryIT method testTemporalExpressionQueriesTemporalIndex.

@Test
public void testTemporalExpressionQueriesTemporalIndex() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final Index temporalIndex = TemporalDimensionalityTypeProvider.createIndexFromOptions(new TemporalOptions());
    ds.addType(adapter, spatialIndex, temporalIndex);
    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);
    // ///////////////////////////////////////////////////
    // After
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isAfter(new Date(ONE_DAY_MILLIS * (TOTAL_FEATURES / 2)))).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    ExplicitFilteredQuery constraints = (ExplicitFilteredQuery) queryConstraints;
    List<QueryFilter> filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 - 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Before
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isBefore(ONE_DAY_MILLIS * (TOTAL_FEATURES / 2))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Before);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // During or After
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isDuringOrAfter(ONE_DAY_MILLIS * (TOTAL_FEATURES / 2))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof DuringOrAfter);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Before or During
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isBeforeOrDuring(ONE_DAY_MILLIS * (TOTAL_FEATURES / 2))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof BeforeOrDuring);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 + 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // During
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isDuring(Interval.of(Instant.ofEpochMilli(ONE_DAY_MILLIS * 5), Instant.ofEpochMilli(ONE_DAY_MILLIS * 10)))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof During);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(5, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Between
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isBetween(Instant.ofEpochMilli(ONE_DAY_MILLIS * 5), Instant.ofEpochMilli(ONE_DAY_MILLIS * 10))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof TemporalBetween);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(6, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains (inverse of During)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TemporalLiteral.of(Interval.of(Instant.ofEpochMilli(ONE_DAY_MILLIS * 5), Instant.ofEpochMilli(ONE_DAY_MILLIS * 10))).contains(TIMESTAMP)).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof During);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(5, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Overlaps
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.overlaps(Interval.of(Instant.ofEpochMilli(ONE_DAY_MILLIS * 5), Instant.ofEpochMilli(ONE_DAY_MILLIS * 10)))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof TimeOverlaps);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(5, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isEqualTo(ONE_DAY_MILLIS * 12)).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof TemporalEqualTo);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Not Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isNotEqualTo(ONE_DAY_MILLIS * 12).and(TIMESTAMP.isNotEqualTo(ONE_DAY_MILLIS * 8))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof And);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 2, Iterators.size(iterator));
    }
}
Also used : Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) 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) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) DataStore(org.locationtech.geowave.core.store.api.DataStore) TemporalEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalEqualTo) ExplicitFilteredQuery(org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Date(java.util.Date) 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) 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) And(org.locationtech.geowave.core.store.query.filter.expression.And) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) TemporalOptions(org.locationtech.geowave.core.geotime.index.TemporalOptions) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Example 2 with DuringOrAfter

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter in project geowave by locationtech.

the class CQLToGeoWaveFilterTest method testCQLtoGeoWaveFilter.

@Test
public void testCQLtoGeoWaveFilter() throws CQLException, ParseException {
    Filter f = fromCQL("EMPLOYED < 15000000");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.LESS_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(15000000L, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue().longValue());
    f = fromCQL("EMPLOYED BETWEEN 1000000 AND 3000000");
    assertTrue(f instanceof NumericBetween);
    assertTrue(((NumericBetween) f).getValue() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericBetween) f).getValue()).getFieldName());
    assertTrue(((NumericBetween) f).getLowerBound() instanceof NumericLiteral);
    assertEquals(1000000L, ((NumericLiteral) ((NumericBetween) f).getLowerBound()).getValue().longValue());
    assertTrue(((NumericBetween) f).getUpperBound() instanceof NumericLiteral);
    assertEquals(3000000L, ((NumericLiteral) ((NumericBetween) f).getUpperBound()).getValue().longValue());
    f = fromCQL("name = 'California'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("California", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    f = fromCQL("UNEMPLOY / (EMPLOYED + UNEMPLOY) > 0.07");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Divide);
    Divide divide = (Divide) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(divide.getExpression1() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) divide.getExpression1()).getFieldName());
    assertTrue(divide.getExpression2() instanceof Add);
    Add add = (Add) divide.getExpression2();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(0.07, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue(), EPSILON);
    f = fromCQL("A <> B AND B <= 8.1");
    assertTrue(f instanceof And);
    assertTrue(((And) f).getChildren().length == 2);
    assertTrue(((And) f).getChildren()[0] instanceof Not);
    assertTrue(((Not) ((And) f).getChildren()[0]).getFilter() instanceof NumericComparisonOperator);
    NumericComparisonOperator equalTo = (NumericComparisonOperator) ((Not) ((And) f).getChildren()[0]).getFilter();
    assertEquals(CompareOp.EQUAL_TO, equalTo.getCompareOp());
    assertTrue(equalTo.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) equalTo.getExpression1()).getFieldName());
    assertTrue(equalTo.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) equalTo.getExpression2()).getFieldName());
    assertTrue(((And) f).getChildren()[1] instanceof NumericComparisonOperator);
    NumericComparisonOperator lessThan = (NumericComparisonOperator) ((And) f).getChildren()[1];
    assertEquals(CompareOp.LESS_THAN_OR_EQUAL, lessThan.getCompareOp());
    assertTrue(lessThan.getExpression1() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) lessThan.getExpression1()).getFieldName());
    assertTrue(lessThan.getExpression2() instanceof NumericLiteral);
    assertEquals(8.1, ((NumericLiteral) lessThan.getExpression2()).getValue(), EPSILON);
    // Order of operations should be preserved
    f = fromCQL("A + B - (C * D) / 8.5 >= E");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN_OR_EQUAL, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Subtract);
    Subtract subtract = (Subtract) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(subtract.getExpression1() instanceof Add);
    add = (Add) subtract.getExpression1();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(subtract.getExpression2() instanceof Divide);
    divide = (Divide) subtract.getExpression2();
    assertTrue(divide.getExpression1() instanceof Multiply);
    Multiply multiply = (Multiply) divide.getExpression1();
    assertTrue(multiply.getExpression1() instanceof NumericFieldValue);
    assertEquals("C", ((NumericFieldValue) multiply.getExpression1()).getFieldName());
    assertTrue(multiply.getExpression2() instanceof NumericFieldValue);
    assertEquals("D", ((NumericFieldValue) multiply.getExpression2()).getFieldName());
    assertTrue(divide.getExpression2() instanceof NumericLiteral);
    assertEquals(8.5, ((NumericLiteral) divide.getExpression2()).getValue(), EPSILON);
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericFieldValue);
    assertEquals("E", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression2()).getFieldName());
    f = fromCQL("BBOX(geom, -90, 40, -60, 45)");
    assertTrue(f instanceof BBox);
    assertTrue(((BBox) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((BBox) f).getExpression1()).getFieldName());
    assertTrue(((BBox) f).getExpression2() instanceof SpatialLiteral);
    SpatialLiteral spatialLit = (SpatialLiteral) ((BBox) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    Geometry geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(-90, -60, 40, 45))));
    f = fromCQL("DISJOINT(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Disjoint);
    assertTrue(((Disjoint) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Disjoint) f).getExpression1()).getFieldName());
    assertTrue(((Disjoint) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Disjoint) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("EQUALS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialEqualTo);
    assertTrue(((SpatialEqualTo) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((SpatialEqualTo) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialEqualTo) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CONTAINS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialContains);
    assertTrue(((SpatialContains) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialContains) f).getExpression1()).getFieldName());
    assertTrue(((SpatialContains) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialContains) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CROSSES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Crosses);
    assertTrue(((Crosses) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Crosses) f).getExpression1()).getFieldName());
    assertTrue(((Crosses) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Crosses) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("INTERSECTS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Intersects);
    assertTrue(((Intersects) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Intersects) f).getExpression1()).getFieldName());
    assertTrue(((Intersects) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Intersects) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("OVERLAPS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Overlaps);
    assertTrue(((Overlaps) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Overlaps) f).getExpression1()).getFieldName());
    assertTrue(((Overlaps) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Overlaps) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("TOUCHES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Touches);
    assertTrue(((Touches) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Touches) f).getExpression1()).getFieldName());
    assertTrue(((Touches) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Touches) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("WITHIN(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Within);
    assertTrue(((Within) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Within) f).getExpression1()).getFieldName());
    assertTrue(((Within) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Within) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    final Instant date1 = Instant.parse("2020-01-25T00:28:32Z");
    final Instant date2 = Instant.parse("2021-03-02T13:08:45Z");
    f = fromCQL("date AFTER 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    Interval interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date > 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BEFORE 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date < 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof During);
    assertTrue(((During) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((During) f).getExpression1()).getFieldName());
    assertTrue(((During) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((During) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    // GeoWave has a BeforeOrDuring class, but the CQL filter translates it using OR
    f = fromCQL("date BEFORE OR DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof Before);
    Before before = (Before) ((Or) f).getChildren()[0];
    assertTrue(before.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) before.getExpression1()).getFieldName());
    assertTrue(before.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) before.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof During);
    During during = (During) ((Or) f).getChildren()[1];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING OR AFTER 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof During);
    during = (During) ((Or) f).getChildren()[0];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof After);
    After after = (After) ((Or) f).getChildren()[1];
    assertTrue(after.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) after.getExpression1()).getFieldName());
    assertTrue(after.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) after.getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date <= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof BeforeOrDuring);
    assertTrue(((BeforeOrDuring) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((BeforeOrDuring) f).getExpression1()).getFieldName());
    assertTrue(((BeforeOrDuring) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((BeforeOrDuring) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date >= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof DuringOrAfter);
    assertTrue(((DuringOrAfter) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((DuringOrAfter) f).getExpression1()).getFieldName());
    assertTrue(((DuringOrAfter) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((DuringOrAfter) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BETWEEN 2020-01-25T00:28:32Z AND 2021-03-02T13:08:45Z");
    assertTrue(f instanceof TemporalBetween);
    assertTrue(((TemporalBetween) f).getValue() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((TemporalBetween) f).getValue()).getFieldName());
    assertTrue(((TemporalBetween) f).getLowerBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getLowerBound())).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((TemporalBetween) f).getUpperBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getUpperBound())).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date IS NULL");
    assertTrue(f instanceof IsNull);
    assertTrue(((IsNull) f).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) f).getExpression()).getFieldName());
    f = fromCQL("date IS NOT NULL");
    assertTrue(f instanceof Not);
    assertTrue(((Not) f).getFilter() instanceof IsNull);
    assertTrue(((IsNull) ((Not) f).getFilter()).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) ((Not) f).getFilter()).getExpression()).getFieldName());
    f = fromCQL("INCLUDE");
    assertTrue(f instanceof Include);
    f = fromCQL("EXCLUDE");
    assertTrue(f instanceof Exclude);
    f = fromCQL("bool = TRUE");
    assertTrue(f instanceof GenericEqualTo);
    assertTrue(((GenericEqualTo) f).getExpression1() instanceof BooleanFieldValue);
    assertEquals("bool", ((BooleanFieldValue) ((GenericEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((GenericEqualTo) f).getExpression2() instanceof BooleanLiteral);
    assertTrue((boolean) ((BooleanLiteral) ((GenericEqualTo) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value'");
    assertTrue(f instanceof EndsWith);
    assertTrue(((EndsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((EndsWith) f).getExpression1()).getFieldName());
    assertTrue(((EndsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((EndsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'value%'");
    assertTrue(f instanceof StartsWith);
    assertTrue(((StartsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((StartsWith) f).getExpression1()).getFieldName());
    assertTrue(((StartsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((StartsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value%'");
    assertTrue(f instanceof Contains);
    assertTrue(((Contains) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) f).getExpression1()).getFieldName());
    assertTrue(((Contains) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((Contains) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'a\\_value'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("a_value", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    try {
        // _ is a single character wild card, so this is not supported
        f = fromCQL("name LIKE 'a_value'");
        fail();
    } catch (CQLToGeoWaveConversionException e) {
    // expected
    }
}
Also used : Add(org.locationtech.geowave.core.store.query.filter.expression.numeric.Add) TextComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator) Or(org.locationtech.geowave.core.store.query.filter.expression.Or) GenericEqualTo(org.locationtech.geowave.core.store.query.filter.expression.GenericEqualTo) Include(org.locationtech.geowave.core.store.query.filter.expression.Include) TemporalFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue) BooleanFieldValue(org.locationtech.geowave.core.store.query.filter.expression.BooleanFieldValue) Divide(org.locationtech.geowave.core.store.query.filter.expression.numeric.Divide) Multiply(org.locationtech.geowave.core.store.query.filter.expression.numeric.Multiply) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) SpatialFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue) NumericBetween(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween) Instant(java.time.Instant) Not(org.locationtech.geowave.core.store.query.filter.expression.Not) Coordinate(org.locationtech.jts.geom.Coordinate) And(org.locationtech.geowave.core.store.query.filter.expression.And) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) Subtract(org.locationtech.geowave.core.store.query.filter.expression.numeric.Subtract) EndsWith(org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith) Interval(org.threeten.extra.Interval) Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Exclude(org.locationtech.geowave.core.store.query.filter.expression.Exclude) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) BooleanLiteral(org.locationtech.geowave.core.store.query.filter.expression.BooleanLiteral) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) Envelope(org.locationtech.jts.geom.Envelope) StartsWith(org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) TemporalLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) Geometry(org.locationtech.jts.geom.Geometry) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) After(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) IsNull(org.locationtech.geowave.core.store.query.filter.expression.IsNull) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Test(org.junit.Test)

Example 3 with DuringOrAfter

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter in project geowave by locationtech.

the class SpatialTemporalFilterExpressionTest method testTemporalExpressions.

@Test
public void testTemporalExpressions() {
    final DataTypeAdapter<TestType> adapter = new TestTypeBasicDataAdapter();
    final TestType entry = new TestType(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(20, 20)), new Date(500), "test");
    final TestType entryNulls = new TestType(null, null, null);
    final TemporalFieldValue dateField = TemporalFieldValue.of("date");
    final TemporalLiteral dateLit = TemporalLiteral.of(new Date(300));
    final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTime(new Date(400));
    final TemporalLiteral calendarLit = TemporalLiteral.of(calendar);
    final TemporalLiteral longLit = TemporalLiteral.of(600);
    final TemporalLiteral instantLit = TemporalLiteral.of(Instant.ofEpochMilli(700));
    final TemporalLiteral intervalLit = TemporalLiteral.of(Interval.of(Instant.ofEpochMilli(450), Instant.ofEpochMilli(650)));
    // Test comparisons
    assertTrue(calendarLit.isEqualTo(new Date(400)).evaluate(adapter, entry));
    assertFalse(calendarLit.isEqualTo(dateLit).evaluate(adapter, entry));
    assertTrue(dateField.isEqualTo(new Date(500)).evaluate(adapter, entry));
    assertFalse(dateField.isEqualTo(longLit).evaluate(adapter, entry));
    assertTrue(dateField.isEqualTo(null).evaluate(adapter, entryNulls));
    assertFalse(dateField.isEqualTo(null).evaluate(adapter, entry));
    assertFalse(calendarLit.isNotEqualTo(new Date(400)).evaluate(adapter, entry));
    assertTrue(calendarLit.isNotEqualTo(dateLit).evaluate(adapter, entry));
    assertFalse(dateField.isNotEqualTo(new Date(500)).evaluate(adapter, entry));
    assertTrue(dateField.isNotEqualTo(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isNotEqualTo(null).evaluate(adapter, entryNulls));
    assertTrue(dateField.isNotEqualTo(null).evaluate(adapter, entry));
    assertFalse(dateField.isNull().evaluate(adapter, entry));
    assertTrue(dateField.isNull().evaluate(adapter, entryNulls));
    assertFalse(instantLit.isNull().evaluate(adapter, entry));
    assertFalse(intervalLit.isNull().evaluate(adapter, entry));
    assertTrue(TemporalLiteral.of(null).isNull().evaluate(adapter, entry));
    assertTrue(dateField.isNotNull().evaluate(adapter, entry));
    assertFalse(dateField.isNotNull().evaluate(adapter, entryNulls));
    assertTrue(instantLit.isNotNull().evaluate(adapter, entry));
    assertTrue(intervalLit.isNotNull().evaluate(adapter, entry));
    assertFalse(TemporalLiteral.of(null).isNotNull().evaluate(adapter, entry));
    assertTrue(dateField.isLessThan(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isLessThan(calendarLit).evaluate(adapter, entry));
    assertTrue(calendarLit.isLessThan(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isLessThan(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.isLessThan(instantLit).evaluate(adapter, entry));
    assertFalse(dateField.isLessThan(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isLessThan(dateField).evaluate(adapter, entryNulls));
    assertTrue(dateField.isLessThanOrEqualTo(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isLessThanOrEqualTo(calendarLit).evaluate(adapter, entry));
    assertTrue(calendarLit.isLessThanOrEqualTo(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isLessThanOrEqualTo(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.isLessThanOrEqualTo(instantLit).evaluate(adapter, entry));
    assertFalse(dateField.isLessThanOrEqualTo(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isLessThanOrEqualTo(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.isGreaterThan(longLit).evaluate(adapter, entry));
    assertTrue(dateField.isGreaterThan(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.isGreaterThan(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isGreaterThan(dateLit).evaluate(adapter, entry));
    assertFalse(intervalLit.isGreaterThan(instantLit).evaluate(adapter, entry));
    assertTrue(instantLit.isGreaterThan(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isGreaterThan(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isGreaterThan(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.isGreaterThanOrEqualTo(longLit).evaluate(adapter, entry));
    assertTrue(dateField.isGreaterThanOrEqualTo(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.isGreaterThanOrEqualTo(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isGreaterThanOrEqualTo(dateLit).evaluate(adapter, entry));
    assertFalse(intervalLit.isGreaterThanOrEqualTo(instantLit).evaluate(adapter, entry));
    assertTrue(instantLit.isGreaterThanOrEqualTo(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isGreaterThanOrEqualTo(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isGreaterThanOrEqualTo(dateField).evaluate(adapter, entryNulls));
    assertTrue(calendarLit.isBetween(dateLit, longLit).evaluate(adapter, entry));
    assertFalse(dateLit.isBetween(calendarLit, longLit).evaluate(adapter, entry));
    assertFalse(longLit.isBetween(dateLit, calendarLit).evaluate(adapter, entry));
    assertFalse(dateField.isBetween(dateLit, longLit).evaluate(adapter, entryNulls));
    assertFalse(dateLit.isBetween(dateField, longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isBetween(dateLit, dateField).evaluate(adapter, entryNulls));
    TemporalBetween between = (TemporalBetween) calendarLit.isBetween(dateField, calendarLit);
    assertTrue(between.getValue() instanceof TemporalLiteral);
    assertTrue(between.getLowerBound() instanceof TemporalFieldValue);
    assertTrue(between.getUpperBound() instanceof TemporalLiteral);
    try {
        dateField.isLessThan("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        dateField.isLessThanOrEqualTo("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        dateField.isGreaterThan("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        dateField.isGreaterThanOrEqualTo("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        dateField.isBetween("invalid", longLit);
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        dateField.isBetween(longLit, "invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        TemporalLiteral.of("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    // Test functions
    assertTrue(dateField.isBefore(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(calendarLit).evaluate(adapter, entry));
    assertTrue(calendarLit.isBefore(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.isBefore(instantLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isBefore(dateField).evaluate(adapter, entryNulls));
    assertTrue(dateField.isBeforeOrDuring(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isBeforeOrDuring(calendarLit).evaluate(adapter, entry));
    assertTrue(calendarLit.isBeforeOrDuring(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isBeforeOrDuring(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.isBeforeOrDuring(instantLit).evaluate(adapter, entry));
    assertFalse(dateField.isBeforeOrDuring(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isBeforeOrDuring(dateField).evaluate(adapter, entryNulls));
    assertTrue(dateField.isBefore(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(calendarLit).evaluate(adapter, entry));
    assertTrue(calendarLit.isBefore(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.isBefore(instantLit).evaluate(adapter, entry));
    assertFalse(dateField.isBefore(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isBefore(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.isAfter(longLit).evaluate(adapter, entry));
    assertTrue(dateField.isAfter(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.isAfter(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isAfter(dateLit).evaluate(adapter, entry));
    assertFalse(intervalLit.isAfter(instantLit).evaluate(adapter, entry));
    assertTrue(instantLit.isAfter(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isAfter(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isAfter(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.isDuringOrAfter(longLit).evaluate(adapter, entry));
    assertTrue(dateField.isDuringOrAfter(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.isDuringOrAfter(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isDuringOrAfter(dateLit).evaluate(adapter, entry));
    assertFalse(intervalLit.isDuringOrAfter(instantLit).evaluate(adapter, entry));
    assertTrue(instantLit.isDuringOrAfter(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isDuringOrAfter(longLit).evaluate(adapter, entryNulls));
    assertFalse(longLit.isDuringOrAfter(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.isDuring(longLit).evaluate(adapter, entry));
    assertFalse(dateField.isDuring(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.isDuring(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.isDuring(intervalLit).evaluate(adapter, entry));
    assertTrue(longLit.isDuring(intervalLit).evaluate(adapter, entry));
    assertFalse(intervalLit.isDuring(dateField).evaluate(adapter, entry));
    assertFalse(instantLit.isDuring(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.isDuring(intervalLit).evaluate(adapter, entryNulls));
    assertFalse(intervalLit.isDuring(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.contains(longLit).evaluate(adapter, entry));
    assertFalse(dateField.contains(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.contains(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.contains(dateField).evaluate(adapter, entry));
    assertTrue(intervalLit.contains(longLit).evaluate(adapter, entry));
    assertFalse(instantLit.contains(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.contains(intervalLit).evaluate(adapter, entryNulls));
    assertFalse(intervalLit.contains(dateField).evaluate(adapter, entryNulls));
    assertFalse(dateField.overlaps(longLit).evaluate(adapter, entry));
    assertFalse(dateField.overlaps(calendarLit).evaluate(adapter, entry));
    assertFalse(calendarLit.overlaps(intervalLit).evaluate(adapter, entry));
    assertTrue(dateField.overlaps(intervalLit).evaluate(adapter, entry));
    assertTrue(longLit.overlaps(intervalLit).evaluate(adapter, entry));
    assertTrue(intervalLit.overlaps(dateField).evaluate(adapter, entry));
    assertFalse(instantLit.overlaps(intervalLit).evaluate(adapter, entry));
    assertTrue(TemporalLiteral.of(Interval.of(Instant.ofEpochMilli(200), Instant.ofEpochMilli(500))).overlaps(intervalLit).evaluate(adapter, entry));
    assertFalse(TemporalLiteral.of(Interval.of(Instant.ofEpochMilli(100), Instant.ofEpochMilli(300))).overlaps(intervalLit).evaluate(adapter, entry));
    assertFalse(dateField.overlaps(intervalLit).evaluate(adapter, entryNulls));
    assertFalse(intervalLit.overlaps(dateField).evaluate(adapter, entryNulls));
    // Test serialization
    byte[] bytes = PersistenceUtils.toBinary(dateField.isAfter(longLit));
    final After after = (After) PersistenceUtils.fromBinary(bytes);
    assertTrue(after.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) after.getExpression1()).getFieldName());
    assertTrue(after.getExpression2() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) after.getExpression2()).getValue() instanceof Interval);
    assertEquals(600, ((Interval) ((TemporalLiteral) after.getExpression2()).getValue()).getStart().toEpochMilli());
    assertEquals(600, ((Interval) ((TemporalLiteral) after.getExpression2()).getValue()).getEnd().toEpochMilli());
    bytes = PersistenceUtils.toBinary(dateField.isDuringOrAfter(intervalLit));
    final DuringOrAfter duringOrAfter = (DuringOrAfter) PersistenceUtils.fromBinary(bytes);
    assertTrue(duringOrAfter.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) duringOrAfter.getExpression1()).getFieldName());
    assertTrue(duringOrAfter.getExpression2() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) duringOrAfter.getExpression2()).getValue() instanceof Interval);
    assertEquals(450, ((Interval) ((TemporalLiteral) duringOrAfter.getExpression2()).getValue()).getStart().toEpochMilli());
    assertEquals(650, ((Interval) ((TemporalLiteral) duringOrAfter.getExpression2()).getValue()).getEnd().toEpochMilli());
    bytes = PersistenceUtils.toBinary(dateField.isBefore(longLit));
    final Before before = (Before) PersistenceUtils.fromBinary(bytes);
    assertTrue(before.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) before.getExpression1()).getFieldName());
    assertTrue(before.getExpression2() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) before.getExpression2()).getValue() instanceof Interval);
    assertEquals(600, ((Interval) ((TemporalLiteral) before.getExpression2()).getValue()).getStart().toEpochMilli());
    assertEquals(600, ((Interval) ((TemporalLiteral) before.getExpression2()).getValue()).getEnd().toEpochMilli());
    bytes = PersistenceUtils.toBinary(dateField.isBeforeOrDuring(intervalLit));
    final BeforeOrDuring beforeOrDuring = (BeforeOrDuring) PersistenceUtils.fromBinary(bytes);
    assertTrue(beforeOrDuring.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) beforeOrDuring.getExpression1()).getFieldName());
    assertTrue(beforeOrDuring.getExpression2() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) beforeOrDuring.getExpression2()).getValue() instanceof Interval);
    assertEquals(450, ((Interval) ((TemporalLiteral) beforeOrDuring.getExpression2()).getValue()).getStart().toEpochMilli());
    assertEquals(650, ((Interval) ((TemporalLiteral) beforeOrDuring.getExpression2()).getValue()).getEnd().toEpochMilli());
    bytes = PersistenceUtils.toBinary(dateField.isDuring(TemporalLiteral.of(null)));
    final During during = (During) PersistenceUtils.fromBinary(bytes);
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    assertNull(((TemporalLiteral) during.getExpression2()).getValue());
    bytes = PersistenceUtils.toBinary(dateField.isBetween(longLit, intervalLit));
    between = (TemporalBetween) PersistenceUtils.fromBinary(bytes);
    assertTrue(between.getValue() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) between.getValue()).getFieldName());
    assertTrue(between.getLowerBound() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) between.getLowerBound()).getValue() instanceof Interval);
    assertEquals(600, ((Interval) ((TemporalLiteral) between.getLowerBound()).getValue()).getStart().toEpochMilli());
    assertEquals(600, ((Interval) ((TemporalLiteral) between.getLowerBound()).getValue()).getEnd().toEpochMilli());
    assertTrue(between.getUpperBound() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) between.getUpperBound()).getValue() instanceof Interval);
    assertEquals(450, ((Interval) ((TemporalLiteral) between.getUpperBound()).getValue()).getStart().toEpochMilli());
    assertEquals(650, ((Interval) ((TemporalLiteral) between.getUpperBound()).getValue()).getEnd().toEpochMilli());
    bytes = PersistenceUtils.toBinary(dateField.overlaps(intervalLit));
    final TimeOverlaps overlaps = (TimeOverlaps) PersistenceUtils.fromBinary(bytes);
    assertTrue(overlaps.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) overlaps.getExpression1()).getFieldName());
    assertTrue(overlaps.getExpression2() instanceof TemporalLiteral);
    assertTrue(((TemporalLiteral) overlaps.getExpression2()).getValue() instanceof Interval);
    assertEquals(450, ((Interval) ((TemporalLiteral) overlaps.getExpression2()).getValue()).getStart().toEpochMilli());
    assertEquals(650, ((Interval) ((TemporalLiteral) overlaps.getExpression2()).getValue()).getEnd().toEpochMilli());
}
Also used : Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) Calendar(java.util.Calendar) TemporalLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral) Date(java.util.Date) TemporalFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) Coordinate(org.locationtech.jts.geom.Coordinate) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) After(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Interval(org.threeten.extra.Interval) Test(org.junit.Test)

Example 4 with DuringOrAfter

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter in project geowave by locationtech.

the class GWQLParserTest method testTemporalOperatorFunctions.

@Test
public void testTemporalOperatorFunctions() {
    final DataStore dataStore = createDataStore();
    String statement = "SELECT * FROM type WHERE start AFTER '2020-01-01'";
    Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    Filter filter = selectStatement.getFilter();
    assertTrue(filter instanceof After);
    BinaryTemporalPredicate predicate = (BinaryTemporalPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof TemporalFieldValue);
    assertEquals("start", ((TemporalFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof TemporalLiteral);
    assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getStart().toEpochMilli());
    assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getEnd().toEpochMilli());
    statement = "SELECT * FROM type WHERE start DURING_OR_AFTER '2020-01-01/2020-01-05'";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof DuringOrAfter);
    predicate = (BinaryTemporalPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof TemporalFieldValue);
    assertEquals("start", ((TemporalFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof TemporalLiteral);
    assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getStart().toEpochMilli());
    assertEquals(TemporalExpression.stringToDate("2020-01-05").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getEnd().toEpochMilli());
    statement = "SELECT * FROM type WHERE start DURING '2020-01-01/2020-01-05'";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof During);
    predicate = (BinaryTemporalPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof TemporalFieldValue);
    assertEquals("start", ((TemporalFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof TemporalLiteral);
    assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getStart().toEpochMilli());
    assertEquals(TemporalExpression.stringToDate("2020-01-05").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getEnd().toEpochMilli());
    statement = "SELECT * FROM type WHERE start BEFORE_OR_DURING '2020-01-01/2020-01-05'";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof BeforeOrDuring);
    predicate = (BinaryTemporalPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof TemporalFieldValue);
    assertEquals("start", ((TemporalFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof TemporalLiteral);
    assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getStart().toEpochMilli());
    assertEquals(TemporalExpression.stringToDate("2020-01-05").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getEnd().toEpochMilli());
    statement = "SELECT * FROM type WHERE start BEFORE '2020-01-05'";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Before);
    predicate = (BinaryTemporalPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof TemporalFieldValue);
    assertEquals("start", ((TemporalFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof TemporalLiteral);
    assertEquals(TemporalExpression.stringToDate("2020-01-05").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getStart().toEpochMilli());
    assertEquals(TemporalExpression.stringToDate("2020-01-05").getTime(), ((TemporalLiteral) predicate.getExpression2()).getValue().getEnd().toEpochMilli());
}
Also used : Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) TemporalLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral) TemporalFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) BinaryTemporalPredicate(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BinaryTemporalPredicate) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) DataStore(org.locationtech.geowave.core.store.api.DataStore) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) After(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) AbstractGWQLTest(org.locationtech.geowave.core.store.query.gwql.AbstractGWQLTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Before (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before)4 BeforeOrDuring (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring)4 During (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During)4 DuringOrAfter (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter)4 After (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After)3 TemporalBetween (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween)3 TemporalFieldValue (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue)3 TemporalLiteral (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral)3 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)3 Date (java.util.Date)2 TimeOverlaps (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 And (org.locationtech.geowave.core.store.query.filter.expression.And)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 Interval (org.threeten.extra.Interval)2 Instant (java.time.Instant)1 Calendar (java.util.Calendar)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 SpatialTemporalOptions (org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions)1