use of com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform 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.layout.component.rule.action.transform.SubstituteTransform 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"));
}
use of com.hortonworks.streamline.streams.layout.component.rule.action.transform.SubstituteTransform in project streamline by hortonworks.
the class NotifierActionRuntime method getNotificationTransforms.
/**
* Returns the necessary transforms to perform based on the action.
*/
private List<Transform> getNotificationTransforms(NotifierAction action, Long ruleId) {
List<Transform> transforms = new ArrayList<>();
if (action.getOutputFieldsAndDefaults() != null && !action.getOutputFieldsAndDefaults().isEmpty()) {
transforms.add(new MergeTransform(action.getOutputFieldsAndDefaults()));
transforms.add(new SubstituteTransform(action.getOutputFieldsAndDefaults().keySet()));
transforms.add(new ProjectionTransform("projection-" + ruleId, action.getOutputFieldsAndDefaults().keySet()));
}
Map<String, Object> headers = new HashMap<>();
headers.put(AddHeaderTransformRuntime.HEADER_FIELD_NOTIFIER_NAME, action.getNotifierName());
headers.put(AddHeaderTransformRuntime.HEADER_FIELD_RULE_ID, ruleId);
transforms.add(new AddHeaderTransform(headers));
return transforms;
}
Aggregations