@Override public void registerByteSizeObserver(WindowedValue<T> value, ElementByteSizeObserver observer) throws Exception { valueCoder.registerByteSizeObserver(value.getValue(), observer); }
@Override public ByteBuffer groupBy(WindowedValue<KV<K, V>> wv) { try { return ByteBuffer.wrap(CoderUtils.encodeToByteArray(keyCoder, wv.getValue().getKey())); } catch (CoderException e) { throw new RuntimeException(e); } } }
@Override public ByteBuffer getKey(WindowedValue<SingletonKeyedWorkItem<K, V>> value) throws Exception { K key = value.getValue().key(); byte[] keyBytes = CoderUtils.encodeToByteArray(keyCoder, key); return ByteBuffer.wrap(keyBytes); }
@Override public ByteBuffer getKey(WindowedValue<KV<K, V>> value) throws Exception { K key = value.getValue().getKey(); byte[] keyBytes = CoderUtils.encodeToByteArray(keyCoder, key); return ByteBuffer.wrap(keyBytes); }
@Override public ByteBuffer getKey(WindowedValue<KV<K, V>> value) throws Exception { K key = value.getValue().getKey(); byte[] keyBytes = CoderUtils.encodeToByteArray(keyCoder, key); return ByteBuffer.wrap(keyBytes); }
@Override public WindowedValue<KV<Void, T>> map(WindowedValue<T> value) { return value.withValue(KV.of(null, value.getValue())); } }
@Override public Iterable<WindowedValue<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>>> processElementInReadyWindows( WindowedValue<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>> windowedKWI) { checkTrivialOuterWindows(windowedKWI); BoundedWindow window = getUnderlyingWindow(windowedKWI.getValue()); if (!isReady(window)) { return Collections.singletonList(windowedKWI); } underlying.processElement(windowedKWI); return Collections.emptyList(); }
@Override public String getKey( WindowedValue<KV<String, Integer>> kvWindowedValue) throws Exception { return kvWindowedValue.getValue().getKey(); } },
@Override public void flatMap( WindowedValue<ValueWithRecordId<T>> value, Collector<WindowedValue<T>> collector) throws Exception { collector.collect(value.withValue(value.getValue().getValue())); } }
@Override public void flatMap( WindowedValue<ValueWithRecordId<T>> value, Collector<WindowedValue<T>> collector) throws Exception { collector.collect(value.withValue(value.getValue().getValue())); } }
/** Extract window from a {@link KV} with {@link WindowedValue} value. */ static <K, V> Function<KV<K, WindowedValue<V>>, WindowedValue<KV<K, V>>> toKVByWindowInValue() { return kv -> { WindowedValue<V> wv = kv.getValue(); return wv.withValue(KV.of(kv.getKey(), wv.getValue())); }; }
@Override protected boolean matchesSafely(WindowedValue<? extends T> windowedValue) { return valueMatcher.matches(windowedValue.getValue()) && timestampMatcher.matches(windowedValue.getTimestamp()) && windowsMatcher.matches(windowedValue.getWindows()) && paneInfoMatcher.matches(windowedValue.getPane()); } }
@Override public <T> void output(TupleTag<T> tag, WindowedValue<T> output) { collector.collect( WindowedValue.of( new RawUnionValue(outputMap.get(tag), output.getValue()), output.getTimestamp(), output.getWindows(), output.getPane())); } }
@Override public void collect(StreamRecord<WindowedValue<ValueWithRecordId<T>>> record) { emittedElements.add(record.getValue().getValue().getValue()); count++; if (count >= elementsToConsumeLimit) { throw new SuccessException(); } }
@Override public void processElement(WindowedValue<InputT> compressedElement) throws Exception { for (WindowedValue<InputT> element : compressedElement.explodeWindows()) { Collection<? extends BoundedWindow> windows = assignWindows(windowFn, element); outputBundle.add( WindowedValue.of( element.getValue(), element.getTimestamp(), windows, element.getPane())); } }
@Override public void processElement(WindowedValue<InputT> compressedElement) throws Exception { for (WindowedValue<InputT> element : compressedElement.explodeWindows()) { Collection<? extends BoundedWindow> windows = assignWindows(windowFn, element); outputBundle.add( WindowedValue.of( element.getValue(), element.getTimestamp(), windows, element.getPane())); } }
@Override public void flatMap(WindowedValue<T> input, Collector<WindowedValue<T>> collector) throws Exception { Collection<W> windows = windowFn.assignWindows(new FlinkAssignContext<>(windowFn, input)); for (W window : windows) { collector.collect( WindowedValue.of(input.getValue(), input.getTimestamp(), window, input.getPane())); } } }
@Override @SuppressWarnings("unchecked") public <T> void output(TupleTag<T> tag, WindowedValue<T> output) { collector.collect( WindowedValue.of( new RawUnionValue(0 /* single output */, output.getValue()), output.getTimestamp(), output.getWindows(), output.getPane())); } }
@Override public void flatMap(WindowedValue<T> input, Collector<WindowedValue<T>> collector) throws Exception { Collection<W> windows = windowFn.assignWindows(new FlinkAssignContext<>(windowFn, input)); for (W window : windows) { collector.collect( WindowedValue.of(input.getValue(), input.getTimestamp(), window, input.getPane())); } } }
@Override public void encode(WindowedValue<T> windowedElem, OutputStream outStream, Context context) throws CoderException, IOException { InstantCoder.of().encode(windowedElem.getTimestamp(), outStream); windowsCoder.encode(windowedElem.getWindows(), outStream); PaneInfoCoder.INSTANCE.encode(windowedElem.getPane(), outStream); valueCoder.encode(windowedElem.getValue(), outStream, context); }