How can I count the element in datastream

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I count the element in datastream

邓俊华
hi,

How can I count the element in datastream? I don't want the keyBy().



Reply | Threaded
Open this post in threaded view
|

Re: How can I count the element in datastream

Tzu-Li (Gordon) Tai
Hi!

Do you mean that you want to count all elements across all partitions of a
DataStream?
To do that, you'll need to transform the DataStream with an operator of
parallelism 1, e.g.

DatatStream<String> stream = ...;
stream.map(new CountingMap<>()).setParallelism(1);

Cheers,
Gordon



--
Sent from: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

回复:How can I count the element in datastream

邓俊华
In reply to this post by 邓俊华
Yes, I want count all the elements. But I can't do cumulative.
eg:
   
distinctOrder.map(new MapFunction<Order, Object>() {

@Override
public Object map(Order value) throws Exception {

return null;
}
}).setParallelism(1).print();


------------------------------------------------------------------
发件人:Tzu-Li (Gordon) Tai <[hidden email]>
发送时间:2018年1月12日(星期五) 22:37
收件人:user <[hidden email]>
主 题:Re: How can I count the element in datastream

Hi!

Do you mean that you want to count all elements across all partitions of a
DataStream?
To do that, you'll need to transform the DataStream with an operator of
parallelism 1, e.g.

DatatStream<String> stream = ...;
stream.map(new CountingMap<>()).setParallelism(1);

Cheers,
Gordon



--
Sent from: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/