use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class TransformRuntimePipelineActionTest method testMergeSubstituteProject.
@Test
public void testMergeSubstituteProject() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "${1} plus ${1}");
Map<String, Object> defaults = new HashMap<>();
defaults.put("2", "TWO");
defaults.put("3", "THREE");
defaults.put("4", "${2} plus ${2}");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
MergeTransform merge = new MergeTransform(defaults);
SubstituteTransform substitute = new SubstituteTransform();
ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
TransformAction transformAction = new TransformAction(ImmutableList.of(merge, substitute, projection));
transformAction.setOutputStreams(ImmutableSet.of("streamid"));
ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
List<StreamlineEvent> resultEvents = new ArrayList<>();
for (Result result : actionRuntime.execute(event)) {
resultEvents.addAll(result.events);
}
assertEquals(1, resultEvents.size());
assertEquals(3, resultEvents.get(0).size());
assertEquals("THREE", resultEvents.get(0).get("3"));
assertEquals("one plus one", resultEvents.get(0).get("2"));
assertEquals("one plus one plus one plus one", resultEvents.get(0).get("4"));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class TransformRuntimePipelineActionTest method testMergeProject.
@Test
public void testMergeProject() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "two");
Map<String, String> defaults = new HashMap<>();
defaults.put("2", "TWO");
defaults.put("3", "THREE");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
MergeTransform merge = new MergeTransform(defaults);
ProjectionTransform projection = new ProjectionTransform("test-projection", defaults.keySet());
TransformAction transformAction = new TransformAction(ImmutableList.of(merge, projection));
transformAction.setOutputStreams(ImmutableSet.of("streamid"));
ActionRuntime actionRuntime = new TransformActionRuntime(transformAction);
List<StreamlineEvent> resultEvents = new ArrayList<>();
for (Result result : actionRuntime.execute(event)) {
resultEvents.addAll(result.events);
}
assertEquals(1, resultEvents.size());
assertEquals(2, resultEvents.get(0).size());
assertEquals("THREE", resultEvents.get(0).get("3"));
assertEquals("two", resultEvents.get(0).get("2"));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class SqlBasicExprScriptTest method testBasicNoMatch.
@Test
public void testBasicNoMatch() 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.StreamlineEvent in project streamline by hortonworks.
the class SqlBasicExprScriptTest 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.EQUALS, 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.assertEquals(1, result.size());
StreamlineEvent resultEvent = result.iterator().next();
Assert.assertTrue(EventCorrelationInjector.containsParentIds(resultEvent));
Assert.assertEquals(Collections.singleton(event.getId()), EventCorrelationInjector.getParentIds(resultEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class GroovyScriptNestedExprTest method testEvaluateNestedMapList.
@Test
public void testEvaluateNestedMapList() throws Exception {
groovyScript = new GroovyScript<>("x < y['a'][0]", new GroovyScriptEngine());
List<Integer> nestedList = new ArrayList<>();
nestedList.add(5);
nestedList.add(1);
Map<String, Object> nestedMap = new HashMap<>();
nestedMap.put("a", nestedList);
Map<String, Object> kv = new HashMap<>();
kv.put("x", 2);
kv.put("y", nestedMap);
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
Boolean result = groovyScript.evaluate(event);
System.out.println(result);
}
Aggregations