Search in sources :

Example 6 with Condition

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

the class RuleParser method parseCondition.

private Condition parseCondition(SqlSelect sqlSelect) {
    Condition condition = null;
    SqlNode where = sqlSelect.getWhere();
    if (where != null) {
        ExpressionGenerator exprGenerator = new ExpressionGenerator(streams, catalogUdfs);
        condition = new Condition(where.accept(exprGenerator));
        referredUdfs.addAll(exprGenerator.getReferredUdfs());
    }
    LOG.debug("Condition {}", condition);
    return condition;
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) SqlNode(org.apache.calcite.sql.SqlNode) ExpressionGenerator(com.hortonworks.streamline.streams.layout.component.rule.sql.ExpressionGenerator)

Example 7 with Condition

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

the class GroovyExpressionTest method testMap.

@Test
public void testMap() throws Exception {
    Condition condition = new Condition();
    condition.setExpression(new BinaryExpression(Operator.LESS_THAN, new MapFieldExpression(getVariable("map"), "foo"), getVariable("b")));
    GroovyExpression expr = new GroovyExpression(condition);
    Assert.assertEquals("map['foo'] < b", expr.asString());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) Test(org.junit.Test)

Example 8 with Condition

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

the class GroovyExpressionTest method testNested.

@Test
public void testNested() throws Exception {
    Condition condition = new Condition();
    condition.setExpression(new BinaryExpression(Operator.LESS_THAN, new ArrayFieldExpression(new MapFieldExpression(getVariable("map"), "foo"), 100), getVariable("b")));
    GroovyExpression expr = new GroovyExpression(condition);
    Assert.assertEquals("map['foo'][100] < b", expr.asString());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) Test(org.junit.Test)

Example 9 with Condition

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

the class GroovyExpressionTest method testArray.

@Test
public void testArray() throws Exception {
    Condition condition = new Condition();
    condition.setExpression(new BinaryExpression(Operator.LESS_THAN, new ArrayFieldExpression(getVariable("arr"), 100), getVariable("b")));
    GroovyExpression expr = new GroovyExpression(condition);
    Assert.assertEquals("arr[100] < b", expr.asString());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) Test(org.junit.Test)

Example 10 with Condition

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

the class GroovyExpressionTest method testOrString.

@Test
public void testOrString() throws Exception {
    Condition condition = new Condition();
    Expression left = new BinaryExpression(Operator.LESS_THAN, getVariable("a"), getVariable("b"));
    Expression right = new BinaryExpression(Operator.GREATER_THAN, getVariable("c"), getVariable("d"));
    condition.setExpression(new BinaryExpression(Operator.OR, left, right));
    GroovyExpression expr = new GroovyExpression(condition);
    Assert.assertEquals("a < b || c > d", expr.asString());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) ArrayFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) MapFieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) Test(org.junit.Test)

Aggregations

Condition (com.hortonworks.streamline.streams.layout.component.rule.expression.Condition)18 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)17 Test (org.junit.Test)15 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)14 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)12 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)12 AggregateFunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression)7 ArrayFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.ArrayFieldExpression)7 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)7 MapFieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.MapFieldExpression)7 Projection (com.hortonworks.streamline.streams.layout.component.rule.expression.Projection)6 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)3 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)2 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)2 Stream (com.hortonworks.streamline.streams.layout.component.Stream)2 AsExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AsExpression)2 GroupBy (com.hortonworks.streamline.streams.layout.component.rule.expression.GroupBy)2