Search in sources :

Example 1 with Contains

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

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

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

the class FilterExpressionTest method testFilters.

@Test
public void testFilters() {
    final DataTypeAdapter<TestType> adapter = new TestTypeBasicDataAdapter();
    final TestType entry = new TestType("test", 1.3, 5, true);
    final NumericFieldValue doubleField = NumericFieldValue.of("doubleField");
    final NumericFieldValue intField = NumericFieldValue.of("intField");
    final TextFieldValue textField = TextFieldValue.of("name");
    // Test And
    assertTrue(doubleField.isLessThan(2).and(textField.concat("oreo").contains("store")).evaluate(adapter, entry));
    assertFalse(intField.isGreaterThan(doubleField).and(intField.isGreaterThan(10)).evaluate(adapter, entry));
    assertFalse(doubleField.isEqualTo(intField).and(intField.isNotNull()).evaluate(adapter, entry));
    assertFalse(textField.contains("val").and(intField.isLessThan(0)).evaluate(adapter, entry));
    // Test Or
    assertTrue(doubleField.isLessThan(2).or(textField.concat("oreo").contains("store")).evaluate(adapter, entry));
    assertTrue(intField.isGreaterThan(doubleField).or(intField.isGreaterThan(10)).evaluate(adapter, entry));
    assertTrue(doubleField.isEqualTo(intField).or(intField.isNotNull()).evaluate(adapter, entry));
    assertFalse(textField.contains("val").or(intField.isLessThan(0)).evaluate(adapter, entry));
    // Test Not
    assertFalse(Filter.not(doubleField.isLessThan(2)).evaluate(adapter, entry));
    assertFalse(Filter.not(doubleField.isLessThan(2).and(textField.concat("oreo").contains("store"))).evaluate(adapter, entry));
    assertTrue(Filter.not(intField.isGreaterThan(doubleField).and(intField.isGreaterThan(10))).evaluate(adapter, entry));
    assertTrue(Filter.not(doubleField.isEqualTo(intField).and(intField.isNotNull())).evaluate(adapter, entry));
    assertTrue(Filter.not(textField.contains("val").and(intField.isLessThan(0))).evaluate(adapter, entry));
    // Test include/exclude
    assertTrue(Filter.include().evaluate(null, null));
    assertFalse(Filter.exclude().evaluate(null, null));
    // Test serialization
    byte[] bytes = PersistenceUtils.toBinary(textField.contains("test").and(intField.isLessThan(1L)));
    final And and = (And) PersistenceUtils.fromBinary(bytes);
    assertEquals(2, and.getChildren().length);
    assertTrue(and.getChildren()[0] instanceof Contains);
    assertTrue(((Contains) and.getChildren()[0]).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) and.getChildren()[0]).getExpression1()).getFieldName());
    assertTrue(((Contains) and.getChildren()[0]).getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) ((Contains) and.getChildren()[0]).getExpression2()).getValue());
    assertTrue(and.getChildren()[1] instanceof NumericComparisonOperator);
    assertEquals(CompareOp.LESS_THAN, ((NumericComparisonOperator) and.getChildren()[1]).getCompareOp());
    assertTrue(((NumericComparisonOperator) and.getChildren()[1]).getExpression1() instanceof NumericFieldValue);
    assertEquals("intField", ((NumericFieldValue) ((NumericComparisonOperator) and.getChildren()[1]).getExpression1()).getFieldName());
    assertTrue(((NumericComparisonOperator) and.getChildren()[1]).getExpression2() instanceof NumericLiteral);
    assertEquals(1.0, (double) ((NumericLiteral) ((NumericComparisonOperator) and.getChildren()[1]).getExpression2()).getValue(), EPSILON);
    bytes = PersistenceUtils.toBinary(textField.contains("test").or(intField.isLessThan(1L)));
    final Or or = (Or) PersistenceUtils.fromBinary(bytes);
    assertEquals(2, or.getChildren().length);
    assertTrue(or.getChildren()[0] instanceof Contains);
    assertTrue(((Contains) or.getChildren()[0]).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) or.getChildren()[0]).getExpression1()).getFieldName());
    assertTrue(((Contains) or.getChildren()[0]).getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) ((Contains) or.getChildren()[0]).getExpression2()).getValue());
    assertTrue(or.getChildren()[1] instanceof NumericComparisonOperator);
    assertEquals(CompareOp.LESS_THAN, ((NumericComparisonOperator) or.getChildren()[1]).getCompareOp());
    assertTrue(((NumericComparisonOperator) or.getChildren()[1]).getExpression1() instanceof NumericFieldValue);
    assertEquals("intField", ((NumericFieldValue) ((NumericComparisonOperator) or.getChildren()[1]).getExpression1()).getFieldName());
    assertTrue(((NumericComparisonOperator) or.getChildren()[1]).getExpression2() instanceof NumericLiteral);
    assertEquals(1.0, (double) ((NumericLiteral) ((NumericComparisonOperator) and.getChildren()[1]).getExpression2()).getValue(), EPSILON);
    bytes = PersistenceUtils.toBinary(Filter.include());
    assertTrue(PersistenceUtils.fromBinary(bytes) instanceof Include);
    bytes = PersistenceUtils.toBinary(Filter.exclude());
    assertTrue(PersistenceUtils.fromBinary(bytes) instanceof Exclude);
    bytes = PersistenceUtils.toBinary(Filter.not(textField.contains("test")));
    final Not not = (Not) PersistenceUtils.fromBinary(bytes);
    assertTrue(not.getFilter() instanceof Contains);
    assertTrue(((Contains) not.getFilter()).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) not.getFilter()).getExpression1()).getFieldName());
    assertTrue(((Contains) not.getFilter()).getExpression2() instanceof TextLiteral);
    assertEquals("test", (String) ((TextLiteral) ((Contains) not.getFilter()).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) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) TestType(org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestType) TestTypeBasicDataAdapter(org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestTypeBasicDataAdapter) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) Test(org.junit.Test)

