@Override public <KeyT, ValueT> MapState<KeyT, ValueT> bindMap( String id, StateSpec<MapState<KeyT, ValueT>> spec, Coder<KeyT> mapKeyCoder, Coder<ValueT> mapValueCoder) { return binder.bindMap(tagForSpec(id, spec), mapKeyCoder, mapValueCoder); }
@Override public <InputT, AccumT, OutputT> CombiningState<InputT, AccumT, OutputT> bindCombiningWithContext( String id, StateSpec<CombiningState<InputT, AccumT, OutputT>> spec, Coder<AccumT> accumCoder, CombineFnWithContext<InputT, AccumT, OutputT> combineFn) { return binder.bindCombiningValueWithContext(tagForSpec(id, spec), accumCoder, combineFn); }
private static void advanceInputWatermark( InMemoryTimerInternals timerInternals, Instant newInputWatermark, DoFnRunner<?, ?> toTrigger) throws Exception { timerInternals.advanceInputWatermark(newInputWatermark); TimerInternals.TimerData timer; while ((timer = timerInternals.removeNextEventTimer()) != null) { StateNamespace namespace = timer.getNamespace(); checkArgument(namespace instanceof StateNamespaces.WindowNamespace); BoundedWindow window = ((StateNamespaces.WindowNamespace) namespace).getWindow(); toTrigger.onTimer(timer.getTimerId(), window, timer.getTimestamp(), timer.getDomain()); } }
private void fireTimer( TimerInternals.TimerData timer, DoFnRunner<KV<K, V>, OutputT> doFnRunner) { StateNamespace namespace = timer.getNamespace(); checkArgument(namespace instanceof StateNamespaces.WindowNamespace); BoundedWindow window = ((StateNamespaces.WindowNamespace) namespace).getWindow(); doFnRunner.onTimer(timer.getTimerId(), window, timer.getTimestamp(), timer.getDomain()); }
@Override public void processElement(WindowedValue<KeyedWorkItem<K, InputT>> elem) { Iterable<WindowedValue<InputT>> nonLateElements = lateDataFilter.filter(elem.getValue().key(), elem.getValue().elementsIterable()); KeyedWorkItem<K, InputT> keyedWorkItem = KeyedWorkItems.workItem( elem.getValue().key(), elem.getValue().timersIterable(), nonLateElements); doFnRunner.processElement(elem.withValue(keyedWorkItem)); }
@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); }
private void prefetchOnTrigger( final ReduceFn<K, InputT, OutputT, W>.Context directContext, ReduceFn<K, InputT, OutputT, W>.Context renamedContext) { paneInfoTracker.prefetchPaneInfo(directContext); watermarkHold.prefetchExtract(renamedContext); nonEmptyPanes.isEmpty(renamedContext.state()).readLater(); reduceFn.prefetchOnTrigger(directContext.state()); }
@Override public WatermarkHoldState bindWatermark( String id, StateSpec<WatermarkHoldState> spec, TimestampCombiner timestampCombiner) { return binder.bindWatermark(tagForSpec(id, spec), timestampCombiner); } };
@Override public <InputT, AccumT, OutputT> CombiningState<InputT, AccumT, OutputT> bindCombining( String id, StateSpec<CombiningState<InputT, AccumT, OutputT>> spec, Coder<AccumT> accumCoder, CombineFn<InputT, AccumT, OutputT> combineFn) { return binder.bindCombiningValue(tagForSpec(id, spec), accumCoder, combineFn); }
@Override public void onMerge(OnMergeContext c) throws Exception { StateMerging.mergeCombiningValues(c.state(), bufferTag); } };
@Override public <T> BagState<T> bindBag(String id, StateSpec<BagState<T>> spec, Coder<T> elemCoder) { return binder.bindBag(tagForSpec(id, spec), elemCoder); }
@Override public <T> SetState<T> bindSet(String id, StateSpec<SetState<T>> spec, Coder<T> elemCoder) { return binder.bindSet(tagForSpec(id, spec), elemCoder); }
/** Create a state tag for the given id and spec. */ public static <StateT extends State> StateTag<StateT> tagForSpec( String id, StateSpec<StateT> spec) { return new SimpleStateTag<>(new StructuredId(id), spec); }
@Override public StateTag<StateT> asKind(StateKind kind) { return new SimpleStateTag<>(id.asKind(kind), spec); }
public ReduceFn<K, InputT, OutputT, W>.OnTriggerContext forTrigger( W window, PaneInfo pane, StateStyle style, OnTriggerCallbacks<OutputT> callbacks) { return new OnTriggerContextImpl(stateAccessor(window, style), pane, callbacks); }
public boolean isMarkedFinished(W window) { return createRunner().isFinished(window); }
public boolean hasNoActiveWindows() { return createRunner().hasNoActiveWindows(); }
private void fireTimer(TimerInternals.TimerData timer, DoFnRunner<KV<K, V>, OutputT> doFnRunner) { StateNamespace namespace = timer.getNamespace(); checkArgument(namespace instanceof StateNamespaces.WindowNamespace); BoundedWindow window = ((StateNamespaces.WindowNamespace) namespace).getWindow(); doFnRunner.onTimer(timer.getTimerId(), window, timer.getTimestamp(), timer.getDomain()); }