Search in sources :

Example 6 with StormSqlExpression

use of com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression in project streamline by hortonworks.

the class SqlNestedExprScriptTest method testEvaluateNestedMap.

// @Test
public void testEvaluateNestedMap() throws Exception {
    Condition condition = new Condition();
    Expression y_b = new MapFieldExpression(new FieldExpression(Schema.Field.of("y", Schema.Type.NESTED)), "b");
    condition.setExpression(new BinaryExpression(Operator.LESS_THAN, y_b, new Literal("100")));
    sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("y")));
    Map<String, Object> nested = new HashMap<>();
    nested.put("a", 5);
    nested.put("b", 10);
    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 10);
    kv.put("y", nested);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Collection<StreamlineEvent> result = sqlScript.evaluate(event);
    Assert.assertEquals(1, result.size());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression)

Example 7 with StormSqlExpression

use of com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression in project streamline by hortonworks.

the class SqlNestedExprScriptTest method testBasic.

@Test
public void testBasic() throws Exception {
    Condition condition = new Condition();
    Expression x = new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER));
    condition.setExpression(new BinaryExpression(Operator.NOT_EQUAL, x, new Literal("100")));
    sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("x")));
    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 100);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Collection<StreamlineEvent> result = sqlScript.evaluate(event);
    Assert.assertTrue(result.isEmpty());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) Test(org.junit.Test)

Example 8 with StormSqlExpression

use of com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression in project streamline by hortonworks.

the class SqlNestedExprScriptTest method testEvaluateNestedMapList.

// @Test
public void testEvaluateNestedMapList() throws Exception {
    Condition condition = new Condition();
    Expression y_a_0 = new ArrayFieldExpression(new MapFieldExpression(new FieldExpression(Schema.Field.of("y", Schema.Type.NESTED)), "a"), 0);
    condition.setExpression(new BinaryExpression(Operator.LESS_THAN, y_a_0, new Literal("100")));
    sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("y")));
    List<Integer> nestedList = new ArrayList<>();
    nestedList.add(500);
    nestedList.add(1);
    Map<String, Object> nestedMap = new HashMap<>();
    nestedMap.put("a", nestedList);
    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 10);
    kv.put("y", nestedMap);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Collection<StreamlineEvent> result = sqlScript.evaluate(event);
    Assert.assertTrue(result.isEmpty());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression)

Aggregations

StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)8 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)6 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)4 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)4 Test (org.junit.Test)4 ArrayFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression)3 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)3 Condition (com.hortonworks.streamline.streams.layout.component.rule.expression.Condition)3 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)3 MapFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression)3 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 GroupBy (com.hortonworks.streamline.streams.layout.component.rule.expression.GroupBy)1 GroovyExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.GroovyExpression)1 SqlEngine (com.hortonworks.streamline.streams.runtime.rule.sql.SqlEngine)1 SqlScript (com.hortonworks.streamline.streams.runtime.rule.sql.SqlScript)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1