use of org.locationtech.geowave.core.store.query.gwql.statement.Statement in project geowave by locationtech.
the class DeleteStatementTest method testDelete.
@Test
public void testDelete() throws ParseException, IOException {
final DataStore dataStore = createDataStore();
final String statement = "DELETE FROM type";
final Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof DeleteStatement);
final DeleteStatement<?> deleteStatement = (DeleteStatement<?>) gwStatement;
assertNotNull(deleteStatement.getAdapter());
assertEquals("type", deleteStatement.getAdapter().getTypeName());
assertNull(deleteStatement.getFilter());
}
use of org.locationtech.geowave.core.store.query.gwql.statement.Statement 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.gwql.statement.Statement in project geowave by locationtech.
the class GWQLParserTest method testTextPredicateFunctions.
@Test
public void testTextPredicateFunctions() {
final DataStore dataStore = createDataStore();
String statement = "SELECT * FROM type WHERE strStartsWith(pid, 'val')";
Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
Filter filter = selectStatement.getFilter();
assertTrue(filter instanceof StartsWith);
TextBinaryPredicate predicate = (TextBinaryPredicate) filter;
assertFalse(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
statement = "SELECT * FROM type WHERE strStartsWith(pid, 'val', true)";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof StartsWith);
predicate = (TextBinaryPredicate) filter;
assertTrue(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
statement = "SELECT * FROM type WHERE strEndsWith(pid, 'val')";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof EndsWith);
predicate = (TextBinaryPredicate) filter;
assertFalse(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
statement = "SELECT * FROM type WHERE strEndsWith(pid, 'val', true)";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof EndsWith);
predicate = (TextBinaryPredicate) filter;
assertTrue(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
statement = "SELECT * FROM type WHERE strContains(pid, 'val')";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof Contains);
predicate = (TextBinaryPredicate) filter;
assertFalse(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
statement = "SELECT * FROM type WHERE strContains(pid, 'val', true)";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof Contains);
predicate = (TextBinaryPredicate) filter;
assertTrue(predicate.isIgnoreCase());
assertTrue(predicate.getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) predicate.getExpression1()).getFieldName());
assertTrue(predicate.getExpression2() instanceof TextLiteral);
assertEquals("val", ((TextLiteral) predicate.getExpression2()).getValue());
}
use of org.locationtech.geowave.core.store.query.gwql.statement.Statement in project geowave by locationtech.
the class GWQLParserTest method testExpressionFunctions.
@Test
public void testExpressionFunctions() {
final DataStore dataStore = createDataStore();
final String statement = "SELECT * FROM type WHERE abs(pop) > 10 AND strStartsWith(concat(pid, 'value'), '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());
final Filter filter = selectStatement.getFilter();
assertTrue(filter instanceof And);
final And and = (And) filter;
assertEquals(2, and.getChildren().length);
assertTrue(and.getChildren()[0] instanceof NumericComparisonOperator);
final NumericComparisonOperator compareOp = (NumericComparisonOperator) and.getChildren()[0];
assertTrue(compareOp.getCompareOp().equals(CompareOp.GREATER_THAN));
assertTrue(compareOp.getExpression1() instanceof Abs);
assertTrue(((Abs) compareOp.getExpression1()).getExpression() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) ((Abs) compareOp.getExpression1()).getExpression()).getFieldName());
assertTrue(compareOp.getExpression2() instanceof NumericLiteral);
assertEquals(10.0, ((NumericLiteral) compareOp.getExpression2()).getValue(), 0.00001);
assertTrue(and.getChildren()[1] instanceof StartsWith);
final StartsWith startsWith = (StartsWith) and.getChildren()[1];
assertTrue(startsWith.getExpression1() instanceof Concat);
assertTrue(((Concat) startsWith.getExpression1()).getExpression1() instanceof TextFieldValue);
assertEquals("pid", ((TextFieldValue) ((Concat) startsWith.getExpression1()).getExpression1()).getFieldName());
assertTrue(((Concat) startsWith.getExpression1()).getExpression2() instanceof TextLiteral);
assertEquals("value", ((TextLiteral) ((Concat) startsWith.getExpression1()).getExpression2()).getValue());
assertTrue(startsWith.getExpression2() instanceof TextLiteral);
assertEquals("abc", ((TextLiteral) startsWith.getExpression2()).getValue());
}
use of org.locationtech.geowave.core.store.query.gwql.statement.Statement in project geowave by locationtech.
the class GWQLParserTest method testMathExpression.
@Test
public void testMathExpression() {
final DataStore dataStore = createDataStore();
String statement = "SELECT * FROM type WHERE pop + 5 > 25";
Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
Filter filter = selectStatement.getFilter();
assertTrue(filter instanceof NumericComparisonOperator);
NumericComparisonOperator compare = (NumericComparisonOperator) filter;
assertEquals(CompareOp.GREATER_THAN, compare.getCompareOp());
assertTrue(compare.getExpression1() instanceof Add);
Add add = (Add) compare.getExpression1();
assertTrue(add.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) add.getExpression1()).getFieldName());
assertTrue(add.getExpression2() instanceof NumericLiteral);
assertEquals(5, ((NumericLiteral) add.getExpression2()).getValue(), 0.000001);
assertTrue(compare.getExpression2() instanceof NumericLiteral);
assertEquals(25, ((NumericLiteral) compare.getExpression2()).getValue(), 0.000001);
statement = "SELECT * FROM type WHERE pop - 5 > 25";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof NumericComparisonOperator);
compare = (NumericComparisonOperator) filter;
assertEquals(CompareOp.GREATER_THAN, compare.getCompareOp());
assertTrue(compare.getExpression1() instanceof Subtract);
Subtract subtract = (Subtract) compare.getExpression1();
assertTrue(subtract.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) subtract.getExpression1()).getFieldName());
assertTrue(subtract.getExpression2() instanceof NumericLiteral);
assertEquals(5, ((NumericLiteral) subtract.getExpression2()).getValue(), 0.000001);
assertTrue(compare.getExpression2() instanceof NumericLiteral);
assertEquals(25, ((NumericLiteral) compare.getExpression2()).getValue(), 0.000001);
statement = "SELECT * FROM type WHERE pop * 5 > 25";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof NumericComparisonOperator);
compare = (NumericComparisonOperator) filter;
assertEquals(CompareOp.GREATER_THAN, compare.getCompareOp());
assertTrue(compare.getExpression1() instanceof Multiply);
Multiply multiply = (Multiply) compare.getExpression1();
assertTrue(multiply.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) multiply.getExpression1()).getFieldName());
assertTrue(multiply.getExpression2() instanceof NumericLiteral);
assertEquals(5, ((NumericLiteral) multiply.getExpression2()).getValue(), 0.000001);
assertTrue(compare.getExpression2() instanceof NumericLiteral);
assertEquals(25, ((NumericLiteral) compare.getExpression2()).getValue(), 0.000001);
statement = "SELECT * FROM type WHERE pop / 5 > 25";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof NumericComparisonOperator);
compare = (NumericComparisonOperator) filter;
assertEquals(CompareOp.GREATER_THAN, compare.getCompareOp());
assertTrue(compare.getExpression1() instanceof Divide);
Divide divide = (Divide) compare.getExpression1();
assertTrue(divide.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) divide.getExpression1()).getFieldName());
assertTrue(divide.getExpression2() instanceof NumericLiteral);
assertEquals(5, ((NumericLiteral) divide.getExpression2()).getValue(), 0.000001);
assertTrue(compare.getExpression2() instanceof NumericLiteral);
assertEquals(25, ((NumericLiteral) compare.getExpression2()).getValue(), 0.000001);
// Test order of operations
// (pop + ((5 * (pop - 8)) / 6))
statement = "SELECT * FROM type WHERE pop + 5 * (pop - 8) / 6 > 25";
gwStatement = GWQLParser.parseStatement(dataStore, statement);
assertTrue(gwStatement instanceof SelectStatement);
selectStatement = (SelectStatement<?>) gwStatement;
assertNotNull(selectStatement.getFilter());
filter = selectStatement.getFilter();
assertTrue(filter instanceof NumericComparisonOperator);
compare = (NumericComparisonOperator) filter;
assertEquals(CompareOp.GREATER_THAN, compare.getCompareOp());
assertTrue(compare.getExpression1() instanceof Add);
add = (Add) compare.getExpression1();
assertTrue(add.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) add.getExpression1()).getFieldName());
assertTrue(add.getExpression2() instanceof Divide);
divide = (Divide) add.getExpression2();
assertTrue(divide.getExpression1() instanceof Multiply);
multiply = (Multiply) divide.getExpression1();
assertTrue(multiply.getExpression1() instanceof NumericLiteral);
assertEquals(5, ((NumericLiteral) multiply.getExpression1()).getValue(), 0.000001);
assertTrue(multiply.getExpression2() instanceof Subtract);
subtract = (Subtract) multiply.getExpression2();
assertTrue(subtract.getExpression1() instanceof NumericFieldValue);
assertEquals("pop", ((NumericFieldValue) subtract.getExpression1()).getFieldName());
assertTrue(subtract.getExpression2() instanceof NumericLiteral);
assertEquals(8, ((NumericLiteral) subtract.getExpression2()).getValue(), 0.000001);
assertTrue(divide.getExpression2() instanceof NumericLiteral);
assertEquals(6, ((NumericLiteral) divide.getExpression2()).getValue(), 0.000001);
assertTrue(compare.getExpression2() instanceof NumericLiteral);
assertEquals(25, ((NumericLiteral) compare.getExpression2()).getValue(), 0.000001);
}
Aggregations