Return-Path: X-Original-To: apmail-flink-user-archive@minotaur.apache.org Delivered-To: apmail-flink-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0F64818F21 for ; Fri, 21 Aug 2015 13:45:11 +0000 (UTC) Received: (qmail 32504 invoked by uid 500); 21 Aug 2015 13:45:10 -0000 Delivered-To: apmail-flink-user-archive@flink.apache.org Received: (qmail 32430 invoked by uid 500); 21 Aug 2015 13:45:10 -0000 Mailing-List: contact user-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@flink.apache.org Delivered-To: mailing list user@flink.apache.org Received: (qmail 32420 invoked by uid 99); 21 Aug 2015 13:45:10 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Aug 2015 13:45:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 08DEADFD27 for ; Fri, 21 Aug 2015 13:45:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.237 X-Spam-Level: *** X-Spam-Status: No, score=3.237 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.764, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id JGm4EFzY7vg4 for ; Fri, 21 Aug 2015 13:45:02 +0000 (UTC) Received: from smail.rz.tu-ilmenau.de (smail.rz.tu-ilmenau.de [141.24.4.149]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 9ACE72100B for ; Fri, 21 Aug 2015 13:45:01 +0000 (UTC) Received: from [192.168.110.159] (wl-r1-3.rz.tu-ilmenau.de [141.24.11.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 370015EFAB for ; Fri, 21 Aug 2015 15:45:00 +0200 (CEST) Message-ID: <55D72B5B.7050702@tu-ilmenau.de> Date: Fri, 21 Aug 2015 15:44:59 +0200 From: Philipp Goetze User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: user@flink.apache.org Subject: Re: Custom Aggregate - Example References: <55D71EBF.4080006@tu-ilmenau.de> In-Reply-To: Content-Type: multipart/alternative; boundary="------------020002080100070000050600" This is a multi-part message in MIME format. --------------020002080100070000050600 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thank you Aljoscha, I guessed that I should use the reduce method. However, I do not look for window aggregations. I want to do this on a grouped stream. The problem is we work with Lists instead of tuples and thus we can not use the pre-implemented aggregates. So the idea is to call it like that: val aggr = source.groupBy(_(0)).reduce(new customReducer(1)) And this is the signature of the class: class customReducer(field: Int) extends RichReduceFunction[List[Any]] How do I have to implement this class now, so that it is working correctly even with parallelism > 1? I hope you understand what I try to do. =) Kind Regards, Philipp On 21.08.2015 15:28, Aljoscha Krettek wrote: > Hi, > with the current API this should do what you are after: > > val input = ... > val result = input > .window(...) > .groupBy(...) > .reduceWindow( /* your reduce function */ ) > > With the reduce function you should be able to implement any custom > aggregations. You can also use foldWindow() if you want to do a > functional fold over the window. > > I hope this helps. > > Cheers, > Aljoscha > > On Fri, 21 Aug 2015 at 14:51 Philipp Goetze > > > wrote: > > Hello community, > > how do I define a custom aggregate function in Flink Streaming > (Scala)? > Could you please provide an example on how to do that? > > Thank you and best regards, > Philipp > --------------020002080100070000050600 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Thank you Aljoscha,

I guessed that I should use the reduce method. However, I do not look for window aggregations. I want to do this on a grouped stream.

The problem is we work with Lists instead of tuples and thus we can not use the pre-implemented aggregates.

So the idea is to call it like that:
val aggr = source.groupBy(_(0)).reduce(new customReducer(1))
And this is the signature of the class:
class customReducer(field: Int) extends RichReduceFunction[List[Any]]

How do I have to implement this class now, so that it is working correctly even with parallelism > 1?

I hope you understand what I try to do. =)

Kind Regards,
Philipp


On 21.08.2015 15:28, Aljoscha Krettek wrote:
Hi,
with the current API this should do what you are after:

val input = ...
 
val result = input
  .window(...)
  .groupBy(...)
  .reduceWindow( /* your reduce function */ )

With the reduce function you should be able to implement any custom aggregations. You can also use foldWindow() if you want to do a functional fold over the window.

I hope this helps.

Cheers,
Aljoscha 

On Fri, 21 Aug 2015 at 14:51 Philipp Goetze <philipp.goetze@tu-ilmenau.de> wrote:
Hello community,

how do I define a custom aggregate function in Flink Streaming (Scala)?
Could you please provide an example on how to do that?

Thank you and best regards,
Philipp

--------------020002080100070000050600--