@Override public StreamlineEvent entity(Result result) { String id = Bytes.toString(result.getRow()); Map<String, Object> fieldsAndValues = new HashMap<>(); for(Map.Entry<byte[], byte[]> entry: result.getFamilyMap(CF_FIELDS).entrySet()) { fieldsAndValues.put(Bytes.toString(entry.getKey()), Bytes.toString(entry.getValue())); } String dataSourceId = Bytes.toString(result.getFamilyMap(CF_DATASOURCE_ID).firstEntry().getKey()); StreamlineEventImpl event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId(dataSourceId).build(); return new IdPreservedStreamlineEvent(event, id); }
public static StreamlineEvent fromString(String s) { ObjectMapper mapper = new ObjectMapper(); try { Map<String, Object> event = mapper.readValue( s.substring(s.indexOf(TO_STRING_PREFIX) + TO_STRING_PREFIX.length()), new TypeReference<Map<String, Object>>() {}); return StreamlineEventImpl.builder() .header((Map<String, Object>) event.get("header")) .sourceStream((String) event.get("sourceStream")) .auxiliaryFieldsAndValues((Map<String, Object>) event.get("auxiliaryFieldsAndValues")) .dataSourceId((String) event.get("dataSourceId")) .putAll((Map<String, Object>) event.get("fieldsAndValues")) .build(); } catch (IOException e) { throw new RuntimeException(e); } }
private List<StreamlineEvent> substitute(StreamlineEvent input) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); StrSubstitutor substitutor = new StrSubstitutor(input); for(Map.Entry<String, Object> entry: input.entrySet()) { if(shouldSubstitue(entry.getKey(), entry.getValue())) { builder.put(entry.getKey(), substitutor.replace(entry.getValue())); } else { builder.put(entry.getKey(), entry.getValue()); } } return Collections.<StreamlineEvent>singletonList(builder.dataSourceId(input.getDataSourceId()).build()); }
.dataSourceId("notificationsTestBolt") .header(header) .build(); .dataSourceId("notificationsTestBolt") .header(header) .build();
streamsToEvents.put(stream.getId(), Collections.singletonList(finalEventBuilder.dataSourceId(modelId).build()));
StreamlineEventImpl streamlineEvent = StreamlineEventImpl.builder() .fieldsAndValues(record) .dataSourceId(testRunSource.getId()) .build(); LOG.debug("Emitting event {} to stream {}", streamlineEvent, outputStream);
@Override public StreamlineEvent convert(CorrelatedValues input, StreamlineEvent inputEvent) { if (this.eventCorrelationInjector == null) { this.eventCorrelationInjector = new EventCorrelationInjector(); } StreamlineEvent result; if (input == null) { return null; } else if (outputFields != null && !outputFields.isEmpty()) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); for (int i = 0; i < outputFields.size(); i++) { builder.put(outputFields.get(i), input.get(i)); } if (inputEvent != null) { result = builder.dataSourceId(inputEvent.getDataSourceId()) .header(inputEvent.getHeader()) .sourceStream(inputEvent.getSourceStream()) .build(); } else { result = builder.build(); } } else { result = inputEvent; } return eventCorrelationInjector.injectCorrelationInformation(result, input.getCorrelated()); }
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); } } }
/** * 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 ); eventBuilder.put(outputKeyName, field); // adds null if field is not found in both tuples } StreamlineEventImpl slEvent = eventBuilder.dataSourceId("multiple sources").build(); return Collections.singletonList(slEvent); }
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; }
@Override public StreamlineEvent join(EventGroup eventGroup) { Map<String, Object> fieldValues = new HashMap<>(); Map<String, Object> auxiliaryFieldValues = new HashMap<>(); for (StreamlineEvent subEvent : eventGroup.getSplitEvents()) { if(subEvent.getAuxiliaryFieldsAndValues() != null) { auxiliaryFieldValues.putAll(subEvent.getAuxiliaryFieldsAndValues()); } fieldValues.putAll(subEvent); } return StreamlineEventImpl.builder() .fieldsAndValues(fieldValues) .dataSourceId(eventGroup.getDataSourceId()) .auxiliaryFieldsAndValues(auxiliaryFieldValues) .build(); } }
private List<StreamlineEvent> doTransform(StreamlineEvent input) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); for (String field : projectionTransform.getProjectionFields()) { builder.put(field, input.get(field)); } return Collections.<StreamlineEvent>singletonList(builder.dataSourceId(input.getDataSourceId()).build()); }
@Override public List<StreamlineEvent> execute(StreamlineEvent input) { StreamlineEventImpl.Builder builder = StreamlineEventImpl.builder(); builder.putAll(input); for (Map.Entry<String, ?> entry : mergeTransform.getDefaults().entrySet()) { if (!input.containsKey(entry.getKey())) { builder.put(entry.getKey(), entry.getValue()); } } return Collections.<StreamlineEvent>singletonList(builder.dataSourceId(input.getDataSourceId()).build()); }
@Override public List<Object> apply (ConsumerRecord<Object, ByteBuffer> consumerRecord) { Map < String, Object > keyValues = (Map<String, Object>) deserializer().deserialize(new ByteBufferInputStream(consumerRecord.value()), readerSchemaVersion); StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().putAll(keyValues).dataSourceId(dataSourceId).build(); KafkaTuple kafkaTuple = new KafkaTuple(streamlineEvent); kafkaTuple.routedTo(outputStream); return kafkaTuple; }
public Builder from(StreamlineEvent other) { return this.header(other.getHeader()) .sourceStream(other.getSourceStream()) .dataSourceId(other.getDataSourceId()) .auxiliaryFieldsAndValues(other.getAuxiliaryFieldsAndValues()) .putAll(other); }