use of com.hortonworks.streamline.streams.common.StreamlineEventImpl 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.common.StreamlineEventImpl in project streamline by hortonworks.
the class WindowedQueryBolt method doProjectionStreamLine.
// Overrides projection behavior to customize for handling of "streamline-event." prefix
protected ArrayList<Object> doProjectionStreamLine(ArrayList<Tuple> tuplesRow, FieldSelector[] projectionKeys) {
String[] finalOutputFieldNames = new String[rawCommaSeparatedOutputKeys.length];
for (int i = 0; i < rawCommaSeparatedOutputKeys.length; ++i) {
finalOutputFieldNames[i] = getAliasOrKeyName(rawCommaSeparatedOutputKeys[i]);
}
StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder();
// Todo: note to self: may be able to optimize this ... perhaps inner loop can be outside to avoid rescanning tuples
for (int i = 0; i < projectionKeys.length; i++) {
for (Tuple cell : tuplesRow) {
Object field = lookupField(projectionKeys[i], cell);
if (field != null) {
eventBuilder.put(finalOutputFieldNames[i], field);
break;
}
}
}
ArrayList<Object> resultRow = new ArrayList<>();
StreamlineEventImpl slEvent = eventBuilder.dataSourceId("multiple sources").build();
resultRow.add(slEvent);
return resultRow;
}
use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.
the class JsonFileReader method next.
// returns null when EOF is reached
public List<Object> next() throws IOException, ParseException {
List<Object> lineTuple = super.next();
if (lineTuple == null)
return null;
String jsonLine = (String) lineTuple.get(0);
if (jsonLine.trim().isEmpty())
return next();
try {
// 1- convert Json to Map<>
HashMap<String, Object> jsonMap = new ObjectMapper().readValue(jsonLine, HashMap.class);
// 2- make StreamlineEvent from map
StreamlineEventImpl slEvent = StreamlineEventImpl.builder().putAll(jsonMap).dataSourceId("HdfsSpout").build();
// 3- create tuple from StreamlineEvent
return Collections.singletonList(slEvent);
} catch (JsonProcessingException e) {
throw new ParseException("Json parsing error at location : " + getFileOffset().toString(), e);
}
}
use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.
the class TestRunSourceSpout method nextTuple.
@Override
public void nextTuple() {
int emitCount = 0;
boolean allOutputStreamsCompleted = true;
// loop output stream and emit at most one record per output stream
for (Map.Entry<String, TestRecordsInformation> entry : testRecordsInformationPerOutputStream.entrySet()) {
String outputStream = entry.getKey();
TestRecordsInformation info = entry.getValue();
if (info.isCompleted()) {
continue;
}
allOutputStreamsCompleted = false;
Optional<Map<String, Object>> recordOptional = info.nextRecord();
if (recordOptional.isPresent()) {
Map<String, Object> record = recordOptional.get();
StreamlineEventImpl streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(record).dataSourceId(testRunSource.getId()).build();
LOG.debug("Emitting event {} to stream {}", streamlineEvent, outputStream);
collector.emit(outputStream, new Values(streamlineEvent), streamlineEvent.getId());
emitCount++;
}
}
if (allOutputStreamsCompleted) {
LOG.info("All iterations are completed, sleeping...");
Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
} else if (emitCount == 0) {
LOG.info("All output streams are finished last iteration and now in sleep phase, sleeping...");
Uninterruptibles.sleepUninterruptibly(testRunSource.getSleepMsPerIteration(), TimeUnit.MILLISECONDS);
}
}
use of com.hortonworks.streamline.streams.common.StreamlineEventImpl in project streamline by hortonworks.
the class SLRealtimeJoinBolt method doProjection.
/**
* NOTE: Streamline specific convenience method. Creates output tuple as a StreamlineEvent
* @param tuple1 can be null
* @param tuple2 can be null
* @return
*/
@Override
protected List<Object> doProjection(Tuple tuple1, Tuple tuple2) {
StreamlineEventImpl.Builder eventBuilder = StreamlineEventImpl.builder();
for (int i = 0; i < outputFields.length; i++) {
FieldSelector outField = outputFields[i];
Object field = outField.findField(tuple1);
if (field == null)
field = outField.findField(tuple2);
String outputKeyName = dropStreamLineEventPrefix(outField.outputName);
// adds null if field is not found in both tuples
eventBuilder.put(outputKeyName, field);
}
StreamlineEventImpl slEvent = eventBuilder.dataSourceId("multiple sources").build();
return Collections.singletonList(slEvent);
}
Aggregations