Flink时间特性

Flink TimeCharacteristic

我在许多旧版本的 Flink 代码中看到一行定义了一些时间特征,像这样:env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);

但是,进一步查看文档表明这已被弃用。不再需要了吗?

从 Flink 1.12 开始,API StreamExecutionEnvironment.setStreamTimeCharacteristic(TimeCharacteristic) 已弃用。新的 API 是 DataStream.assignTimestampsAndWatermarks(WatermarkStrategy)

不再需要设置时间特性。

老实说,它做的并不多。时间特性决定了 TimeWindow 是 event-time 还是 processing-time window;将时间特征设置为为自动生成的时间戳和水印安排的摄取时间;以及其他一些小细节。一些 API 更改使时间特性完全不必要(主要是引入了新的 WatermarkStrategy 接口)。

引自 Flink 1.12 发行说明:

In Flink 1.12 the default stream time characteristic has been changed to EventTime, thus you don’t need to call this method for enabling event-time support anymore. Explicitly using processing-time windows and timers works in event-time mode. If you need to disable watermarks, please use ExecutionConfig.setAutoWatermarkInterval(long). If you are using IngestionTime, please manually set an appropriate WatermarkStrategy. If you are using generic “time window” operations (for example KeyedStream.timeWindow()) that change behaviour based on the time characteristic, please use equivalent operations that explicitly specify processing time or event time.