Search in sources :

Example 1 with FunctionExpression

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

the class StormSqlExpressionTest method testCreateSelect.

@Test
public void testCreateSelect() throws Exception {
    Condition condition = new Condition();
    Expression function = new FunctionExpression("SUM", "com.hortonworks.streamline.MyPlus", ImmutableList.of(new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER)), new FieldExpression(Schema.Field.of("y", Schema.Type.INTEGER))));
    Expression expression = new BinaryExpression(Operator.GREATER_THAN, function, new Literal("100"));
    condition.setExpression(expression);
    stormSqlExpression = new StormSqlExpression(condition);
    assertEquals("CREATE EXTERNAL TABLE RULETABLE (\"x\" INTEGER, \"y\" INTEGER) LOCATION 'schema:///RULETABLE'", stormSqlExpression.createTable("schema"));
    assertEquals("SELECT STREAM \"x\", \"y\" FROM RULETABLE WHERE SUM(RULETABLE.\"x\", RULETABLE.\"y\") > 100", stormSqlExpression.select());
    assertEquals(Arrays.asList("CREATE FUNCTION SUM AS 'com.hortonworks.streamline.MyPlus'"), stormSqlExpression.createFunctions());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) 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) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Test(org.junit.Test)

Example 2 with FunctionExpression

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

the class StormSqlExpressionTest method testCreateSelectProject.

@Test
public void testCreateSelectProject() throws Exception {
    Condition condition = new Condition();
    Expression function = new FunctionExpression("SUM", "com.hortonworks.streamline.MyPlus", ImmutableList.of(new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER)), new FieldExpression(Schema.Field.of("y", Schema.Type.INTEGER))));
    Expression z = new FieldExpression(Schema.Field.of("z", Schema.Type.INTEGER));
    Expression z_gt_100 = new BinaryExpression(Operator.GREATER_THAN, z, new Literal("100"));
    condition.setExpression(z_gt_100);
    Projection projection = new Projection();
    projection.setExpressions(ImmutableList.<Expression>of(function));
    stormSqlExpression = new StormSqlExpression(condition, projection);
    assertEquals("CREATE EXTERNAL TABLE RULETABLE (\"x\" INTEGER, \"y\" INTEGER, \"z\" INTEGER) LOCATION 'schema:///RULETABLE'", stormSqlExpression.createTable("schema"));
    assertEquals("SELECT STREAM SUM(RULETABLE.\"x\", RULETABLE.\"y\") FROM RULETABLE WHERE RULETABLE.\"z\" > 100", stormSqlExpression.select());
    assertEquals(Arrays.asList("CREATE FUNCTION SUM AS 'com.hortonworks.streamline.MyPlus'"), stormSqlExpression.createFunctions());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) 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) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Test(org.junit.Test)

Example 3 with FunctionExpression

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

the class RulesProcessorMock method getRule.

private Rule getRule(long ruleId, Condition condition, TransformAction action) {
    Rule rule = new Rule();
    rule.setId(ruleId);
    rule.setName(RULE + "_" + ruleId);
    rule.setDescription(RULE + "_" + ruleId + "_desc");
    rule.setRuleProcessorName(RULE_PROCESSOR + "_" + ruleProcessorId);
    rule.setCondition(condition);
    if (ruleId % 2 == 0) {
        Projection projection = new Projection();
        Expression humidity = new FieldExpression(Field.of("humidity", Schema.Type.INTEGER));
        Expression deviceName = new FieldExpression(Field.of("devicename", Schema.Type.STRING));
        Expression incr = new FunctionExpression("INCR", "com.hortonworks.streamline.streams.runtime.storm.layout.runtime.rule.topology.RulesProcessorMock$Incr", ImmutableList.<Expression>of(humidity, new Literal("10")));
        Expression upper = new FunctionExpression("UPPER", ImmutableList.<Expression>of(deviceName));
        projection.setExpressions(ImmutableList.<Expression>of(humidity, incr, upper));
        rule.setProjection(projection);
    }
    rule.setActions(Collections.singletonList((Action) action));
    return rule;
}
Also used : Action(com.hortonworks.streamline.streams.layout.component.rule.action.Action) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) 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) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)

Example 4 with FunctionExpression

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

the class StormSqlExpressionTest method testCreateFunctionDuplicate.

@Test
public void testCreateFunctionDuplicate() throws Exception {
    Condition condition = new Condition();
    Expression f1 = new FunctionExpression("FLOOR", "com.hortonworks.streamline.Floor", ImmutableList.of(new Literal("100.5")));
    Expression f2 = new FunctionExpression("FLOOR", "com.hortonworks.streamline.Floor", ImmutableList.of(new Literal("2.5")));
    Expression expression1 = new BinaryExpression(Operator.GREATER_THAN, new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER)), f1);
    Expression expression2 = new BinaryExpression(Operator.GREATER_THAN, new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER)), f2);
    Expression expression = new BinaryExpression(Operator.AND, expression1, expression2);
    condition.setExpression(expression);
    stormSqlExpression = new StormSqlExpression(condition);
    assertEquals(Arrays.asList("CREATE FUNCTION FLOOR AS 'com.hortonworks.streamline.Floor'"), stormSqlExpression.createFunctions());
}
Also used : Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) AggregateFunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression) 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) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Test(org.junit.Test)

Aggregations

BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)4 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)4 FieldExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression)4 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)4 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)4 AggregateFunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.AggregateFunctionExpression)3 Condition (com.hortonworks.streamline.streams.layout.component.rule.expression.Condition)3 Test (org.junit.Test)3 Projection (com.hortonworks.streamline.streams.layout.component.rule.expression.Projection)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