You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Soheil Pourbafrani <so...@gmail.com> on 2018/04/27 15:08:58 UTC

Flink flatMap to pass a tuple and get multiple tuple

Hi, I want to use flatMap to pass to function namely 'parse' a tuple and it
will return multiple tuple, that each should be a record in datastream
object.

Something like this:

DataStream<Tuple2<Integer,Long>> res = stream.flatMap(new
FlatMapFunction<tuple3<int, int, int>, Tuple2<Integer,Long>>() {

    @Override
    public void flatMap(Tuple3<int, int, int> t,
Collector<Tuple2<Integer,Long>> collector) throws Exception {

        collector.collect(parse(t.f_3));
    }
});


that parse will return for example 6 tuples2 and I want them inserted into
res datastream.

Re: Flink flatMap to pass a tuple and get multiple tuple

Posted by TechnoMage <ml...@technomage.com>.
Any itterable of Tuples will work for a for loop: List, Set, etc.

Michael

> On Apr 27, 2018, at 10:47 AM, Soheil Pourbafrani <so...@gmail.com> wrote:
> 
> Thanks, what did you consider the return type of parse method? Arraylist of tuples?
> 
> On Friday, April 27, 2018, TechnoMage <mlatta@technomage.com <ma...@technomage.com>> wrote:
> > it would look more like:
> > for (Tuple2<> t2 : parse(t.f3) {
> > collector.collect(t2);
> > }
> > Michael
> >
> > On Apr 27, 2018, at 9:08 AM, Soheil Pourbafrani <soheil.ir08@gmail.com <ma...@gmail.com>> wrote:
> > Hi, I want to use flatMap to pass to function namely 'parse' a tuple and it will return multiple tuple, that each should be a record in datastream object.
> > Something like this:
> >
> > DataStream<Tuple2<Integer,Long>> res = stream.flatMap(new FlatMapFunction<tuple3<int, int, int>, Tuple2<Integer,Long>>() {
> >
> > @Override
> > public void flatMap(Tuple3<int, int, int> t, Collector<Tuple2<Integer,Long>> collector) throws Exception {
> >
> > collector.collect(parse(t.f_3));
> > }
> > });
> >
> > that parse will return for example 6 tuples2 and I want them inserted into res datastream.
> >


Re: Flink flatMap to pass a tuple and get multiple tuple

Posted by TechnoMage <ml...@technomage.com>.
it would look more like:

for (Tuple2<> t2 : parse(t.f3) {
	collector.collect(t2);
}

Michael

> On Apr 27, 2018, at 9:08 AM, Soheil Pourbafrani <so...@gmail.com> wrote:
> 
> Hi, I want to use flatMap to pass to function namely 'parse' a tuple and it will return multiple tuple, that each should be a record in datastream object.
> 
> Something like this:
> 
> DataStream<Tuple2<Integer,Long>> res = stream.flatMap(new FlatMapFunction<tuple3<int, int, int>, Tuple2<Integer,Long>>() {
> 
>     @Override
>     public void flatMap(Tuple3<int, int, int> t, Collector<Tuple2<Integer,Long>> collector) throws Exception {
>         
>         collector.collect(parse(t.f_3));
>     }
> });
> 
> that parse will return for example 6 tuples2 and I want them inserted into res datastream.