Search in sources :

Example 1 with TextFieldValue

use of org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue in project geowave by locationtech.

the class FilterExpressionTest method testTextExpressions.

@Test
public void testTextExpressions() {
    final DataTypeAdapter<TestType> adapter = new TestTypeBasicDataAdapter();
    final TestType entry = new TestType("test", 1.3, 5, true);
    final TestType entryNulls = new TestType(null, null, null, null);
    final TextLiteral textLit = TextLiteral.of("text");
    final TextLiteral valueLit = TextLiteral.of("value");
    final TextFieldValue textField = TextFieldValue.of("name");
    assertEquals("test", textField.evaluateValue(adapter, entry));
    assertNull(textField.evaluateValue(adapter, entryNulls));
    // Test comparisons
    assertTrue(textLit.isLessThan(valueLit).evaluate(adapter, entry));
    assertFalse(valueLit.isLessThan(textLit).evaluate(adapter, entry));
    assertTrue(textLit.isLessThan("tfxt").evaluate(adapter, entry));
    assertFalse(textLit.isLessThan("text").evaluate(adapter, entry));
    assertTrue(textField.isLessThan(textLit).evaluate(adapter, entry));
    assertFalse(valueLit.isLessThan(TextFieldValue.of("name")).evaluate(adapter, entry));
    assertFalse(textField.isLessThan(textLit).evaluate(adapter, entryNulls));
    assertFalse(textLit.isGreaterThan(valueLit).evaluate(adapter, entry));
    assertTrue(valueLit.isGreaterThan(textLit).evaluate(adapter, entry));
    assertFalse(textLit.isGreaterThan("text").evaluate(adapter, entry));
    assertTrue(textLit.isGreaterThan("tdxt").evaluate(adapter, entry));
    assertFalse(textField.isGreaterThan(textLit).evaluate(adapter, entry));
    assertTrue(valueLit.isGreaterThan(TextFieldValue.of("name")).evaluate(adapter, entry));
    assertFalse(textField.isGreaterThan(textLit).evaluate(adapter, entryNulls));
    assertTrue(textLit.isLessThanOrEqualTo(valueLit).evaluate(adapter, entry));
    assertFalse(valueLit.isLessThanOrEqualTo(textLit).evaluate(adapter, entry));
    assertTrue(textLit.isLessThanOrEqualTo("tfxt").evaluate(adapter, entry));
    assertFalse(textLit.isLessThanOrEqualTo("test").evaluate(adapter, entry));
    assertTrue(textField.isLessThanOrEqualTo(textLit).evaluate(adapter, entry));
    assertFalse(valueLit.isLessThanOrEqualTo(textField).evaluate(adapter, entry));
    assertTrue(valueLit.isLessThanOrEqualTo("value").evaluate(adapter, entry));
    assertFalse(textLit.isGreaterThanOrEqualTo(valueLit).evaluate(adapter, entry));
    assertTrue(valueLit.isGreaterThanOrEqualTo(textLit).evaluate(adapter, entry));
    assertTrue(textLit.isGreaterThanOrEqualTo("text").evaluate(adapter, entry));
    assertTrue(textLit.isGreaterThanOrEqualTo("tdxt").evaluate(adapter, entry));
    assertFalse(textField.isGreaterThanOrEqualTo(textLit).evaluate(adapter, entry));
    assertTrue(valueLit.isGreaterThanOrEqualTo(textField).evaluate(adapter, entry));
    assertTrue(textField.isGreaterThanOrEqualTo("test").evaluate(adapter, entry));
    assertTrue(textField.isEqualTo("test").evaluate(adapter, entry));
    assertFalse(textField.isEqualTo("TEST").evaluate(adapter, entry));
    assertTrue(textField.isEqualTo("TEST", true).evaluate(adapter, entry));
    assertFalse(textField.isEqualTo(textLit).evaluate(adapter, entry));
    assertFalse(textField.isNotEqualTo("test").evaluate(adapter, entry));
    assertTrue(textField.isNotEqualTo("TEST").evaluate(adapter, entry));
    assertFalse(textField.isNotEqualTo("TEST", true).evaluate(adapter, entry));
    assertTrue(textField.isNotEqualTo("TFST", true).evaluate(adapter, entry));
    assertTrue(textField.isNotEqualTo(textLit).evaluate(adapter, entry));
    assertFalse(textLit.isNull().evaluate(adapter, entry));
    assertFalse(valueLit.isNull().evaluate(adapter, entry));
    assertFalse(textField.isNull().evaluate(adapter, entry));
    assertTrue(textField.isNull().evaluate(adapter, entryNulls));
    assertTrue(textLit.isNotNull().evaluate(adapter, entry));
    assertTrue(valueLit.isNotNull().evaluate(adapter, entry));
    assertTrue(textField.isNotNull().evaluate(adapter, entry));
    assertFalse(textField.isNotNull().evaluate(adapter, entryNulls));
    assertFalse(textField.isLessThan(null).evaluate(adapter, entry));
    assertFalse(textField.isGreaterThan(null).evaluate(adapter, entry));
    assertFalse(textField.isLessThanOrEqualTo(null).evaluate(adapter, entry));
    assertFalse(textField.isGreaterThanOrEqualTo(null).evaluate(adapter, entry));
    assertFalse(textField.isEqualTo(null).evaluate(adapter, entry));
    assertTrue(textField.isNotEqualTo(null).evaluate(adapter, entry));
    assertTrue(textField.isEqualTo(textField).evaluate(adapter, entryNulls));
    assertFalse(textField.isEqualTo(textLit).evaluate(adapter, entryNulls));
    assertFalse(textField.isNotEqualTo(null).evaluate(adapter, entryNulls));
    assertTrue(textField.isNotEqualTo(valueLit).evaluate(adapter, entryNulls));
    assertTrue(textField.isBetween("a", "z").evaluate(adapter, entry));
    assertFalse(textLit.isBetween("u", "z").evaluate(adapter, entry));
    assertTrue(textLit.isBetween(textField, valueLit).evaluate(adapter, entry));
    assertFalse(textField.isBetween(textLit, valueLit).evaluate(adapter, entryNulls));
    assertFalse(textLit.isBetween(valueLit, textField).evaluate(adapter, entryNulls));
    assertFalse(textLit.isBetween(textField, valueLit).evaluate(adapter, entryNulls));
    assertFalse(valueLit.isBetween(textLit, textField).evaluate(adapter, entry));
    assertTrue(textLit.isLiteral());
    assertFalse(textField.isLiteral());
    assertTrue(textLit.concat(valueLit).isLiteral());
    assertFalse(textLit.concat(textField).isLiteral());
    assertFalse(textField.concat(textLit).isLiteral());
    // Test functions
    assertEquals("textvalue", textLit.concat(valueLit).evaluateValue(adapter, entry));
    assertEquals("text", textLit.concat(textField).evaluateValue(adapter, entryNulls));
    assertEquals("text", textField.concat(textLit).evaluateValue(adapter, entryNulls));
    assertEquals("text", textLit.concat(null).evaluateValue(adapter, entry));
    assertEquals("text1.5", textLit.concat(1.5).evaluateValue(adapter, entry));
    assertTrue(textLit.contains("ex").evaluate(adapter, entry));
    assertFalse(textLit.contains("EX").evaluate(adapter, entry));
    assertTrue(textLit.contains("EX", true).evaluate(adapter, entry));
    assertFalse(textField.contains(null).evaluate(adapter, entry));
    assertFalse(textField.contains("es").evaluate(adapter, entryNulls));
    assertTrue(textField.contains("test").evaluate(adapter, entry));
    assertTrue(textLit.startsWith("tex").evaluate(adapter, entry));
    assertFalse(textLit.startsWith("TEX").evaluate(adapter, entry));
    assertTrue(textLit.startsWith("TEX", true).evaluate(adapter, entry));
    assertFalse(textField.startsWith(null).evaluate(adapter, entry));
    assertFalse(textField.startsWith("tes").evaluate(adapter, entryNulls));
    assertTrue(textField.startsWith("test").evaluate(adapter, entry));
    assertTrue(textLit.endsWith("xt").evaluate(adapter, entry));
    assertFalse(textLit.endsWith("XT").evaluate(adapter, entry));
    assertTrue(textLit.endsWith("XT", true).evaluate(adapter, entry));
    assertFalse(textField.endsWith(null).evaluate(adapter, entry));
    assertFalse(textField.endsWith("st").evaluate(adapter, entryNulls));
    assertTrue(textField.endsWith("test").evaluate(adapter, entry));
    // Test serialization
    byte[] bytes = PersistenceUtils.toBinary(textField.concat("test"));
    final Concat concat = (Concat) PersistenceUtils.fromBinary(bytes);
    assertTrue(concat.getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) concat.getExpression1()).getFieldName());
    assertTrue(concat.getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) concat.getExpression2()).getValue());
    bytes = PersistenceUtils.toBinary(textField.contains("test", true));
    final Contains contains = (Contains) PersistenceUtils.fromBinary(bytes);
    assertTrue(contains.isIgnoreCase());
    assertTrue(contains.getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) contains.getExpression1()).getFieldName());
    assertTrue(contains.getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) contains.getExpression2()).getValue());
    bytes = PersistenceUtils.toBinary(textField.endsWith("test"));
    final EndsWith endsWith = (EndsWith) PersistenceUtils.fromBinary(bytes);
    assertFalse(endsWith.isIgnoreCase());
    assertTrue(endsWith.getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) endsWith.getExpression1()).getFieldName());
    assertTrue(endsWith.getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) endsWith.getExpression2()).getValue());
    bytes = PersistenceUtils.toBinary(textField.startsWith(null));
    final StartsWith startsWith = (StartsWith) PersistenceUtils.fromBinary(bytes);
    assertFalse(startsWith.isIgnoreCase());
    assertTrue(startsWith.getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) startsWith.getExpression1()).getFieldName());
    assertTrue(startsWith.getExpression2() instanceof TextLiteral);
    assertNull(((TextLiteral) startsWith.getExpression2()).getValue());
}
Also used : Concat(org.locationtech.geowave.core.store.query.filter.expression.text.Concat) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) TestType(org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestType) TestTypeBasicDataAdapter(org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestTypeBasicDataAdapter) 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 TextFieldValue

