Search in sources :

Example 16 with StreamlineEvent

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"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) SubstituteTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 17 with StreamlineEvent

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"));
}
Also used : ProjectionTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.ProjectionTransform) MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformAction(com.hortonworks.streamline.streams.layout.component.rule.action.TransformAction) ArrayList(java.util.ArrayList) ActionRuntime(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntime) Result(com.hortonworks.streamline.streams.Result) Test(org.junit.Test)

Example 18 with StreamlineEvent

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());
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) Test(org.junit.Test)

Example 19 with StreamlineEvent

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));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) StormSqlExpression(com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression) Test(org.junit.Test)

Example 20 with StreamlineEvent

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);
}
Also used : GroovyScriptEngine(com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3