private static Instant minTimestamp(Iterable<? extends WindowedValue<?>> elements) { Instant minTs = BoundedWindow.TIMESTAMP_MAX_VALUE; for (WindowedValue<?> element : elements) { if (element.getTimestamp().isBefore(minTs)) { minTs = element.getTimestamp(); } } return minTs; } }
private static Instant minTimestamp(Iterable<? extends WindowedValue<?>> elements) { Instant minTs = BoundedWindow.TIMESTAMP_MAX_VALUE; for (WindowedValue<?> element : elements) { if (element.getTimestamp().isBefore(minTs)) { minTs = element.getTimestamp(); } } return minTs; } }
@Override public int hashCode() { // Hash only the millis of the timestamp to be consistent with equals return Objects.hash(getValue(), getTimestamp().getMillis(), getWindows(), getPane()); }
@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 <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 <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 KV<Instant, WindowedValue<KV<K, V>>> map(WindowedValue<KV<K, V>> wv) { BoundedWindow window = Iterables.getOnlyElement(wv.getWindows()); Instant timestamp = timestampCombiner.assign(window, windowFn.getOutputTime(wv.getTimestamp(), window)); return KV.of(timestamp, wv); } }
@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 @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 @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 WindowedValue<KV<K, OutputT>> call(WindowedValue<KV<K, Iterable<InputT>>> windowedKv) throws Exception { return WindowedValue.of( KV.of(windowedKv.getValue().getKey(), fn.apply(windowedKv)), windowedKv.getTimestamp(), windowedKv.getWindows(), windowedKv.getPane()); } }
/** * Returns a collection of {@link WindowedValue WindowedValues} identical to this one, except each * is in exactly one of the windows that this {@link WindowedValue} is in. */ public Iterable<WindowedValue<T>> explodeWindows() { ImmutableList.Builder<WindowedValue<T>> windowedValues = ImmutableList.builder(); for (BoundedWindow w : getWindows()) { windowedValues.add(of(getValue(), getTimestamp(), w, getPane())); } return windowedValues.build(); }
@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); }
@Override public void registerByteSizeObserver(WindowedValue<T> value, ElementByteSizeObserver observer) throws Exception { InstantCoder.of().registerByteSizeObserver(value.getTimestamp(), observer); windowsCoder.registerByteSizeObserver(value.getWindows(), observer); PaneInfoCoder.INSTANCE.registerByteSizeObserver(value.getPane(), observer); valueCoder.registerByteSizeObserver(value.getValue(), observer); }