You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Punit Naik <na...@gmail.com> on 2016/04/29 12:29:04 UTC

Count on grouped keys

I have a dataset which has maps. I have performed a groupBy on a key and I
want to count all the elements in a particular group. How do I do this?

-- 
Thank You

Regards

Punit Naik

Re: Count on grouped keys

Posted by Punit Naik <na...@gmail.com>.
Yeah no problem. Its not an optimised solution but I think it gives enough
understanding of how reduceGroup works.
On 29-Apr-2016 5:17 PM, "Stefano Baghino" <st...@radicalbit.io>
wrote:

> Thanks for sharing the solution, Punit.
>
> On Fri, Apr 29, 2016 at 1:40 PM, Punit Naik <na...@gmail.com>
> wrote:
>
>> Anyways, I managed to do it. you should attach the following code block
>> to your groupBy
>> .reduceGroup {
>>       (in, out: org.apache.flink.util.Collector[(Map[String,String],
>> Int)]) => // Map[String,String] is the data type I want to output along
>> with the count as Int in a Tuple
>>         var v:Int = 0;
>>         var k:Map[String,String]=Map()
>>         for (t <- in) {
>>           v+=1;
>>           k=t
>>         }
>>         out.collect((k,v))
>>
>> On Fri, Apr 29, 2016 at 3:59 PM, Punit Naik <na...@gmail.com>
>> wrote:
>>
>>> I have a dataset which has maps. I have performed a groupBy on a key and
>>> I want to count all the elements in a particular group. How do I do this?
>>>
>>> --
>>> Thank You
>>>
>>> Regards
>>>
>>> Punit Naik
>>>
>>
>>
>>
>> --
>> Thank You
>>
>> Regards
>>
>> Punit Naik
>>
>
>
>
> --
> BR,
> Stefano Baghino
>
> Software Engineer @ Radicalbit
>

Re: Count on grouped keys

Posted by Stefano Baghino <st...@radicalbit.io>.
Thanks for sharing the solution, Punit.

On Fri, Apr 29, 2016 at 1:40 PM, Punit Naik <na...@gmail.com> wrote:

> Anyways, I managed to do it. you should attach the following code block to
> your groupBy
> .reduceGroup {
>       (in, out: org.apache.flink.util.Collector[(Map[String,String],
> Int)]) => // Map[String,String] is the data type I want to output along
> with the count as Int in a Tuple
>         var v:Int = 0;
>         var k:Map[String,String]=Map()
>         for (t <- in) {
>           v+=1;
>           k=t
>         }
>         out.collect((k,v))
>
> On Fri, Apr 29, 2016 at 3:59 PM, Punit Naik <na...@gmail.com>
> wrote:
>
>> I have a dataset which has maps. I have performed a groupBy on a key and
>> I want to count all the elements in a particular group. How do I do this?
>>
>> --
>> Thank You
>>
>> Regards
>>
>> Punit Naik
>>
>
>
>
> --
> Thank You
>
> Regards
>
> Punit Naik
>



-- 
BR,
Stefano Baghino

Software Engineer @ Radicalbit

Re: Count on grouped keys

Posted by Punit Naik <na...@gmail.com>.
Anyways, I managed to do it. you should attach the following code block to
your groupBy
.reduceGroup {
      (in, out: org.apache.flink.util.Collector[(Map[String,String], Int)])
=> // Map[String,String] is the data type I want to output along with the
count as Int in a Tuple
        var v:Int = 0;
        var k:Map[String,String]=Map()
        for (t <- in) {
          v+=1;
          k=t
        }
        out.collect((k,v))

On Fri, Apr 29, 2016 at 3:59 PM, Punit Naik <na...@gmail.com> wrote:

> I have a dataset which has maps. I have performed a groupBy on a key and I
> want to count all the elements in a particular group. How do I do this?
>
> --
> Thank You
>
> Regards
>
> Punit Naik
>



-- 
Thank You

Regards

Punit Naik