protected StateNamespace namespaceFor(W window) { return StateNamespaces.window(windowCoder, window); }
@Test public void testFromStringGlobalWindow() { assertStringKeyRoundTrips(GlobalWindow.Coder.INSTANCE, StateNamespaces.global()); assertStringKeyRoundTrips( GlobalWindow.Coder.INSTANCE, StateNamespaces.window(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE)); assertStringKeyRoundTrips( GlobalWindow.Coder.INSTANCE, StateNamespaces.windowAndTrigger(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE, 18)); }
@Override public void append(K key, W window, Iterator<V> values) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); while (values.hasNext()) { bagState.add(values.next()); } }
/** Test that WindowAndTrigger namespaces are prefixed by the related Window namespace. */ @Test public void testGlobalWindowPrefixing() { StateNamespace window = StateNamespaces.window(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE); StateNamespace windowAndTrigger = StateNamespaces.windowAndTrigger(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE, 57); assertThat(windowAndTrigger.stringKey(), Matchers.startsWith(window.stringKey())); assertThat( StateNamespaces.global().stringKey(), Matchers.not(Matchers.startsWith(window.stringKey()))); }
@Override public void append(K key, W window, Iterator<V> values) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); while (values.hasNext()) { bagState.add(values.next()); } }
/** Test that WindowAndTrigger namespaces are prefixed by the related Window namespace. */ @Test public void testIntervalWindowPrefixing() { StateNamespace window = StateNamespaces.window(intervalCoder, intervalWindow(1000, 87392)); StateNamespace windowAndTrigger = StateNamespaces.windowAndTrigger(intervalCoder, intervalWindow(1000, 87392), 57); assertThat(windowAndTrigger.stringKey(), Matchers.startsWith(window.stringKey())); assertThat( StateNamespaces.global().stringKey(), Matchers.not(Matchers.startsWith(window.stringKey()))); }
@Override public void setForWindow(BoundedWindow window) { Instant gcTime = LateDataUtils.garbageCollectionTime(window, windowingStrategy); // make sure this fires after any window.maxTimestamp() timers gcTime = gcTime.plus(GC_DELAY_MS); timerInternals.setTimer( StateNamespaces.window(windowCoder, window), GC_TIMER_ID, gcTime, TimeDomain.EVENT_TIME); }
@Override public void clear(K key, W window) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); bagState.clear(); }
@Override public void clear(K key, W window) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); bagState.clear(); }
@Override public Iterable<V> get(K key, W window) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); return bagState.read(); }
@Override public Iterable<V> get(K key, W window) { initStateInternals(key); StateNamespace namespace = StateNamespaces.window(windowCoder, window); BagState<V> bagState = stateInternals.state(namespace, stateTag); return bagState.read(); }
private StateNamespace windowNamespace(W window) { return StateNamespaces.window(windowFn.windowCoder(), window); }
@Override public void onTimer( String timerId, BoundedWindow window, Instant timestamp, TimeDomain timeDomain) { firedTimers.add( TimerData.of( timerId, StateNamespaces.window(IntervalWindow.getCoder(), (IntervalWindow) window), timestamp, timeDomain)); }
private StateNamespace windowNamespace(W window) { return StateNamespaces.window(windowFn.windowCoder(), checkNotNull(window)); }
private static StateNamespace windowNamespace(IntervalWindow window) { return StateNamespaces.window((Coder) WINDOWING_STRATEGY.getWindowFn().windowCoder(), window); }
public void fireTimer(W window, Instant timestamp, TimeDomain domain) throws Exception { ReduceFnRunner<String, InputT, OutputT, W> runner = createRunner(); ArrayList<TimerData> timers = new ArrayList<>(1); timers.add( TimerData.of(StateNamespaces.window(windowFn.windowCoder(), window), timestamp, domain)); runner.onTimers(timers); runner.persist(); }
@OnTimer(TIMER_ID) public void onTimer(OnTimerContext context) { onTimerInvocations.add( TimerData.of( DoFnWithTimers.TIMER_ID, StateNamespaces.window(windowCoder, (W) context.window()), context.timestamp(), context.timeDomain())); } }
public void fireTimers(W window, TimestampedValue<TimeDomain>... timers) throws Exception { ReduceFnRunner<String, InputT, OutputT, W> runner = createRunner(); ArrayList<TimerData> timerData = new ArrayList<>(timers.length); for (TimestampedValue<TimeDomain> timer : timers) { timerData.add( TimerData.of( StateNamespaces.window(windowFn.windowCoder(), window), timer.getTimestamp(), timer.getValue())); } runner.onTimers(timerData); runner.persist(); }
@Test public void testCompareByNamespace() { Instant timestamp = new Instant(100); IntervalWindow firstWindow = new IntervalWindow(new Instant(0), timestamp); IntervalWindow secondWindow = new IntervalWindow(timestamp, new Instant(200)); Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder(); StateNamespace firstWindowNs = StateNamespaces.window(windowCoder, firstWindow); StateNamespace secondWindowNs = StateNamespaces.window(windowCoder, secondWindow); TimerData secondEventTime = TimerData.of(firstWindowNs, timestamp, TimeDomain.EVENT_TIME); TimerData thirdEventTime = TimerData.of(secondWindowNs, timestamp, TimeDomain.EVENT_TIME); assertThat(secondEventTime, lessThan(thirdEventTime)); }
@Test public void testTimerDataCoder() throws Exception { CoderProperties.coderDecodeEncodeEqual( TimerDataCoder.of(GlobalWindow.Coder.INSTANCE), TimerData.of( "arbitrary-id", StateNamespaces.global(), new Instant(0), TimeDomain.EVENT_TIME)); Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder(); CoderProperties.coderDecodeEncodeEqual( TimerDataCoder.of(windowCoder), TimerData.of( "another-id", StateNamespaces.window( windowCoder, new IntervalWindow(new Instant(0), new Instant(100))), new Instant(99), TimeDomain.PROCESSING_TIME)); }