use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression 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());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class StormSqlExpressionTest method testGroupByMultipleFields.
@Test
public void testGroupByMultipleFields() throws Exception {
// SELECT STREAM MIN(SALARY) FROM FOO where ID > 0 GROUP BY DEPTID, EMPID
Expression min_salary = new AggregateFunctionExpression("MIN", ImmutableList.of(new FieldExpression(Schema.Field.of("salary", Schema.Type.INTEGER))));
Expression deptid = new FieldExpression(Schema.Field.of("deptid", Schema.Type.INTEGER));
Expression empid = new FieldExpression(Schema.Field.of("empid", Schema.Type.INTEGER));
GroupBy groupBy = new GroupBy(ImmutableList.of(deptid, empid));
Expression id = new FieldExpression(Schema.Field.of("id", Schema.Type.INTEGER));
Expression id_gt_0 = new BinaryExpression(Operator.GREATER_THAN, id, new Literal("0"));
Condition condition = new Condition();
condition.setExpression(id_gt_0);
Projection projection = new Projection();
projection.setExpressions(ImmutableList.<Expression>of(min_salary));
stormSqlExpression = new StormSqlExpression(condition, projection, groupBy, null);
assertEquals("CREATE EXTERNAL TABLE RULETABLE (\"salary\" INTEGER, \"id\" INTEGER, \"deptid\" INTEGER PRIMARY KEY, " + "\"empid\" INTEGER) LOCATION 'schema:///RULETABLE'", stormSqlExpression.createTable("schema"));
assertEquals("SELECT STREAM MIN(RULETABLE.\"salary\") FROM RULETABLE WHERE RULETABLE.\"id\" > 0 GROUP BY RULETABLE.\"deptid\",RULETABLE.\"empid\"", stormSqlExpression.select());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class StormSqlExpressionTest method testProjectAndCondition.
@Test
public void testProjectAndCondition() throws Exception {
Expression x = new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER));
Expression y = new FieldExpression(Schema.Field.of("y", Schema.Type.INTEGER));
Expression x_gt_100 = new BinaryExpression(Operator.GREATER_THAN, x, new Literal("100"));
Projection projection = new Projection();
projection.setExpressions(ImmutableList.<Expression>of(y));
Condition condition = new Condition();
condition.setExpression(x_gt_100);
stormSqlExpression = new StormSqlExpression(condition, projection);
assertEquals("CREATE EXTERNAL TABLE RULETABLE (\"y\" INTEGER, \"x\" INTEGER) LOCATION 'schema:///RULETABLE'", stormSqlExpression.createTable("schema"));
assertEquals("SELECT STREAM RULETABLE.\"y\" FROM RULETABLE WHERE RULETABLE.\"x\" > 100", stormSqlExpression.select());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression 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());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression 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;
}
Aggregations