@ProcessElement public void processElement(ProcessContext c) { KV<KV<String, String>, KV<Double, Integer>> result = c.element(); String call1 = result.getKey().getKey(); String call2 = result.getKey().getValue(); Double sumOfRatios = result.getValue().getKey(); int numberOfRatios = result.getValue().getValue(); c.output(Joiner.on('\t').join(call1, call2, sumOfRatios / numberOfRatios, sumOfRatios, numberOfRatios)); } }
@ProcessElement public void processElement(ProcessContext c) { KV<KV<String, String>, KV<Double, Integer>> result = c.element(); String call1 = result.getKey().getKey(); String call2 = result.getKey().getValue(); Double sumOfRatios = result.getValue().getKey(); int numberOfRatios = result.getValue().getValue(); c.output(Joiner.on('\t').join(call1, call2, sumOfRatios / numberOfRatios, sumOfRatios, numberOfRatios)); } }
@Override public boolean canStopPolling(Instant now, KV<Instant, ReadableDuration> state) { Instant timeOfLastNewOutput = state.getKey(); ReadableDuration maxTimeSinceNewOutput = state.getValue(); return timeOfLastNewOutput != null && new Duration(timeOfLastNewOutput, now).isLongerThan(maxTimeSinceNewOutput); }
/** * Create a map of information that describes how to write pipeline output to text. This map is * passed to the {@link WriteToText} constructor to write user score sums. */ protected static Map<String, WriteToText.FieldFn<KV<String, Integer>>> configureOutput() { Map<String, WriteToText.FieldFn<KV<String, Integer>>> config = new HashMap<>(); config.put("user", (c, w) -> c.element().getKey()); config.put("total_score", (c, w) -> c.element().getValue()); return config; }
@ProcessElement public void processElement(ProcessContext c) { /** * Filter null value when AggregateCombineFn for nothing, see {@link * org.talend.components.processing.runtime.aggregate.AggregateCombineFn#extractOutput(AggregateCombineFn.AggregateAccumulator)} */ if (c.element().getValue() != null) { c.output(c.element()); } } }))
@ProcessElement public void processElement(ProcessContext c, BoundedWindow window) { StringBuilder str = new StringBuilder(); KV<String, List<CompletionCandidate>> elem = c.element(); str.append(elem.getKey() + " @ " + window + " -> "); for (CompletionCandidate cand: elem.getValue()) { str.append(cand.toString() + " "); } System.out.println(str.toString()); c.output(str.toString()); } }
@ProcessElement public void processElement(ProcessContext c) { /** * Filter null value when AggregateCombineFn for nothing, see {@link * org.talend.components.processing.runtime.aggregate.AggregateCombineFn#extractOutput(AggregateCombineFn.AggregateAccumulator)} */ if (c.element().getValue() != null) { c.output(c.element()); } } }))