Refine search
/** * Estimate the number of additional bytes required to store this record. Including the key, the * value and any overhead for objects and references. */ private long estimateRecordBytes(KV<byte[], byte[]> record) { return RECORD_MEMORY_OVERHEAD_ESTIMATE + record.getKey().length + record.getValue().length; }
@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; }
/** This outputs records which will be used to construct the entry set. */ private void outputMetadataRecordForEntrySet( ProcessContext c, KV<KV<K, W>, WindowedValue<V>> value) { c.output( outputForEntrySet, KV.of( ismCoder.hash( ImmutableList.of(IsmFormat.getMetadataKey(), value.getKey().getValue())), KV.of(value.getKey().getValue(), value.getKey().getKey()))); } }
@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( @Element KV<Integer, Iterable<KV<KeyT, ValueT>>> input, OutputReceiver<KV<Integer, KV<KeyT, ValueT>>> outputReceiver) { final Integer key = input.getKey(); for (KV<KeyT, ValueT> element : requireNonNull(input.getValue(), "Iterable can not be null.")) { outputReceiver.output(KV.of(key, element)); } } }