Re: Why FoldFunction deprecated?

2018-05-07 Thread Fabian Hueske
Hi,

FoldFunction was deprecated because it doesn't support partial aggregation.
AggregateFunction is much more expressive, however requires a bit more
implementation effort.
In favor of a concise API, FoldFunction was deprecated because it doesn't
offer more functionality than AggregateFunction.

You can implement your use case also easily using a MapFunction before the
window, that maps WikipediaEditEvent to Tuple2 and a
ReduceFunction in the window that sums the length field.

Best, Fabian

2018-05-04 23:36 GMT+02:00 陈梓立 :

> I just write a code snip like
>
> ```
> .fold(new Tuple2<>("", 0L), new FoldFunction Tuple2>() {
> @Override
> public Tuple2 fold(Tuple2
> acc, WikipediaEditEvent event) {
> acc.f0 = event.getUser();
> acc.f1 += event.getByteDiff();
> return acc;
> }
> });
> ```
>
> and replace it using `aggregate()`
>
> ```
> .aggregate(new AggregateFunction Long>, Tuple2>() {
> @Override
> public Tuple2 createAccumulator() {
> return new Tuple2<>("", 0L);
> }
>
> @Override
> public Tuple2 add(WikipediaEditEvent
> event, Tuple2 acc) {
> return new Tuple2<>(event.getUser(), acc.f1 +
> event.getByteDiff());
> }
>
> @Override
> public Tuple2 getResult(Tuple2 Long> acc) {
> return acc;
> }
>
> @Override
> public Tuple2 merge(Tuple2
> a, Tuple2 b) {
> return new Tuple2<>(a.f0, a.f1 + b.f1);
> }
> });
> ```
>
> It seems I have to write much more code using `aggregate()`
>
> Is there something I miss so that write so much code? Or say, maybe
> `aggregate()` is expressive, but why `fold()` deprecated? Since `fold` is a
> general concept people can understand.
>


Why FoldFunction deprecated?

2018-05-04 Thread 陈梓立
I just write a code snip like

```
.fold(new Tuple2<>("", 0L), new FoldFunction>() {
@Override
public Tuple2 fold(Tuple2
acc, WikipediaEditEvent event) {
acc.f0 = event.getUser();
acc.f1 += event.getByteDiff();
return acc;
}
});
```

and replace it using `aggregate()`

```
.aggregate(new AggregateFunction,
Tuple2>() {
@Override
public Tuple2 createAccumulator() {
return new Tuple2<>("", 0L);
}

@Override
public Tuple2 add(WikipediaEditEvent
event, Tuple2 acc) {
return new Tuple2<>(event.getUser(), acc.f1 +
event.getByteDiff());
}

@Override
public Tuple2 getResult(Tuple2 acc) {
return acc;
}

@Override
public Tuple2 merge(Tuple2
a, Tuple2 b) {
return new Tuple2<>(a.f0, a.f1 + b.f1);
}
});
```

It seems I have to write much more code using `aggregate()`

Is there something I miss so that write so much code? Or say, maybe
`aggregate()` is expressive, but why `fold()` deprecated? Since `fold` is a
general concept people can understand.