Search in sources :

Example 1 with TextBinaryPredicate

use of org.locationtech.geowave.core.store.query.filter.expression.text.TextBinaryPredicate 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)

Aggregations

Test (org.junit.Test)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)1 Contains (org.locationtech.geowave.core.store.query.filter.expression.text.Contains)1 EndsWith (org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith)1 StartsWith (org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith)1 TextBinaryPredicate (org.locationtech.geowave.core.store.query.filter.expression.text.TextBinaryPredicate)1 TextFieldValue (org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue)1 TextLiteral (org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral)1 SelectStatement (org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement)1 Statement (org.locationtech.geowave.core.store.query.gwql.statement.Statement)1