reduce a data stream to other type

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

reduce a data stream to other type

Soheil Pourbafrani
Hi, I have a keyed datastream in the type of Tuple2<Long, byte[]>. I want to reduce it and merge all of the byte[] for a key. (the first filed (Long) is the key). So I need reduce function return the type Tuple2<Long, ArrayList<byte[]>>, but reduce function didn't allow that! How can I do such job in Flink?
Reply | Threaded
Open this post in threaded view
|

Re: reduce a data stream to other type

Hequn Cheng
Hi Soheil,

Yes, reduce function doesn't allow this. A ReduceFunction specifies how two elements from the input are combined to produce an output element of the same type. 
You can use AggregateFunction or FoldFunction. More details here[1].

Best, Hequn


On Sat, Jul 14, 2018 at 9:24 PM, Soheil Pourbafrani <[hidden email]> wrote:
Hi, I have a keyed datastream in the type of Tuple2<Long, byte[]>. I want to reduce it and merge all of the byte[] for a key. (the first filed (Long) is the key). So I need reduce function return the type Tuple2<Long, ArrayList<byte[]>>, but reduce function didn't allow that! How can I do such job in Flink?