Jaehyeon Kim
10/11/2023, 10:19 PM...
class CustomTimestampAssigner(TimestampAssigner):
def extract_timestamp(self, value, record_timestamp):
if value.marker == "late":
return int(time.time_ns() / 1000000) + 50000
else:
return int(time.time_ns() / 1000000)
custom_watermark_strategy = WatermarkStrategy.for_monotonous_timestamps().with_timestamp_assigner(
CustomTimestampAssigner()
)
env = StreamExecutionEnvironment.get_execution_environment()
data_stream = env.from_collection(
collection=[(1, "a", "on_time"), (2, "a", "on_time"), (3, "a", "late")],
type_info=MyData.get_type_info(),
).assign_timestamps_and_watermarks(custom_watermark_strategy)
data_stream.map(MyData.from_row).map(Stats.from_mydata).key_by(lambda s: s.key).window(
TumblingEventTimeWindows.of(Time.minutes(1))
).reduce(Stats.merge).print()
env.execute()
# expected
3> Stats(value=6, key='a')
# actual
3> Stats(value=3, key='a')
3> Stats(value=3, key='a')Huib
10/11/2023, 10:27 PMJaehyeon Kim
10/11/2023, 10:34 PMHuib
10/11/2023, 10:53 PMJaehyeon Kim
10/11/2023, 11:08 PM