@Override public KV<Row, Row> apply(Row input) { return KV.of(input, input); } }
@Override public void describeMismatch(Object item, Description mismatchDescription) { @SuppressWarnings("unchecked") KV<?, V> kvItem = (KV<?, V>) item; if (!valueMatcher.matches(kvItem.getValue())) { mismatchDescription.appendText("value did not match: "); valueMatcher.describeMismatch(kvItem.getValue(), mismatchDescription); } }
@Override public int partitionFor(KV<String, List<CompletionCandidate>> elem, int numPartitions) { return elem.getKey().length() > minPrefix ? 0 : 1; } }
@ProcessElement public void processElement( @Element String element, OutputReceiver<KV<String, String>> r) throws Exception { Matcher m = pattern.matcher(element); if (m.find()) { r.output(KV.of(m.group(keyGroupName), m.group(valueGroupName))); } } }));
@Override public Iterable<T> extractOutput( Top.BoundedHeap<KV<Integer, T>, SerializableComparator<KV<Integer, T>>> accumulator) { List<T> out = new ArrayList<>(); for (KV<Integer, T> element : accumulator.extractOutput()) { out.add(element.getValue()); } return out; }
@Override public int partitionFor(KV<String, List<CompletionCandidate>> elem, int numPartitions) { return elem.getKey().length() > minPrefix ? 0 : 1; } }
public SyntheticStep(Options options) { options.validate(); this.options = options; Random rand = new Random(); // use a random id so that a pipeline could have multiple SyntheticSteps this.idAndThroughput = KV.of(rand.nextLong(), options.maxWorkerThroughput); }
@Override public Boolean apply(KV<Position, AlleleFreq> input) { double freq = input.getValue().getRefFreq(); if (freq >= minFreq && (1.0 - freq) >= minFreq) { return true; } return false; } }
@Override public Iterable<KV<byte[], byte[]>> sort() { checkState(!sortCalled, "sort() can only be called once."); sortCalled = true; Comparator<KV<byte[], byte[]>> kvComparator = (o1, o2) -> COMPARATOR.compare(o1.getKey(), o2.getKey()); records.sort(kvComparator); return Collections.unmodifiableList(records); }
@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)); } }
static <K, V> void output(DoFn<?, KV<K, V>>.FinishBundleContext context, Map<? extends K, ? extends V> map, BoundedWindow window) { for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { context.output(KV.<K, V>of(entry.getKey(), entry.getValue()), window.maxTimestamp(), window); } }