apache-flink - 处理来自 flink 数据流的输出数据
问题描述
下面是我的流处理的伪代码。
Datastream env = StreamExecutionEnvironment.getExecutionEnvironment()
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
Datastream stream = env.addSource() .map(mapping to java object)
.filter(filter for specific type of events)
.assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor(Time.seconds(2)){})
.timeWindowAll(Time.seconds(10));
//collect all records.
Datastream windowedStream = stream.apply(new AllWindowFunction(...))
Datastream processedStream = windowedStream.keyBy(...).reduce(...)
String outputPath = ""
final StreamingFileSink sink = StreamingFileSink.forRowFormat(...).build();
processedStream.addSink(sink)
上面的代码流程是创建多个文件,我猜每个文件都有不同窗口的记录。例如,每个文件中的记录都有 30-40 秒之间的时间戳,而窗口时间只有 10 秒。我预期的输出模式是将每个窗口数据写入单独的文件。对此的任何参考或输入都会有很大帮助。
解决方案
看一下BucketAssigner接口。它应该足够灵活以满足您的需求。您只需要确保您的流事件包含足够的信息来确定您希望它们写入的路径。