use of com.hortonworks.streamline.streams.Result in project streamline by hortonworks.
the class NormalizationBolt method process.
public void process(Tuple inputTuple, StreamlineEvent event) throws Exception {
LOG.debug("Normalizing received StreamlineEvent: [{}] with tuple: [{}]", event, inputTuple);
// todo this bolt will be replaced with custom baseprocessor bolt.
StreamlineEventImpl eventWithStream = StreamlineEventImpl.builder().from(event).sourceStream(inputTuple.getSourceStreamId()).build();
List<Result> outputEvents = normalizationProcessorRuntime.process(eventWithStream);
LOG.debug("Emitting events to collector: [{}]", outputEvents);
for (Result outputEvent : outputEvents) {
for (StreamlineEvent e : outputEvent.events) {
collector.emit(outputEvent.stream, inputTuple, new Values(e));
}
}
}
use of com.hortonworks.streamline.streams.Result in project streamline by hortonworks.
the class WindowRulesBolt method processAndEmit.
private void processAndEmit(StreamlineEvent event, Map<String, Tuple> curGroup) throws ProcessingException {
List<Result> results = ruleProcessorRuntime.process(eventWithWindowId(event));
for (Result result : results) {
for (StreamlineEvent e : result.events) {
// anchor parent events if such information is available
if (EventCorrelationInjector.containsParentIds(e)) {
Set<String> parentIds = EventCorrelationInjector.getParentIds(e);
List<Tuple> parents = parentIds.stream().map(pid -> {
if (!curGroup.containsKey(pid)) {
throw new IllegalStateException("parents should be in grouped tuples");
}
return curGroup.get(pid);
}).collect(Collectors.toList());
collector.emit(result.stream, parents, new Values(updateHeaders(e, parents)));
} else {
// put all events in current group if there's no information
collector.emit(result.stream, curGroup.values(), new Values(updateHeaders(e, curGroup.values())));
}
}
}
}
use of com.hortonworks.streamline.streams.Result 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.Result 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.Result in project streamline by hortonworks.
the class SplitJoinTest method runSplitJoin.
protected void runSplitJoin(SplitAction splitAction, JoinAction joinAction, Map<String, Object> config) {
SplitActionRuntime splitActionRuntime = new SplitActionRuntime(splitAction);
splitActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, splitAction));
splitActionRuntime.initialize(config);
StreamlineEvent event = createRootEvent();
final List<Result> results = splitActionRuntime.execute(event);
JoinActionRuntime joinActionRuntime = new JoinActionRuntime(joinAction);
joinActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, joinAction));
joinActionRuntime.initialize(config);
List<Result> effectiveResult = null;
for (Result result : results) {
for (StreamlineEvent e : result.events) {
List<Result> processedResult = joinActionRuntime.execute(e);
if (processedResult != null) {
effectiveResult = processedResult;
}
}
}
Assert.assertNotNull(effectiveResult);
}
Aggregations