Apache Beam 设置自定义事件时间戳和水印

Apache Beam setting custom Event timestamp and watermark

我正在使用 Apache Beam 从 Kafka 读取数据。由于乱序写入 Kafka,我想使用有效负载中的事件时间戳而不是默认的 LogAppendTime。

我在 Apache Beam: Error assigning event time using Withtimestamp

我们如何定义水印?考虑到它应该是单调的。

方法中

getWatermark(TimestampPolicy.PartitionContext ctx)

当事件晚了几个小时时,我们如何确定水印。

这似乎是一种非常常见的乱序写入和事件时间窗口的情况。我没有看到太多关于如何做到这一点的文献。

您可以使用 ParDooutputWithTimestamp 从数据中提取时间戳,就像这里描述的那样 https://beam.apache.org/documentation/programming-guide/#adding-timestamps-to-a-pcollections-elements