Storm Trident 'average aggregator

Posted by E Shindler on Stack Overflow See other posts from Stack Overflow or by E Shindler
Published on 2013-10-29T21:50:56Z Indexed on 2013/10/29 21:54 UTC
Read the original article Hit count: 264

Filed under:
|

I am a newbie to Trident and I'm looking to create an 'Average' aggregator similar to 'Sum(), but for 'Average'.The following does not work:

       public class Average implements CombinerAggregator<Long>.......{

       public Long init(TridentTuple tuple)
       {
       (Long)tuple.getValue(0);
        }
        public Long Combine(long val1,long val2){
        return val1+val2/2;
        }
        public Long zero(){
        return 0L;
         }
       }

It may not be exactly syntactically correct, but that's the idea. Please help if you can. Given 2 tuples with values [2,4,1] and [2,2,5] and fields 'a','b' and 'c' and doing an average on field 'b' should return '3'. I'm not entirely sure how init() and zero() work.

Thank you so much for your help in advance.

Eli

© Stack Overflow or respective owner

Related posts about storm

Related posts about trident