Search in sources :

Example 1 with Concat

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

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

Aggregations

Test (org.junit.Test)2 Concat (org.locationtech.geowave.core.store.query.filter.expression.text.Concat)2 StartsWith (org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith)2 TextFieldValue (org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue)2 TextLiteral (org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral)2 TestType (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestType)1 TestTypeBasicDataAdapter (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestTypeBasicDataAdapter)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 And (org.locationtech.geowave.core.store.query.filter.expression.And)1 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)1 Abs (org.locationtech.geowave.core.store.query.filter.expression.numeric.Abs)1 NumericComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator)1 NumericFieldValue (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue)1 NumericLiteral (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral)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 SelectStatement (org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement)1 Statement (org.locationtech.geowave.core.store.query.gwql.statement.Statement)1