apache-flink:输出中的滑动窗口

时间:2017-04-07 13:36:30

标签: apache-flink

我正在编写一个小应用程序来理解FLINK中的滑动窗口(使用来自APACHE-KAFKA主题的数据输入):

//Split kafka stream by comma and create tuple 
DataStream<Tuple3<String, Integer, Date>> parsedStream = stream
    .map((line) -> {
       String[] cells = line.split(",");
       return new Tuple3(cells[1], Integer.parseInt(cells[4]), f.parse(cells[2]));
    });

DataStream<Tuple3<String, Integer, Date>> parsedStreamWithTSWM = parsedStream
        .assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor<Tuple3<String, Integer, Date>>(Time.minutes(1)) {

            @Override
            public long extractTimestamp(Tuple3<String, Integer, Date> element) {
                return element.f2.getTime();
            }
        });

//Sum values per windows and per id
DataStream<Tuple3<String, Integer, Date>>  AggStream = parsedStreamWithTSWM
    .keyBy(0)
    .window(SlidingEventTimeWindows.of(Time.minutes(30), Time.minutes(1)))
    .sum(1);

AggStream.print();

是否可以通过添加产生聚合输出的窗口详细信息来改进输出(AggStream.print();)?

$ tail -f flink-chapichapo-jobmanager-0.out
(228035740000002,300,Fri Apr 07 14:42:00 CEST 2017)
(228035740000000,28,Fri Apr 07 14:42:00 CEST 2017)
(228035740000002,300,Fri Apr 07 14:43:00 CEST 2017)
(228035740000000,27,Fri Apr 07 14:43:00 CEST 2017)
(228035740000002,300,Fri Apr 07 14:44:00 CEST 2017)
(228035740000000,26,Fri Apr 07 14:44:00 CEST 2017)
(228035740000001,27,Fri Apr 07 14:44:00 CEST 2017)
(228035740000002,300,Fri Apr 07 14:45:00 CEST 2017)
(228035740000000,25,Fri Apr 07 14:45:00 CEST 2017)

提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用可以访问patchForm() { this.payeeEditForm.setValue({ company: this.data.company, first_name: this.data.first_name, last_name: this.data.last_name, notes: this.data.notes }); } 信息的通用函数apply

Window

请参阅docs