flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Ewen <se...@apache.org>
Subject Re: Sort tuple dataset
Date Sun, 15 Mar 2015 15:22:55 GMT
Hi Kristoffer!

There are a few issues with that code:

1) Grouping and then calling "sort group" sorts within the group. In your
case, you group after the entire element and each group has on value - the
element. Sorting inside the group does not make any difference. There is no
order across groups.

2) This code never groups and sorts. The calls to "groupBy(0).sortGroup(0,
Order.DESCENDING)." do not group and sort already, they set up a grouping
to be used with a reduce or aggregate function. The "getDataSet()" call
gets you the original data set, which is the original input.

To see an illustration of this, get the program plan
(env.getExecutionPlan()). You can render it using the html file


On Sun, Mar 15, 2015 at 3:29 PM, Kristoffer Sjögren <stoffe@gmail.com>

> Hi
> This is silly but I can't understand why the following code doesn't sort
> the collection of integers. It seems to be reasonable thing to do from an
> API perspective?
> Cheers,
> -Kristoffer
> final ExecutionEnvironment env =
> ExecutionEnvironment.getExecutionEnvironment();
>     env.fromCollection(Lists.newArrayList(2,1,5,3,4,5)).map(new
> MapFunction<Integer, Tuple1<Integer>>() {
>       @Override
>       public Tuple1<Integer> map(Integer value) throws Exception {
>         return new Tuple1(value);
>       }
>     }).groupBy(0).sortGroup(0, Order.DESCENDING).getDataSet().print();
>     env.execute();

View raw message