use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps 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));
}
}
use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps in project geowave by locationtech.
the class GWQLParserTest method testTemporalPredicateFunctions.
@Test
public void testTemporalPredicateFunctions() {
final DataStore dataStore = createDataStore();
String statement = "SELECT * FROM type WHERE tcontains(start, '2020-01-01')";
Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
Filter filter = selectStatement.getFilter();
// During is the inverse of contains, so the operands should be flipped
assertTrue(filter instanceof During);
BinaryTemporalPredicate predicate = (BinaryTemporalPredicate) filter;
assertTrue(predicate.getExpression1() instanceof TemporalLiteral);
assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression1()).getValue().getStart().toEpochMilli());
assertEquals(TemporalExpression.stringToDate("2020-01-01").getTime(), ((TemporalLiteral) predicate.getExpression1()).getValue().getEnd().toEpochMilli());
assertTrue(predicate.getExpression2() instanceof TemporalFieldValue);
assertEquals("start", ((TemporalFieldValue) predicate.getExpression2()).getFieldName());
statement = "SELECT * FROM type WHERE toverlaps(start, '2020-01-01')";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof TimeOverlaps);
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());
}
use of org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps 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());
}
Aggregations