wangpeibin713 edited a comment on issue #7786: [FLINK-11706] Add the SumFunction to support KeyedStream.sum URL: https://github.com/apache/flink/pull/7786#issuecomment-465968792 ``` DataStream<Tuple2<Long, Integer[]>> src = env.fromCollection(Arrays.asList( new Tuple2<>(1L, new Integer[]{2, 4}), new Tuple2<>(1L, new Integer[]{3, 6}), new Tuple2<>(1L, new Integer[]{4, 8}) )); ``` with the flatmap function as your code, the output of the datastream (show above) is : ``` (1,2) (1,6) (1,9) (1,15) (1,19) (1,27) ``` my expected output is : ``` (1,[2, 4]) (1,[5, 10]) (1,[9, 18]) ``` > How about the below code > > ``` > src.flatMap(new FlatMapFunction<Tuple2<Long, Integer[]>, Tuple2<Long, Integer>>() { > @Override > public void flatMap(Tuple2<Long, Integer[]> value, Collector<Tuple2<Long, Integer>> out) throws Exception { > for (Integer v : value.f1) { > out.collect(new Tuple2<>(value.f0, v)); > } > } > }).keyBy(0) > .sum(1) > .print(); > ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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
