Пример #1
0
            def on_processing_time(internal_timer: InternalTimerImpl):
                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_current_key(user_current_key)
                on_timer_ctx.set_time_domain(TimeDomain.PROCESSING_TIME)

                return process_function.on_timer(timestamp, on_timer_ctx)
Пример #2
0
    def accept(self, operation_input):
        input_type = operation_input[0]
        normal_data = operation_input[1]
        timestamp = operation_input[2]
        watermark = operation_input[3]
        timer_data = operation_input[4]

        self.advance_watermark(watermark)
        if input_type == RunnerInputType.NORMAL_RECORD.value:
            yield from self.process_element(normal_data, timestamp)
        elif input_type == RunnerInputType.TRIGGER_TIMER.value:
            timer_type = timer_data[0]
            key = timer_data[1]
            serialized_namespace = timer_data[2]
            if self._namespace_coder is not None:
                namespace = self._namespace_coder.decode_nested(
                    serialized_namespace)
            else:
                namespace = None
            internal_timer = InternalTimerImpl(timestamp, key, namespace)
            if timer_type == TimerType.EVENT_TIME.value:
                yield from self.on_event_time(internal_timer)
            elif timer_type == TimerType.PROCESSING_TIME.value:
                yield from self.on_processing_time(internal_timer)
            else:
                raise Exception("Unsupported timer type: %d" % timer_type)
        else:
            raise Exception("Unsupported input type: %d" % input_type)
Пример #3
0
 def process_element_or_timer(self, input_data: Tuple[int, Row, int, int, Row]):
     if input_data[0] == NORMAL_RECORD:
         self.group_agg_function.process_watermark(input_data[3])
         if has_cython:
             input_row = InternalRow.from_row(input_data[1])
         else:
             input_row = input_data[1]
         result_datas = self.group_agg_function.process_element(input_row)
         for result_data in result_datas:
             yield [NORMAL_RECORD, result_data, None]
         timers = self.group_agg_function.get_timers()
         for timer in timers:
             timer_operand_type = timer[0]  # type: TimerOperandType
             internal_timer = timer[1]  # type: InternalTimer
             window = internal_timer.get_namespace()
             self._reuse_key_data._values = internal_timer.get_key()
             timestamp = internal_timer.get_timestamp()
             encoded_window = self._namespace_coder.encode(window)
             self._reuse_timer_data._values = \
                 [timer_operand_type.value, self._reuse_key_data, timestamp, encoded_window]
             yield [TRIGGER_TIMER, None, self._reuse_timer_data]
     else:
         timestamp = input_data[2]
         timer_data = input_data[4]
         key = list(timer_data[1])
         timer_type = timer_data[0]
         namespace = self._namespace_coder.decode(timer_data[2])
         timer = InternalTimerImpl(timestamp, key, namespace)
         if timer_type == REGISTER_EVENT_TIMER:
             result_datas = self.group_agg_function.on_event_time(timer)
         else:
             result_datas = self.group_agg_function.on_processing_time(timer)
         for result_data in result_datas:
             yield [NORMAL_RECORD, result_data, None]
Пример #4
0
 def process_element_or_timer(self, input_data: Tuple[int, Row, int, int,
                                                      Row]):
     results = []
     if input_data[0] == NORMAL_RECORD:
         self.group_agg_function.process_watermark(input_data[3])
         if has_cython:
             input_row = InternalRow(input_data[1]._values,
                                     input_data[1].get_row_kind().value)
         else:
             input_row = input_data[1]
         result_datas = self.group_agg_function.process_element(input_row)
         for result_data in result_datas:
             result = [NORMAL_RECORD, result_data, None]
             results.append(result)
         timers = self.group_agg_function.get_timers()
         for timer in timers:
             timer_operand_type = timer[0]  # type: TimerOperandType
             internal_timer = timer[1]  # type: InternalTimer
             window = internal_timer.get_namespace()
             key = internal_timer.get_key()
             timestamp = internal_timer.get_timestamp()
             encoded_window = self._namespace_coder.encode_nested(window)
             timer_data = [
                 TRIGGER_TIMER, None,
                 [timer_operand_type.value, key, timestamp, encoded_window]
             ]
             results.append(timer_data)
     else:
         timestamp = input_data[2]
         timer_data = input_data[4]
         key = list(timer_data[1])
         timer_type = timer_data[0]
         namespace = self._namespace_coder.decode_nested(timer_data[2])
         timer = InternalTimerImpl(timestamp, key, namespace)
         if timer_type == REGISTER_EVENT_TIMER:
             result_datas = self.group_agg_function.on_event_time(timer)
         else:
             result_datas = self.group_agg_function.on_processing_time(
                 timer)
         for result_data in result_datas:
             result = [NORMAL_RECORD, result_data, None]
             results.append(result)
     return results