Search in sources :

Example 1 with TransformRuntime

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

the class SubstituteTransformRuntimeTest method testSubstituteNoVars.

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

Example 2 with TransformRuntime

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

the class SubstituteTransformRuntimeTest method testCyclicRef.

@Test
public void testCyclicRef() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "${2} minus one");
    fieldsAndValues.put("2", "${1} plus one");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime();
    List<StreamlineEvent> result = transformRuntime.execute(event);
    System.out.println(result);
    assertEquals(1, result.size());
    assertEquals(event, result.get(0));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

Example 3 with TransformRuntime

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

the class SubstituteTransformRuntimeTest method testSubstituteSimpleVars.

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

Example 4 with TransformRuntime

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

the class SubstituteTransformRuntimeTest method testSubstituteRefVars.

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

Example 5 with TransformRuntime

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

the class SubstituteTransformRuntimeTest method testSubstituteSimpleObj.

@Test
public void testSubstituteSimpleObj() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", 1);
    fieldsAndValues.put("2", 2);
    fieldsAndValues.put("3", "${1} plus ${2}");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime();
    List<StreamlineEvent> result = transformRuntime.execute(event);
    assertEquals(1, result.size());
    assertEquals(3, result.get(0).size());
    assertEquals(1, result.get(0).get("1"));
    assertEquals(2, result.get(0).get("2"));
    assertEquals("1 plus 2", result.get(0).get("3"));
}
Also used : 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