Search in sources :

Example 6 with TransformRuntime

use of com.hortonworks.streamline.streams.runtime.TransformRuntime in project streamline by hortonworks.

the class SubstituteTransformRuntimeTest method testSubstituteSpecificVars.

@Test
public void testSubstituteSpecificVars() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "${1} plus ${1}");
    fieldsAndValues.put("3", "${1} plus two");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime(new SubstituteTransform(Collections.singleton("3")));
    List<StreamlineEvent> result = transformRuntime.execute(event);
    assertEquals(1, result.size());
    assertEquals(3, result.get(0).size());
    assertEquals("one", result.get(0).get("1"));
    assertEquals("${1} plus ${1}", result.get(0).get("2"));
    assertEquals("one plus two", result.get(0).get("3"));
}
Also used : SubstituteTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

Example 7 with TransformRuntime

use of com.hortonworks.streamline.streams.runtime.TransformRuntime in project streamline by hortonworks.

the class MergeTransformRuntimeTest method testExecute.

@Test
public void testExecute() 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();
    TransformRuntime transformRuntime = new MergeTransformRuntime(new MergeTransform(defaults));
    List<StreamlineEvent> result = transformRuntime.execute(event);
    System.out.println(result);
    assertEquals(1, result.size());
    assertEquals("two", result.get(0).get("2"));
    assertEquals("THREE", result.get(0).get("3"));
}
Also used : MergeTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)7 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)1 SubstituteTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform)1