use of com.hortonworks.streamline.streams.layout.component.rule.expression.Literal in project streamline by hortonworks.
the class StormSqlExpressionTest method testCreateSelectProjectGroupBy.
@Test
public void testCreateSelectProjectGroupBy() throws Exception {
// SELECT STREAM ID, MIN(SALARY) FROM FOO where ID > 0 GROUP BY (ID) HAVING ID > 2 AND MAX(SALARY) > 5
Expression min_salary = new AggregateFunctionExpression("MIN", ImmutableList.of(new FieldExpression(Schema.Field.of("salary", Schema.Type.INTEGER))));
Expression max_salary = new AggregateFunctionExpression("MAX", ImmutableList.of(new FieldExpression(Schema.Field.of("salary", Schema.Type.INTEGER))));
Expression id = new FieldExpression(Schema.Field.of("id", Schema.Type.INTEGER));
Expression id_gt_0 = new BinaryExpression(Operator.GREATER_THAN, id, new Literal("0"));
Expression id_gt_2 = new BinaryExpression(Operator.GREATER_THAN, id, new Literal("2"));
Expression max_salary_gt_5 = new BinaryExpression(Operator.GREATER_THAN, max_salary, new Literal("5"));
GroupBy groupBy_id = new GroupBy();
groupBy_id.setExpression(Collections.singletonList(id));
Having having_id_gt_2 = new Having();
having_id_gt_2.setExpression(new BinaryExpression(Operator.AND, id_gt_2, max_salary_gt_5));
Condition condition = new Condition();
condition.setExpression(id_gt_0);
Projection projection = new Projection();
projection.setExpressions(ImmutableList.<Expression>of(id, min_salary));
stormSqlExpression = new StormSqlExpression(condition, projection, groupBy_id, having_id_gt_2);
assertEquals("CREATE EXTERNAL TABLE RULETABLE (\"id\" INTEGER PRIMARY KEY, \"salary\" INTEGER) LOCATION 'schema:///RULETABLE'", stormSqlExpression.createTable("schema"));
assertEquals("SELECT STREAM RULETABLE.\"id\", MIN(RULETABLE.\"salary\") FROM RULETABLE WHERE RULETABLE.\"id\" > 0 GROUP BY RULETABLE.\"id\" HAVING RULETABLE.\"id\" > 2 AND MAX(RULETABLE.\"salary\") > 5", stormSqlExpression.select());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Literal in project streamline by hortonworks.
the class SqlNestedExprScriptTest method testEvaluateNestedMap.
// @Test
public void testEvaluateNestedMap() throws Exception {
Condition condition = new Condition();
Expression y_b = new MapFieldExpression(new FieldExpression(Schema.Field.of("y", Schema.Type.NESTED)), "b");
condition.setExpression(new BinaryExpression(Operator.LESS_THAN, y_b, new Literal("100")));
sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("y")));
Map<String, Object> nested = new HashMap<>();
nested.put("a", 5);
nested.put("b", 10);
Map<String, Object> kv = new HashMap<>();
kv.put("x", 10);
kv.put("y", nested);
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
Collection<StreamlineEvent> result = sqlScript.evaluate(event);
Assert.assertEquals(1, result.size());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Literal in project streamline by hortonworks.
the class SqlNestedExprScriptTest method testBasic.
@Test
public void testBasic() throws Exception {
Condition condition = new Condition();
Expression x = new FieldExpression(Schema.Field.of("x", Schema.Type.INTEGER));
condition.setExpression(new BinaryExpression(Operator.NOT_EQUAL, x, new Literal("100")));
sqlScript = new SqlScript(new StormSqlExpression(condition), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Collections.singletonList("x")));
Map<String, Object> kv = new HashMap<>();
kv.put("x", 100);
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
Collection<StreamlineEvent> result = sqlScript.evaluate(event);
Assert.assertTrue(result.isEmpty());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Literal 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());
}
Aggregations