Search in sources :

Example 6 with BinaryExpression

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

use of com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression 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 8 with BinaryExpression

use of com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression 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 9 with BinaryExpression

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

Example 10 with BinaryExpression

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

the class GroovyExpressionTest method testAndAsString.

@Test
public void testAndAsString() throws Exception {
    Condition condition = new Condition();
    Expression left = new BinaryExpression(Operator.OR, getVariable("a"), getVariable("b"));
    Expression right = new BinaryExpression(Operator.OR, getVariable("c"), getVariable("d"));
    condition.setExpression(new BinaryExpression(Operator.AND, 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

BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)18 Condition (com.hortonworks.streamline.streams.layout.component.rule.expression.Condition)17 Test (org.junit.Test)16 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)14 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)13 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)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 ArrayList (java.util.ArrayList)4 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)3 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)3 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)3 HashMap (java.util.HashMap)3 Expectations (mockit.Expectations)3 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