use of org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween 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.numeric.NumericBetween in project geowave by locationtech.
the class SelectStatementTest method testAllColumnsWithFilterAndLimit.
@Test
public void testAllColumnsWithFilterAndLimit() throws ParseException, IOException {
final DataStore dataStore = createDataStore();
final String statement = "SELECT * FROM type WHERE pop BETWEEN 1000 AND 2000 and pid > 'abc' LIMIT 1";
final Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
final SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
assertFalse(selectStatement.isAggregation());
assertNotNull(selectStatement.getAdapter());
assertEquals("type", selectStatement.getAdapter().getTypeName());
assertNotNull(selectStatement.getFilter());
Filter filter = selectStatement.getFilter();
assertTrue(filter instanceof And);
And andFilter = (And) filter;
assertTrue(andFilter.getChildren().length == 2);
assertTrue(andFilter.getChildren()[0] instanceof NumericBetween);
assertTrue(andFilter.getChildren()[1] instanceof TextComparisonOperator);
assertNotNull(selectStatement.getLimit());
assertEquals(1, selectStatement.getLimit().intValue());
}
use of org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween 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.numeric.NumericBetween in project geowave by locationtech.
the class SelectStatementTest method testAllColumnsWithFilter.
@Test
public void testAllColumnsWithFilter() throws ParseException, IOException {
final DataStore dataStore = createDataStore();
final String statement = "SELECT * FROM type WHERE pop BETWEEN 1000 AND 2000 and pid > 'abc'";
final Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
final SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
assertFalse(selectStatement.isAggregation());
assertNotNull(selectStatement.getAdapter());
assertEquals("type", selectStatement.getAdapter().getTypeName());
assertNotNull(selectStatement.getFilter());
Filter filter = selectStatement.getFilter();
assertTrue(filter instanceof And);
And andFilter = (And) filter;
assertTrue(andFilter.getChildren().length == 2);
assertTrue(andFilter.getChildren()[0] instanceof NumericBetween);
assertTrue(andFilter.getChildren()[1] instanceof TextComparisonOperator);
assertNull(selectStatement.getLimit());
}
use of org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween in project geowave by locationtech.
the class DeleteStatementTest method testDeleteWithFilter.
@Test
public void testDeleteWithFilter() throws ParseException, IOException {
final DataStore dataStore = createDataStore();
final String statement = "DELETE FROM type WHERE pop BETWEEN 1000 AND 2000 and pid > 'abc'";
final Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof DeleteStatement);
final DeleteStatement<?> deleteStatement = (DeleteStatement<?>) gwStatement;
assertNotNull(deleteStatement.getAdapter());
assertEquals("type", deleteStatement.getAdapter().getTypeName());
assertNotNull(deleteStatement.getFilter());
final Filter filter = deleteStatement.getFilter();
assertTrue(filter instanceof And);
final And andFilter = (And) filter;
assertTrue(andFilter.getChildren().length == 2);
assertTrue(andFilter.getChildren()[0] instanceof NumericBetween);
assertTrue(andFilter.getChildren()[1] instanceof TextComparisonOperator);
}
Aggregations