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()
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_processing_time(self, internal_timer: InternalTimer) -> Iterable: yield from self._on_timer(TimeDomain.PROCESSING_TIME, internal_timer.get_key(), internal_timer.get_timestamp())
def on_event_time(self, internal_timer: InternalTimer) -> Iterable: yield from self._on_timer(TimeDomain.EVENT_TIME, internal_timer.get_key(), internal_timer.get_timestamp())