Example 4 with Contains

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

the class CQLToGeoWaveFilterTest method testCQLtoGeoWaveFilter.

@Test
public void testCQLtoGeoWaveFilter() throws CQLException, ParseException {
    Filter f = fromCQL("EMPLOYED < 15000000");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.LESS_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(15000000L, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue().longValue());
    f = fromCQL("EMPLOYED BETWEEN 1000000 AND 3000000");
    assertTrue(f instanceof NumericBetween);
    assertTrue(((NumericBetween) f).getValue() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericBetween) f).getValue()).getFieldName());
    assertTrue(((NumericBetween) f).getLowerBound() instanceof NumericLiteral);
    assertEquals(1000000L, ((NumericLiteral) ((NumericBetween) f).getLowerBound()).getValue().longValue());
    assertTrue(((NumericBetween) f).getUpperBound() instanceof NumericLiteral);
    assertEquals(3000000L, ((NumericLiteral) ((NumericBetween) f).getUpperBound()).getValue().longValue());
    f = fromCQL("name = 'California'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("California", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    f = fromCQL("UNEMPLOY / (EMPLOYED + UNEMPLOY) > 0.07");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Divide);
    Divide divide = (Divide) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(divide.getExpression1() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) divide.getExpression1()).getFieldName());
    assertTrue(divide.getExpression2() instanceof Add);
    Add add = (Add) divide.getExpression2();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(0.07, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue(), EPSILON);
    f = fromCQL("A <> B AND B <= 8.1");
    assertTrue(f instanceof And);
    assertTrue(((And) f).getChildren().length == 2);
    assertTrue(((And) f).getChildren()[0] instanceof Not);
    assertTrue(((Not) ((And) f).getChildren()[0]).getFilter() instanceof NumericComparisonOperator);
    NumericComparisonOperator equalTo = (NumericComparisonOperator) ((Not) ((And) f).getChildren()[0]).getFilter();
    assertEquals(CompareOp.EQUAL_TO, equalTo.getCompareOp());
    assertTrue(equalTo.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) equalTo.getExpression1()).getFieldName());
    assertTrue(equalTo.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) equalTo.getExpression2()).getFieldName());
    assertTrue(((And) f).getChildren()[1] instanceof NumericComparisonOperator);
    NumericComparisonOperator lessThan = (NumericComparisonOperator) ((And) f).getChildren()[1];
    assertEquals(CompareOp.LESS_THAN_OR_EQUAL, lessThan.getCompareOp());
    assertTrue(lessThan.getExpression1() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) lessThan.getExpression1()).getFieldName());
    assertTrue(lessThan.getExpression2() instanceof NumericLiteral);
    assertEquals(8.1, ((NumericLiteral) lessThan.getExpression2()).getValue(), EPSILON);
    // Order of operations should be preserved
    f = fromCQL("A + B - (C * D) / 8.5 >= E");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN_OR_EQUAL, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Subtract);
    Subtract subtract = (Subtract) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(subtract.getExpression1() instanceof Add);
    add = (Add) subtract.getExpression1();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(subtract.getExpression2() instanceof Divide);
    divide = (Divide) subtract.getExpression2();
    assertTrue(divide.getExpression1() instanceof Multiply);
    Multiply multiply = (Multiply) divide.getExpression1();
    assertTrue(multiply.getExpression1() instanceof NumericFieldValue);
    assertEquals("C", ((NumericFieldValue) multiply.getExpression1()).getFieldName());
    assertTrue(multiply.getExpression2() instanceof NumericFieldValue);
    assertEquals("D", ((NumericFieldValue) multiply.getExpression2()).getFieldName());
    assertTrue(divide.getExpression2() instanceof NumericLiteral);
    assertEquals(8.5, ((NumericLiteral) divide.getExpression2()).getValue(), EPSILON);
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericFieldValue);
    assertEquals("E", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression2()).getFieldName());
    f = fromCQL("BBOX(geom, -90, 40, -60, 45)");
    assertTrue(f instanceof BBox);
    assertTrue(((BBox) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((BBox) f).getExpression1()).getFieldName());
    assertTrue(((BBox) f).getExpression2() instanceof SpatialLiteral);
    SpatialLiteral spatialLit = (SpatialLiteral) ((BBox) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    Geometry geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(-90, -60, 40, 45))));
    f = fromCQL("DISJOINT(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Disjoint);
    assertTrue(((Disjoint) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Disjoint) f).getExpression1()).getFieldName());
    assertTrue(((Disjoint) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Disjoint) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("EQUALS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialEqualTo);
    assertTrue(((SpatialEqualTo) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((SpatialEqualTo) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialEqualTo) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CONTAINS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialContains);
    assertTrue(((SpatialContains) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialContains) f).getExpression1()).getFieldName());
    assertTrue(((SpatialContains) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialContains) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CROSSES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Crosses);
    assertTrue(((Crosses) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Crosses) f).getExpression1()).getFieldName());
    assertTrue(((Crosses) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Crosses) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("INTERSECTS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Intersects);
    assertTrue(((Intersects) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Intersects) f).getExpression1()).getFieldName());
    assertTrue(((Intersects) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Intersects) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("OVERLAPS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Overlaps);
    assertTrue(((Overlaps) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Overlaps) f).getExpression1()).getFieldName());
    assertTrue(((Overlaps) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Overlaps) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("TOUCHES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Touches);
    assertTrue(((Touches) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Touches) f).getExpression1()).getFieldName());
    assertTrue(((Touches) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Touches) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("WITHIN(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Within);
    assertTrue(((Within) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Within) f).getExpression1()).getFieldName());
    assertTrue(((Within) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Within) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    final Instant date1 = Instant.parse("2020-01-25T00:28:32Z");
    final Instant date2 = Instant.parse("2021-03-02T13:08:45Z");
    f = fromCQL("date AFTER 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    Interval interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date > 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BEFORE 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date < 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof During);
    assertTrue(((During) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((During) f).getExpression1()).getFieldName());
    assertTrue(((During) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((During) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    // GeoWave has a BeforeOrDuring class, but the CQL filter translates it using OR
    f = fromCQL("date BEFORE OR DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof Before);
    Before before = (Before) ((Or) f).getChildren()[0];
    assertTrue(before.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) before.getExpression1()).getFieldName());
    assertTrue(before.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) before.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof During);
    During during = (During) ((Or) f).getChildren()[1];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING OR AFTER 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof During);
    during = (During) ((Or) f).getChildren()[0];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof After);
    After after = (After) ((Or) f).getChildren()[1];
    assertTrue(after.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) after.getExpression1()).getFieldName());
    assertTrue(after.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) after.getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date <= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof BeforeOrDuring);
    assertTrue(((BeforeOrDuring) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((BeforeOrDuring) f).getExpression1()).getFieldName());
    assertTrue(((BeforeOrDuring) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((BeforeOrDuring) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date >= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof DuringOrAfter);
    assertTrue(((DuringOrAfter) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((DuringOrAfter) f).getExpression1()).getFieldName());
    assertTrue(((DuringOrAfter) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((DuringOrAfter) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BETWEEN 2020-01-25T00:28:32Z AND 2021-03-02T13:08:45Z");
    assertTrue(f instanceof TemporalBetween);
    assertTrue(((TemporalBetween) f).getValue() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((TemporalBetween) f).getValue()).getFieldName());
    assertTrue(((TemporalBetween) f).getLowerBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getLowerBound())).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((TemporalBetween) f).getUpperBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getUpperBound())).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date IS NULL");
    assertTrue(f instanceof IsNull);
    assertTrue(((IsNull) f).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) f).getExpression()).getFieldName());
    f = fromCQL("date IS NOT NULL");
    assertTrue(f instanceof Not);
    assertTrue(((Not) f).getFilter() instanceof IsNull);
    assertTrue(((IsNull) ((Not) f).getFilter()).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) ((Not) f).getFilter()).getExpression()).getFieldName());
    f = fromCQL("INCLUDE");
    assertTrue(f instanceof Include);
    f = fromCQL("EXCLUDE");
    assertTrue(f instanceof Exclude);
    f = fromCQL("bool = TRUE");
    assertTrue(f instanceof GenericEqualTo);
    assertTrue(((GenericEqualTo) f).getExpression1() instanceof BooleanFieldValue);
    assertEquals("bool", ((BooleanFieldValue) ((GenericEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((GenericEqualTo) f).getExpression2() instanceof BooleanLiteral);
    assertTrue((boolean) ((BooleanLiteral) ((GenericEqualTo) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value'");
    assertTrue(f instanceof EndsWith);
    assertTrue(((EndsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((EndsWith) f).getExpression1()).getFieldName());
    assertTrue(((EndsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((EndsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'value%'");
    assertTrue(f instanceof StartsWith);
    assertTrue(((StartsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((StartsWith) f).getExpression1()).getFieldName());
    assertTrue(((StartsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((StartsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value%'");
    assertTrue(f instanceof Contains);
    assertTrue(((Contains) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) f).getExpression1()).getFieldName());
    assertTrue(((Contains) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((Contains) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'a\\_value'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("a_value", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    try {
        // _ is a single character wild card, so this is not supported
        f = fromCQL("name LIKE 'a_value'");
        fail();
    } catch (CQLToGeoWaveConversionException e) {
    // expected
    }
}
Also used : Add(org.locationtech.geowave.core.store.query.filter.expression.numeric.Add) TextComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator) Or(org.locationtech.geowave.core.store.query.filter.expression.Or) GenericEqualTo(org.locationtech.geowave.core.store.query.filter.expression.GenericEqualTo) Include(org.locationtech.geowave.core.store.query.filter.expression.Include) TemporalFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue) BooleanFieldValue(org.locationtech.geowave.core.store.query.filter.expression.BooleanFieldValue) Divide(org.locationtech.geowave.core.store.query.filter.expression.numeric.Divide) Multiply(org.locationtech.geowave.core.store.query.filter.expression.numeric.Multiply) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) 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) Instant(java.time.Instant) Not(org.locationtech.geowave.core.store.query.filter.expression.Not) Coordinate(org.locationtech.jts.geom.Coordinate) And(org.locationtech.geowave.core.store.query.filter.expression.And) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) Subtract(org.locationtech.geowave.core.store.query.filter.expression.numeric.Subtract) EndsWith(org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith) Interval(org.threeten.extra.Interval) Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Exclude(org.locationtech.geowave.core.store.query.filter.expression.Exclude) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) BooleanLiteral(org.locationtech.geowave.core.store.query.filter.expression.BooleanLiteral) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) 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) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) TemporalLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral) 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) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) After(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) IsNull(org.locationtech.geowave.core.store.query.filter.expression.IsNull) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Test(org.junit.Test)

Example 5 with Contains

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

the class ExpressionQueryIT method testTextExpressionQueries.

@Test
public void testTextExpressionQueries() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    ds.addType(adapter, spatialIndex);
    final Index commentIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, COMMENT_FIELD));
    final Index idIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ID_FIELD));
    ds.addIndex(TYPE_NAME, commentIndex, idIndex);
    final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore aimStore = dataStore.createAdapterIndexMappingStore();
    final IndexStore indexStore = dataStore.createIndexStore();
    final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
    final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(TYPE_NAME));
    // Ingest data
    ingestData(ds);
    // ///////////////////////////////////////////////////
    // Starts With
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.startsWith("Br")).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    CustomQueryConstraints<?> customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    List<QueryFilter> filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Starts With (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.startsWith("br", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Ends With
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.endsWith("phA")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Ends With (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.endsWith("pha", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.contains("lph")).build();
    // Spatial index will be selected since contains is a full scan
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    FilteredEverythingQuery everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Contains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.contains("al", true)).build();
    // Spatial index will be selected since contains is a full scan
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Contains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Between
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isBetween("A", "C")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Between);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Between (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isBetween("alpha", "bravo", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Between);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThan("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThan("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThan("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Less than can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThan("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Less than can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than Or Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThanOrEqualTo("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Greater than or equal to can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Greater Than Or Equal To (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isGreaterThanOrEqualTo("c", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    // Greater than or equal to can be an exact query and doesn't need filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than Or Equal To
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThanOrEqualTo("B")).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Less Than Or Equal To (ignore case)
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(COMMENT.isLessThanOrEqualTo("bravo", true)).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof ComparisonOperator);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2, Iterators.size(iterator));
    }
}
Also used : ComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.ComparisonOperator) Index(org.locationtech.geowave.core.store.api.Index) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) FilteredEverythingQuery(org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Between(org.locationtech.geowave.core.store.query.filter.expression.Between) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Contains (org.locationtech.geowave.core.store.query.filter.expression.text.Contains)5 TextFieldValue (org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue)4 TextLiteral (org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral)4 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)3 SpatialContains (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains)2 TemporalBetween (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween)2 TestType (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestType)2 TestTypeBasicDataAdapter (org.locationtech.geowave.core.store.adapter.AbstractDataTypeAdapterTest.TestTypeBasicDataAdapter)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 NumericComparisonOperator (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator)2 NumericFieldValue (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue)2 NumericLiteral (org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral)2 EndsWith (org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith)2 StartsWith (org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith)2 Instant (java.time.Instant)1 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)1 BBox (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox)1 Crosses (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses)1 Disjoint (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint)1