leesf commented on a change in pull request #7897: [FLINK-11817] Uses aggregate
function in DataStream API Tutorial
URL: https://github.com/apache/flink/pull/7897#discussion_r262757924
##########
File path: docs/tutorials/datastream_api.md
##########
@@ -240,13 +255,28 @@ public class WikipediaAnalysis {
DataStream<Tuple2<String, Long>> result = keyedEdits
.timeWindow(Time.seconds(5))
- .fold(new Tuple2<>("", 0L), new FoldFunction<WikipediaEditEvent,
Tuple2<String, Long>>() {
+ .aggregate(new AggregateFunction<WikipediaEditEvent, Tuple2<String,
Long>, Tuple2<String, Long>>() {
@Override
- public Tuple2<String, Long> fold(Tuple2<String, Long> acc,
WikipediaEditEvent event) {
- acc.f0 = event.getUser();
- acc.f1 += event.getByteDiff();
- return acc;
- }
+ public Tuple2<String, Long> createAccumulator() {
+ return new Tuple2<>("", 0L);
+ }
+
+ @Override
+ public Tuple2<String, Long> add(WikipediaEditEvent value,
Tuple2<String, Long> accumulator) {
+ accumulator.f0 = value.getUser();
+ accumulator.f1 += value.getByteDiff();
+ return accumulator;
+ }
+
+ @Override
+ public Tuple2<String, Long> getResult(Tuple2<String, Long> accumulator)
{
+ return accumulator;
+ }
+
+ @Override
+ public Tuple2<String, Long> merge(Tuple2<String, Long> a,
Tuple2<String, Long> b) {
Review comment:
@mikeholler hi, it seems that using b makes no sence in the example.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services