use of org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue 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());
}
Also used : Or(org.locationtech.geowave.core.store.query.filter.expression.Or) TextComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) DeleteStatement(org.locationtech.geowave.core.store.query.gwql.statement.DeleteStatement) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) NumericBetween(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) DeleteStatement(org.locationtech.geowave.core.store.query.gwql.statement.DeleteStatement) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) 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 TextFieldValue

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

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

use of org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue 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());
}
Also used : Or(org.locationtech.geowave.core.store.query.filter.expression.Or) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) Envelope(org.locationtech.jts.geom.Envelope) StartsWith(org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) SpatialFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue) NumericBetween(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) Geometry(org.locationtech.jts.geom.Geometry) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) And(org.locationtech.geowave.core.store.query.filter.expression.And) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 TextFieldValue (org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue)8 TextLiteral (org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral)8 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)6 NumericComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator)5 NumericFieldValue (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue)5 NumericLiteral (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral)5 DataStore (org.locationtech.geowave.core.store.api.DataStore)4 And (org.locationtech.geowave.core.store.query.filter.expression.And)4 Contains (org.locationtech.geowave.core.store.query.filter.expression.text.Contains)4 StartsWith (org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith)4 TextComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator)3 Statement (org.locationtech.geowave.core.store.query.gwql.statement.Statement)3 BBox (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox)2 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 UnpreparedFilterGeometry (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry)2 TestType (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestType)2 TestTypeBasicDataAdapter (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestTypeBasicDataAdapter)2 Or (org.locationtech.geowave.core.store.query.filter.expression.Or)2