Search in sources :

Example 16 with Expression

use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression 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)

Example 17 with Expression

use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.

the class StormSqlExpression method handleGroupByHaving.

private void handleGroupByHaving() {
    if (groupBy != null) {
        List<String> groupByExpressions = new ArrayList<>();
        for (Expression expr : groupBy.getExpressions()) {
            ExpressionTranslator groupByTranslator = new StormSqlExpressionTranslator();
            expr.accept(groupByTranslator);
            stormSqlFields.addAll(groupByTranslator.getFields());
            groupByFields.addAll(groupByTranslator.getFields());
            functions.addAll(groupByTranslator.getFunctions());
            groupByExpressions.add(groupByTranslator.getTranslatedExpression());
        }
        groupByExpression = Joiner.on(",").join(groupByExpressions);
        if (having != null) {
            ExpressionTranslator havingTranslator = new StormSqlExpressionTranslator();
            having.getExpression().accept(havingTranslator);
            stormSqlFields.addAll(havingTranslator.getFields());
            functions.addAll(havingTranslator.getFunctions());
            aggregateFunctions.addAll(havingTranslator.getAggregateFunctions());
            havingExpression = havingTranslator.getTranslatedExpression();
            LOG.debug("Built expression [{}] for having [{}]", havingExpression, having);
        }
    }
}
Also used : FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) ArrayList(java.util.ArrayList) ExpressionTranslator(com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)

Aggregations

Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)17 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)15 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)14 Condition (com.hortonworks.streamline.streams.layout.component.rule.expression.Condition)12 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)11 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)11 Test (org.junit.Test)10 AggregateFunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression)8 ArrayFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression)6 MapFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression)6 Projection (com.hortonworks.streamline.streams.layout.component.rule.expression.Projection)5 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)4 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)3 GroupBy (com.hortonworks.streamline.streams.layout.component.rule.expression.GroupBy)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ExpressionTranslator (com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)2 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)1 Action (com.hortonworks.streamline.streams.layout.component.rule.action.Action)1 TransformAction (com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction)1