def on_timer(time_domain: TimeDomain, internal_timer: InternalTimer): timestamp = internal_timer.get_timestamp() state_current_key = internal_timer.get_key() user_current_key = user_key_selector(state_current_key) on_timer_ctx.set_timestamp(timestamp) on_timer_ctx.set_current_key(user_current_key) on_timer_ctx.set_time_domain(time_domain) return process_function.on_timer(timestamp, on_timer_ctx)
def on_processing_time(self, timer: InternalTimer): result = [] timestamp = timer.get_timestamp() key = timer.get_key() self._state_backend.set_current_key(key) window = timer.get_namespace() self._trigger_context.window = window if self._trigger_context.on_processing_time(timestamp): # fire result.append(self._emit_window_result(key, window)) if not self._window_assigner.is_event_time(): self._window_function.clean_window_if_needed(window, timestamp) return result
def on_event_time(self, timer: InternalTimer) -> None: self.trigger_context.user_key = self.user_key_selector(timer.get_key()) self.trigger_context.window = timer.get_namespace() if isinstance(self.window_assigner, MergingWindowAssigner): merging_windows = self.get_merging_window_set() state_window = merging_windows.get_state_window( self.trigger_context.window) if state_window is None: # Timer firing for non-existent window, this can only happen if a # trigger did not clean up timers. We have already cleared the merging # window and therefore the Trigger state, however, so nothing to do. return else: self.window_state.set_current_namespace(state_window) else: self.window_state.set_current_namespace( self.trigger_context.window) merging_windows = None trigger_result = self.trigger_context.on_event_time( timer.get_timestamp()) if trigger_result.is_fire(): contents = self.window_state.get() # for list state the iterable will never be none if isinstance(self.window_state, ListState): contents = [i for i in contents] if len(contents) == 0: contents = None if contents is not None: yield from self.emit_window_contents( self.trigger_context.window, contents) if trigger_result.is_purge(): self.window_state.clear() if self.window_assigner.is_event_time() and self.is_cleanup_time( self.trigger_context.window, timer.get_timestamp()): self.clear_all_state(self.trigger_context.window, self.window_state, merging_windows) if merging_windows is not None: merging_windows.persist()