@Override public W getSideInputWindow(BoundedWindow mainWindow) { if (mainWindow instanceof GlobalWindow) { throw new IllegalArgumentException( "Attempted to get side input window for GlobalWindow from non-global WindowFn"); } return assignWindow(mainWindow.maxTimestamp()); } };
@FinishBundle public void finishBundle(FinishBundleContext c) { for (BoundedWindow w : windows) { c.output(null, w.maxTimestamp(), w); } } }
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); } }
protected static <T> Iterable<WindowedValue<T>> sortByWindows(Iterable<WindowedValue<T>> iter) { List<WindowedValue<T>> sorted = Lists.newArrayList(iter); sorted.sort(Comparator.comparing(o -> Iterables.getOnlyElement(o.getWindows()).maxTimestamp())); return sorted; }
@Override public IntervalWindow getSideInputWindow(BoundedWindow mainWindow) { if (mainWindow instanceof GlobalWindow) { throw new IllegalArgumentException( "Attempted to get side input window for GlobalWindow from non-global WindowFn"); } long lastStart = lastStartFor(mainWindow.maxTimestamp().minus(size)); return new IntervalWindow(new Instant(lastStart + period.getMillis()), size); } };
@Override public void onElement(OnElementContext c) throws Exception { // If the end of the window has already been reached, then we are already ready to fire // and do not need to set a wake-up timer. if (!endOfWindowReached(c)) { c.setTimer(c.window().maxTimestamp(), TimeDomain.EVENT_TIME); } }
@Override public void onMerge(OnMergeContext c) throws Exception { // If the end of the window has already been reached, then we are already ready to fire // and do not need to set a wake-up timer. if (!endOfWindowReached(c)) { c.setTimer(c.window().maxTimestamp(), TimeDomain.EVENT_TIME); } }
@Override public void onElement(OnElementContext c) throws Exception { // We're interested in knowing when the input watermark passes the end of the window. // (It is possible this has already happened, in which case the timer will be fired // almost immediately). if (!endOfWindowReached(c)) { c.setTimer(c.window().maxTimestamp(), TimeDomain.EVENT_TIME); } }
@ProcessElement public void processElement(ProcessContext c, BoundedWindow window) throws Exception { c.output(KV.of(window.maxTimestamp(), c.element())); } }
@FinishBundle public void finishBundle(FinishBundleContext c) throws Exception { for (BoundedWindow w : bundles.keySet()) { c.output(Lists.newArrayList(bundles.get(w)), w.maxTimestamp(), w); } } }
public static <W extends BoundedWindow> WatermarkCallback afterWindowExpiration( BoundedWindow window, WindowingStrategy<?, W> strategy, Runnable callback) { // Fire one milli past the end of the window. This ensures that all window expiration // timers are delivered first Instant firingAfter = window.maxTimestamp().plus(strategy.getAllowedLateness()).plus(1L); return new WatermarkCallback(firingAfter, callback); }
private boolean windowIsExpired(BoundedWindow w) { return timerInternals .currentInputWatermarkTime() .isAfter(w.maxTimestamp().plus(windowingStrategy.getAllowedLateness())); } }
@FinishBundle public void finishBundle(FinishBundleContext context) throws Exception { Multimap<BoundedWindow, KV<String, String>> kvs = fetchAndFlush(); for (BoundedWindow w : kvs.keySet()) { for (KV<String, String> kv : kvs.get(w)) { context.output(kv, w.maxTimestamp(), w); } } } }
@ProcessElement public void process( ProcessContext c, BoundedWindow w, @TimerId(timerId) Timer timer) { timer.set(w.maxTimestamp()); }
@ProcessElement public void processElement( @TimerId(timerId) Timer timer, BoundedWindow window, OutputReceiver<Integer> r) { timer.set(window.maxTimestamp()); r.output(3); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }
@ProcessElement public void processElement( ProcessContext context, @TimerId(timerId) Timer timer, @StateId(stateId) ValueState<String> state, BoundedWindow window) { timer.set(window.maxTimestamp()); state.write(context.element().getKey()); context.output( KV.of(context.element().getKey(), context.element().getValue() + offset)); }