use of org.locationtech.geowave.core.store.query.filter.expression.Or in project geowave by locationtech.
the class DeleteStatementTest method testComplexStatement.
@Test
public void testComplexStatement() {
final DataStore dataStore = createDataStore();
final Statement statement = GWQLParser.parseStatement(dataStore, "DELETE FROM type " + "WHERE (pop < 1) " + "AND ((pop > 48 OR pid > 'a') AND (pop BETWEEN 0 AND 10 OR pid <= 'b'))");
assertTrue(statement instanceof DeleteStatement);
final DeleteStatement<?> deleteStatement = (DeleteStatement<?>) statement;
assertNotNull(deleteStatement.getAdapter());
assertEquals("type", deleteStatement.getAdapter().getTypeName());
assertNotNull(deleteStatement.getFilter());
final Filter filter = deleteStatement.getFilter();
assertTrue(filter instanceof And);
And andFilter = (And) filter;
assertTrue(andFilter.getChildren().length == 2);
assertTrue(andFilter.getChildren()[0] instanceof NumericComparisonOperator);
NumericComparisonOperator compareOp = (NumericComparisonOperator) andFilter.getChildren()[0];
assertTrue(compareOp.getCompareOp().equals(CompareOp.LESS_THAN));
assertTrue(compareOp.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) compareOp.getExpression1()).getFieldName());
assertTrue(compareOp.getExpression2() instanceof NumericLiteral);
assertEquals(1, ((NumericLiteral) compareOp.getExpression2()).getValue(), 0.00001);
assertTrue(andFilter.getChildren()[1] instanceof And);
andFilter = (And) andFilter.getChildren()[1];
assertTrue(andFilter.getChildren().length == 2);
assertTrue(andFilter.getChildren()[0] instanceof Or);
Or orFilter = (Or) andFilter.getChildren()[0];
assertTrue(orFilter.getChildren().length == 2);
assertTrue(orFilter.getChildren()[0] instanceof NumericComparisonOperator);
final NumericComparisonOperator numericCompare = (NumericComparisonOperator) orFilter.getChildren()[0];
assertTrue(numericCompare.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) numericCompare.getExpression1()).getFieldName());
assertTrue(numericCompare.getExpression2() instanceof NumericLiteral);
assertEquals(48, ((NumericLiteral) numericCompare.getExpression2()).evaluateValue(null), 0.00001);
assertTrue(orFilter.getChildren()[1] instanceof TextComparisonOperator);
TextComparisonOperator textCompareOp = (TextComparisonOperator) orFilter.getChildren()[1];
assertTrue(textCompareOp.getCompareOp().equals(CompareOp.GREATER_THAN));
assertTrue(textCompareOp.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) textCompareOp.getExpression1()).getFieldName());
assertTrue(textCompareOp.getExpression2() instanceof TextLiteral);
assertEquals("a", ((TextLiteral) textCompareOp.getExpression2()).getValue());
assertTrue(andFilter.getChildren()[1] instanceof Or);
orFilter = (Or) andFilter.getChildren()[1];
assertTrue(orFilter.getChildren().length == 2);
assertTrue(orFilter.getChildren()[0] instanceof NumericBetween);
NumericBetween between = (NumericBetween) orFilter.getChildren()[0];
assertTrue(between.getValue() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) between.getValue()).getFieldName());
assertTrue(between.getLowerBound() instanceof NumericLiteral);
assertEquals(0, ((NumericLiteral) between.getLowerBound()).getValue(), 0.00001);
assertTrue(between.getUpperBound() instanceof NumericLiteral);
assertEquals(10, ((NumericLiteral) between.getUpperBound()).getValue(), 0.00001);
assertTrue(orFilter.getChildren()[1] instanceof TextComparisonOperator);
textCompareOp = (TextComparisonOperator) orFilter.getChildren()[1];
assertTrue(textCompareOp.getCompareOp().equals(CompareOp.LESS_THAN_OR_EQUAL));
assertTrue(textCompareOp.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) textCompareOp.getExpression1()).getFieldName());
assertTrue(textCompareOp.getExpression2() instanceof TextLiteral);
assertEquals("b", ((TextLiteral) textCompareOp.getExpression2()).getValue());
}
use of org.locationtech.geowave.core.store.query.filter.expression.Or in project geowave by locationtech.
the class ExpressionQueryIT method testIndexSelection.
@Test
public void testIndexSelection() {
final DataStore ds = dataStore.createDataStore();
final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
final Index spatialTemporalIndex = SpatialTemporalDimensionalityTypeProvider.createIndexFromOptions(new SpatialTemporalOptions());
final Index temporalIndex = TemporalDimensionalityTypeProvider.createIndexFromOptions(new TemporalOptions());
ds.addType(adapter, spatialIndex, spatialTemporalIndex, temporalIndex);
final Index altIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ALTERNATE_GEOMETRY_FIELD));
final Index integerIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, INTEGER_FIELD));
final Index commentIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, COMMENT_FIELD));
final Index idIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ID_FIELD));
final Index latitudeIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, LATITUDE_FIELD));
final Index longitudeIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, LONGITUDE_FIELD));
ds.addIndex(TYPE_NAME, altIndex, integerIndex, commentIndex, idIndex, latitudeIndex, longitudeIndex);
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);
// ///////////////////////////////////////////////////
// Basic BBOX on Alternate Geometry
// ///////////////////////////////////////////////////
Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, 0.5, 0.5, 64.5)).build();
QueryConstraints queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
ExplicitFilteredQuery constraints = (ExplicitFilteredQuery) queryConstraints;
List<QueryFilter> filters = constraints.createFilters(altIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
assertTrue(filter instanceof BBox);
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Both bbox and comment are indexed, but comment
// should result in fewer rows queried so that
// should be the selected index
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, -32.5, 32.5, 64.5).and(COMMENT.startsWith("b", true))).build();
queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof CustomQueryConstraints);
CustomQueryConstraints<?> customConstraints = (CustomQueryConstraints<?>) queryConstraints;
filters = customConstraints.createFilters(commentIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// Comment predicate was exact so only the bbox filter should need to be performed
assertTrue(filter instanceof BBox);
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
int count = 0;
while (iterator.hasNext()) {
final SimpleFeature feature = iterator.next();
assertEquals("Bravo", feature.getAttribute(COMMENT_FIELD));
count++;
}
// 1/4 of entries match the comment predicate, but only 3/4 of those match the bounding box
assertEquals(Math.round(TOTAL_FEATURES / 8 * 1.5), count);
}
// ///////////////////////////////////////////////////
// Both bbox and comment are indexed, but bbox should
// result in fewer rows queried so that should be the
// selected index
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, 32.5, -32.5, 64.5).and(COMMENT.startsWith("b", true))).build();
queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(altIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// bbox is not exact, so it will still be part of the filter
assertTrue(filter instanceof And);
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(TOTAL_FEATURES / 16, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Latitude is the most constraining
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LATITUDE.isGreaterThan(5).and(LATITUDE.isLessThan(10), LONGITUDE.isGreaterThanOrEqualTo(7))).build();
queryConstraints = assertBestIndex(internalAdapter, latitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(latitudeIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// since the latitude fields are exact, only the longitude needs to be filtered later
assertTrue(filter instanceof ComparisonOperator);
Set<String> referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(LONGITUDE_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(3, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Longitude is the most constraining
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LONGITUDE.isGreaterThanOrEqualTo(5).and(LONGITUDE.isLessThan(10).or(LATITUDE.isLessThanOrEqualTo(15)))).build();
queryConstraints = assertBestIndex(internalAdapter, longitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(longitudeIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// The second half of the expression cannot be predetermined, so both sides of the Or need to be
// present
assertTrue(filter instanceof Or);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(2, referencedFields.size());
assertTrue(referencedFields.contains(LATITUDE_FIELD));
assertTrue(referencedFields.contains(LONGITUDE_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(11, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Longitude is an exact range
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LONGITUDE.isLessThan(-31.5).or(LONGITUDE.isGreaterThan(31.5))).build();
queryConstraints = assertBestIndex(internalAdapter, longitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(longitudeIndex);
// The constraints are exact, so there shouldn't be any additional filtering
assertEquals(0, filters.size());
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(TOTAL_FEATURES / 2 + 1, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Default geom only should select spatial index
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 10.5, 10.5)).build();
queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(spatialIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// BBox isn't exact, so it should still be filtered
assertTrue(filter instanceof BBox);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(10, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Default geom and time should select spatial-
// temporal index
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 30.5, 30.5).and(TIMESTAMP.isBefore(new Date((long) (66 * ONE_DAY_MILLIS + 1))))).build();
queryConstraints = assertBestIndex(internalAdapter, spatialTemporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(spatialTemporalIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// BBox isn't exact, and neither is timestamp in a binned temporal index
assertTrue(filter instanceof And);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(2, referencedFields.size());
assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
assertTrue(referencedFields.contains(TIMESTAMP_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(2, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Only timestamp should use temporal index
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isBefore(new Date((long) (66 * ONE_DAY_MILLIS + 1)))).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());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// Timestamp is not exact on temporal index because there could be ranges
assertTrue(filter instanceof Before);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(TIMESTAMP_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(67, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Integer is more constraining, half of the ID
// values end with 0
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ID.endsWith("0").and(INTEGER.isBetween(10, 20))).build();
queryConstraints = assertBestIndex(internalAdapter, integerIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(integerIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// Integer is exact, so only the string predicate should remain
assertTrue(filter instanceof EndsWith);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(ID_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(6, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// ID is more constraining
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ID.endsWith("a0").and(INTEGER.isBetween(0, 40))).build();
queryConstraints = assertBestIndex(internalAdapter, idIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof CustomQueryConstraints);
customConstraints = (CustomQueryConstraints<?>) queryConstraints;
filters = customConstraints.createFilters(commentIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// ID constraint is exact, so only the integer predicate should remain
assertTrue(filter instanceof Between);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(INTEGER_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(2, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Alternate geometry is 50% null, so it is more
// constraining
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(-30.5, -30.5, 30.5, 30.5).and(ALT.bbox(-30.5, -30.5, 30.5, 30.5))).build();
queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(altIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// Neither bbox is exact, so they will both be filtered
assertTrue(filter instanceof And);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(2, referencedFields.size());
assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
assertTrue(referencedFields.contains(ALTERNATE_GEOMETRY_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(30, Iterators.size(iterator));
}
// ///////////////////////////////////////////////////
// Integer is more constraining
// ///////////////////////////////////////////////////
query = QueryBuilder.newBuilder(SimpleFeature.class).filter(INTEGER.isLessThan(-60).and(LATITUDE.isLessThan(5))).build();
queryConstraints = assertBestIndex(internalAdapter, integerIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
constraints = (ExplicitFilteredQuery) queryConstraints;
filters = constraints.createFilters(integerIndex);
assertEquals(1, filters.size());
assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
// Neither bbox is exact, so they will both be filtered
assertTrue(filter instanceof ComparisonOperator);
referencedFields = Sets.newHashSet();
filter.addReferencedFields(referencedFields);
assertEquals(1, referencedFields.size());
assertTrue(referencedFields.contains(LATITUDE_FIELD));
// Query data
try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
assertTrue(iterator.hasNext());
assertEquals(4, Iterators.size(iterator));
}
}
use of org.locationtech.geowave.core.store.query.filter.expression.Or in project geowave by locationtech.
the class CQLToGeoWaveFilterTest method testComplexConstraints.
@Test
public void testComplexConstraints() throws CQLException {
final Filter f = fromCQL("BBOX(geom, 5, 20, 8, 30) AND ((A BETWEEN 5 AND 10 AND B < 10) OR (A BETWEEN 15 AND 20 AND B > 5)) AND name LIKE 'aBc%'");
// This filter should result in the following constraints:
// A -> [5, 10], [15, 20]
// B -> [null, null] // B > 5 OR B < 10 is a full scan
// geom -> [5, 8] // geom dimension 0
// [20, 30] // geom dimension 1
// str -> ["aBc", "aBd") // "aBd" is exclusive
assertTrue(f instanceof And);
assertEquals(2, ((And) f).getChildren().length);
assertTrue(((And) f).getChildren()[0] instanceof And);
assertEquals(2, ((And) ((And) f).getChildren()[0]).getChildren().length);
assertTrue(((And) ((And) f).getChildren()[0]).getChildren()[0] instanceof BBox);
final BBox bbox = (BBox) ((And) ((And) f).getChildren()[0]).getChildren()[0];
assertTrue(bbox.getExpression1() instanceof SpatialFieldValue);
assertEquals("geom", ((SpatialFieldValue) bbox.getExpression1()).getFieldName());
assertTrue(bbox.getExpression2() instanceof SpatialLiteral);
SpatialLiteral spatialLit = (SpatialLiteral) bbox.getExpression2();
assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
Geometry geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(5, 8, 20, 30))));
assertTrue(((And) ((And) f).getChildren()[0]).getChildren()[1] instanceof Or);
final Or or = (Or) ((And) ((And) f).getChildren()[0]).getChildren()[1];
assertEquals(2, or.getChildren().length);
assertTrue(or.getChildren()[0] instanceof And);
And and = (And) or.getChildren()[0];
assertEquals(2, and.getChildren().length);
assertTrue(and.getChildren()[0] instanceof NumericBetween);
NumericBetween between = (NumericBetween) and.getChildren()[0];
assertTrue(between.getValue() instanceof NumericFieldValue);
assertEquals("A", ((NumericFieldValue) between.getValue()).getFieldName());
assertTrue(between.getLowerBound() instanceof NumericLiteral);
assertEquals(5L, ((NumericLiteral) between.getLowerBound()).getValue().longValue());
assertTrue(between.getUpperBound() instanceof NumericLiteral);
assertEquals(10L, ((NumericLiteral) between.getUpperBound()).getValue().longValue());
assertTrue(and.getChildren()[1] instanceof NumericComparisonOperator);
NumericComparisonOperator compareOp = (NumericComparisonOperator) and.getChildren()[1];
assertEquals(CompareOp.LESS_THAN, compareOp.getCompareOp());
assertTrue(compareOp.getExpression1() instanceof NumericFieldValue);
assertEquals("B", ((NumericFieldValue) compareOp.getExpression1()).getFieldName());
assertTrue(compareOp.getExpression2() instanceof NumericLiteral);
assertEquals(10L, ((NumericLiteral) compareOp.getExpression2()).getValue().longValue());
assertTrue(or.getChildren()[1] instanceof And);
and = (And) or.getChildren()[1];
assertEquals(2, and.getChildren().length);
assertTrue(and.getChildren()[0] instanceof NumericBetween);
between = (NumericBetween) and.getChildren()[0];
assertTrue(between.getValue() instanceof NumericFieldValue);
assertEquals("A", ((NumericFieldValue) between.getValue()).getFieldName());
assertTrue(between.getLowerBound() instanceof NumericLiteral);
assertEquals(15L, ((NumericLiteral) between.getLowerBound()).getValue().longValue());
assertTrue(between.getUpperBound() instanceof NumericLiteral);
assertEquals(20L, ((NumericLiteral) between.getUpperBound()).getValue().longValue());
assertTrue(and.getChildren()[1] instanceof NumericComparisonOperator);
compareOp = (NumericComparisonOperator) and.getChildren()[1];
assertEquals(CompareOp.GREATER_THAN, compareOp.getCompareOp());
assertTrue(compareOp.getExpression1() instanceof NumericFieldValue);
assertEquals("B", ((NumericFieldValue) compareOp.getExpression1()).getFieldName());
assertTrue(compareOp.getExpression2() instanceof NumericLiteral);
assertEquals(5L, ((NumericLiteral) compareOp.getExpression2()).getValue().longValue());
assertTrue(((And) f).getChildren()[1] instanceof StartsWith);
final StartsWith startsWith = (StartsWith) ((And) f).getChildren()[1];
assertTrue(startsWith.getExpression1() instanceof TextFieldValue);
assertEquals("name", ((TextFieldValue) startsWith.getExpression1()).getFieldName());
assertTrue(startsWith.getExpression2() instanceof TextLiteral);
assertEquals("aBc", ((TextLiteral) startsWith.getExpression2()).getValue());
// Check geom constraints
final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
AdapterToIndexMapping mapping = BaseDataStoreUtils.mapAdapterToIndex(adapter.asInternalAdapter((short) 0), spatialIndex);
FilterConstraints<Double> constraints = f.getConstraints(Double.class, null, adapter, mapping, spatialIndex, Sets.newHashSet("geom"));
IndexFieldConstraints<?> fieldConstraints = constraints.getFieldConstraints("geom");
assertNotNull(fieldConstraints);
DimensionConstraints<?> dimRanges = fieldConstraints.getDimensionRanges(0);
assertNotNull(dimRanges);
assertEquals(1, dimRanges.getRanges().size());
assertEquals(5L, ((Double) dimRanges.getRanges().get(0).getStart()).longValue());
assertTrue(dimRanges.getRanges().get(0).isStartInclusive());
assertEquals(8L, ((Double) dimRanges.getRanges().get(0).getEnd()).longValue());
assertTrue(dimRanges.getRanges().get(0).isEndInclusive());
assertFalse(dimRanges.getRanges().get(0).isExact());
dimRanges = fieldConstraints.getDimensionRanges(1);
assertNotNull(dimRanges);
assertEquals(1, dimRanges.getRanges().size());
assertEquals(20L, ((Double) dimRanges.getRanges().get(0).getStart()).longValue());
assertTrue(dimRanges.getRanges().get(0).isStartInclusive());
assertEquals(30L, ((Double) dimRanges.getRanges().get(0).getEnd()).longValue());
assertTrue(dimRanges.getRanges().get(0).isEndInclusive());
assertFalse(dimRanges.getRanges().get(0).isExact());
// Check A constraints
final Index aIndex = AttributeDimensionalityTypeProvider.createIndexForDescriptor(adapter, adapter.getFieldDescriptor("A"), "aIndex");
mapping = BaseDataStoreUtils.mapAdapterToIndex(adapter.asInternalAdapter((short) 0), aIndex);
constraints = f.getConstraints(Double.class, null, adapter, mapping, aIndex, Sets.newHashSet("A"));
fieldConstraints = constraints.getFieldConstraints("A");
assertNotNull(fieldConstraints);
dimRanges = fieldConstraints.getDimensionRanges(0);
assertNotNull(dimRanges);
assertEquals(2, dimRanges.getRanges().size());
assertEquals(5L, ((Double) dimRanges.getRanges().get(0).getStart()).longValue());
assertTrue(dimRanges.getRanges().get(0).isStartInclusive());
assertEquals(10L, ((Double) dimRanges.getRanges().get(0).getEnd()).longValue());
assertTrue(dimRanges.getRanges().get(0).isEndInclusive());
assertTrue(dimRanges.getRanges().get(0).isExact());
assertEquals(15L, ((Double) dimRanges.getRanges().get(1).getStart()).longValue());
assertTrue(dimRanges.getRanges().get(1).isStartInclusive());
assertEquals(20L, ((Double) dimRanges.getRanges().get(1).getEnd()).longValue());
assertTrue(dimRanges.getRanges().get(1).isEndInclusive());
assertTrue(dimRanges.getRanges().get(1).isExact());
// Check B constraints
final Index bIndex = AttributeDimensionalityTypeProvider.createIndexForDescriptor(adapter, adapter.getFieldDescriptor("B"), "bIndex");
mapping = BaseDataStoreUtils.mapAdapterToIndex(adapter.asInternalAdapter((short) 0), bIndex);
constraints = f.getConstraints(Double.class, null, adapter, mapping, bIndex, Sets.newHashSet("B"));
fieldConstraints = constraints.getFieldConstraints("B");
assertNotNull(fieldConstraints);
dimRanges = fieldConstraints.getDimensionRanges(0);
assertNotNull(dimRanges);
assertEquals(1, dimRanges.getRanges().size());
assertNull(dimRanges.getRanges().get(0).getStart());
assertTrue(dimRanges.getRanges().get(0).isStartInclusive());
assertNull(dimRanges.getRanges().get(0).getEnd());
assertTrue(dimRanges.getRanges().get(0).isEndInclusive());
assertTrue(dimRanges.getRanges().get(0).isExact());
// Check name constraints
final Index nameIndex = AttributeDimensionalityTypeProvider.createIndexForDescriptor(adapter, adapter.getFieldDescriptor("name"), "nameIndex");
mapping = BaseDataStoreUtils.mapAdapterToIndex(adapter.asInternalAdapter((short) 0), nameIndex);
FilterConstraints<String> textConstraints = f.getConstraints(String.class, null, adapter, mapping, nameIndex, Sets.newHashSet("name"));
fieldConstraints = textConstraints.getFieldConstraints("name");
assertNotNull(fieldConstraints);
dimRanges = fieldConstraints.getDimensionRanges(0);
assertNotNull(dimRanges);
assertEquals(1, dimRanges.getRanges().size());
assertEquals("aBc", dimRanges.getRanges().get(0).getStart());
assertTrue(dimRanges.getRanges().get(0).isStartInclusive());
assertEquals("aBc", dimRanges.getRanges().get(0).getEnd());
assertTrue(dimRanges.getRanges().get(0).isEndInclusive());
assertTrue(dimRanges.getRanges().get(0).isExact());
}
use of org.locationtech.geowave.core.store.query.filter.expression.Or 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
}
}
Aggregations