@Override public void nextTuple() { try (BufferedReader br = new BufferedReader(Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8))) { String line; while ((line = br.readLine()) != null) { String[] result = line.split(delimiter); if (result.length != 2) { LOG.error("Format of input file not as expected. Expecting {} separated first name and last name", delimiter); } else { List<Object> values = new ArrayList<>(); values.add(StreamlineEventImpl.builder().sourceStream(outputStream).put(FIRST_NAME, result[0].trim()).put(LAST_NAME, result[1].trim()) .build()); spoutOutputCollector.emit(outputStream, values, UUID.randomUUID()); } } } catch (IOException e) { LOG.error("Got exception while reading file at {}", path); throw new RuntimeException(e); } }
private void putPmmlScoresInEvent(Map<FieldName, ?> predScores, Set<String> inserted, StreamlineEventImpl.Builder eventBuilder, List<FieldName> predOrOutFields, String msg) { for (FieldName predOrOutField : predOrOutFields) { final Object targetValue = predScores.get(predOrOutField); final String fieldName = predOrOutField.getValue(); final Object predValue = EvaluatorUtil.decode(targetValue); eventBuilder.put(fieldName, predValue); LOG.debug(msg, fieldName, predValue); inserted.add(fieldName); } } }
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()); }
@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()); }
/** * 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; }
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()); }