You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Pouria Pirzadeh <po...@gmail.com> on 2022/01/27 22:48:31 UTC

Aggregation support in the Table API

I am using the Table api in Java to write queries with
grouping/aggregation.
The aggregations may use built-in functions or user defined aggregate
functions. Therefore I am using the aggregate() method on a
WindowGroupedTable.

table.window(...)
     .groupBy(...)
     .aggregate(Expressions.call("someUDAF", $("a")).as("res"))
     .select(...);

Above works fine for one aggregation per window/group; However I can not
find a way to do multiple aggregations on such a group using the table API.
WindowGroupedTable class has no method as aggregate(Expression...
aggregateFunction) which can take multiple aggregates.

Any suggestions on how multiple aggregations, with UDAFs, could be done via
table API?

Re: Aggregation support in the Table API

Posted by Caizhi Weng <ts...@gmail.com>.
Hi!

You can directly use .select() to call an aggregate function (either
built-in or user-defined). See [1] for an example on how to use call()
expression to call an user-defined aggregate function.

[1]
https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/functions/udfs/#aggregate-functions

Pouria Pirzadeh <po...@gmail.com> 于2022年1月28日周五 06:48写道:

> I am using the Table api in Java to write queries with
> grouping/aggregation.
> The aggregations may use built-in functions or user defined aggregate
> functions. Therefore I am using the aggregate() method on a
> WindowGroupedTable.
>
> table.window(...)
>      .groupBy(...)
>      .aggregate(Expressions.call("someUDAF", $("a")).as("res"))
>      .select(...);
>
> Above works fine for one aggregation per window/group; However I can not
> find a way to do multiple aggregations on such a group using the table API.
> WindowGroupedTable class has no method as aggregate(Expression...
> aggregateFunction) which can take multiple aggregates.
>
> Any suggestions on how multiple aggregations, with UDAFs, could be done
> via table API?
>
>
>