You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Ori Popowski <or...@gmail.com> on 2020/11/09 13:33:54 UTC

SQL aggregation functions inside the Table API

Hi,

Some functions only exist in the SQL interface and are missing from the
Table API. For example LAST_VALUE(expression) [1]

I still want to use this function in my aggregation, and I don't want to
implement a user-defined function. Can I combine an SQL expression inside
my Table API?

For example:

val table = tenv
      .fromDataStream(stream)
      .groupBy($"name")
      .select($"name", $"products".count(), $"LAST_VALUE(age)")

If not - how can I get the last value of a column inside an aggregation?

Thanks.

[1]
https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/functions/systemFunctions.html#aggregate-functions

Re: SQL aggregation functions inside the Table API

Posted by Ori Popowski <or...@gmail.com>.
Thanks


On Mon, Nov 9, 2020 at 4:50 PM Timo Walther <tw...@apache.org> wrote:

> Hi Ori,
>
> we might support SQL expressions soon in Table API. However, we might
> not support aggregate functions immediately. I would recommend to use
> `sqlQuery` for now.
>
> The following is supported:
>
> val table = tenv.fromDataStream(stream)
>
> val newTable = tenv.sqlQuery(s"SELECT ... FROM $table")
>
> So switching between Table API and SQL can be done fluently.
>
> I hope this helps.
>
> Regards,
> Timo
>
>
> On 09.11.20 14:33, Ori Popowski wrote:
> > Hi,
> >
> > Some functions only exist in the SQL interface and are missing from the
> > Table API. For example LAST_VALUE(expression) [1]
> >
> > I still want to use this function in my aggregation, and I don't want to
> > implement a user-defined function. Can I combine an SQL expression
> > inside my Table API?
> >
> > For example:
> >
> > val table = tenv
> >        .fromDataStream(stream)
> >        .groupBy($"name")
> >        .select($"name", $"products".count(), $"LAST_VALUE(age)")
> >
> > If not - how can I get the last value of a column inside an aggregation?
> >
> > Thanks.
> >
> > [1]
> >
> https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/functions/systemFunctions.html#aggregate-functions
> > <
> https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/functions/systemFunctions.html#aggregate-functions
> >
>
>

Re: SQL aggregation functions inside the Table API

Posted by Timo Walther <tw...@apache.org>.
Hi Ori,

we might support SQL expressions soon in Table API. However, we might 
not support aggregate functions immediately. I would recommend to use 
`sqlQuery` for now.

The following is supported:

val table = tenv.fromDataStream(stream)

val newTable = tenv.sqlQuery(s"SELECT ... FROM $table")

So switching between Table API and SQL can be done fluently.

I hope this helps.

Regards,
Timo


On 09.11.20 14:33, Ori Popowski wrote:
> Hi,
> 
> Some functions only exist in the SQL interface and are missing from the 
> Table API. For example LAST_VALUE(expression) [1]
> 
> I still want to use this function in my aggregation, and I don't want to 
> implement a user-defined function. Can I combine an SQL expression 
> inside my Table API?
> 
> For example:
> 
> val table = tenv
>        .fromDataStream(stream)
>        .groupBy($"name")
>        .select($"name", $"products".count(), $"LAST_VALUE(age)")
> 
> If not - how can I get the last value of a column inside an aggregation?
> 
> Thanks.
> 
> [1] 
> https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/functions/systemFunctions.html#aggregate-functions 
> <https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/functions/systemFunctions.html#aggregate-functions>