Search in sources :

Example 1 with SelectStatement

use of org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement 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());
}
Also used : SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) TextBinaryPredicate(org.locationtech.geowave.core.store.query.filter.expression.text.TextBinaryPredicate) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) DataStore(org.locationtech.geowave.core.store.api.DataStore) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) StartsWith(org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) EndsWith(org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith) Test(org.junit.Test)

Example 2 with SelectStatement

use of org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement 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());
}
Also used : NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) StartsWith(org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) Concat(org.locationtech.geowave.core.store.query.filter.expression.text.Concat) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) Abs(org.locationtech.geowave.core.store.query.filter.expression.numeric.Abs) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) And(org.locationtech.geowave.core.store.query.filter.expression.And) DataStore(org.locationtech.geowave.core.store.api.DataStore) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) Test(org.junit.Test)

Example 3 with SelectStatement

use of org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement 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);
}
Also used : Add(org.locationtech.geowave.core.store.query.filter.expression.numeric.Add) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) Divide(org.locationtech.geowave.core.store.query.filter.expression.numeric.Divide) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) DataStore(org.locationtech.geowave.core.store.api.DataStore) Multiply(org.locationtech.geowave.core.store.query.filter.expression.numeric.Multiply) Subtract(org.locationtech.geowave.core.store.query.filter.expression.numeric.Subtract) Test(org.junit.Test)

Example 4 with SelectStatement

use of org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement 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());
}
Also used : SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) TextComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) And(org.locationtech.geowave.core.store.query.filter.expression.And) DataStore(org.locationtech.geowave.core.store.api.DataStore) NumericBetween(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween) Test(org.junit.Test)

Example 5 with SelectStatement

use of org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement in project geowave by locationtech.

the class SelectStatementTest method testColumnSubset.

@Test
public void testColumnSubset() {
    final DataStore dataStore = createDataStore();
    final String statement = "SELECT pop, start, end FROM type";
    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.getSelectors());
    assertTrue(selectStatement.getSelectors().size() == 3);
    assertTrue(selectStatement.getSelectors().get(0) instanceof ColumnSelector);
    ColumnSelector selector = (ColumnSelector) selectStatement.getSelectors().get(0);
    assertNull(selector.alias());
    assertEquals("pop", selector.columnName());
    assertTrue(selectStatement.getSelectors().get(1) instanceof ColumnSelector);
    selector = (ColumnSelector) selectStatement.getSelectors().get(1);
    assertNull(selector.alias());
    assertEquals("start", selector.columnName());
    assertTrue(selectStatement.getSelectors().get(2) instanceof ColumnSelector);
    selector = (ColumnSelector) selectStatement.getSelectors().get(2);
    assertNull(selector.alias());
    assertEquals("end", selector.columnName());
    assertNull(selectStatement.getFilter());
}
Also used : SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) DataStore(org.locationtech.geowave.core.store.api.DataStore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 DataStore (org.locationtech.geowave.core.store.api.DataStore)18 SelectStatement (org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement)18 Statement (org.locationtech.geowave.core.store.query.gwql.statement.Statement)18 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)12 NumericFieldValue (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue)4 AbstractGWQLTest (org.locationtech.geowave.core.store.query.gwql.AbstractGWQLTest)4 TemporalFieldValue (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue)3 TemporalLiteral (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral)3 And (org.locationtech.geowave.core.store.query.filter.expression.And)3 NumericComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator)3 NumericLiteral (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral)3 TextComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator)3 TextFieldValue (org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue)3 TextLiteral (org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral)3 SpatialFieldValue (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue)2 SpatialLiteral (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral)2 BeforeOrDuring (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring)2 BinaryTemporalPredicate (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BinaryTemporalPredicate)2 During (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During)2