You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Michał Rudko <mi...@getindata.com> on 2021/08/31 15:38:43 UTC

Session windows - how to get the last value from a window using FlinkSQL?

Hi,

I had trouble to find in the documentation of Flink/Ververica which
aggregations or analytical functions are supported within such SESSION
WINDOW. In particular - I would like to capture the last value of a certain
field. Is it possible?
I have included all the details in StackOverflow here
<https://stackoverflow.com/questions/68925461/how-to-get-last-value-in-a-session-window-in-flinksql>
-
so far without any answers.
In case it's not doable, any workarounds would be appreciated.

Thanks!

-- 

Pozdrawiam / Regards


Michał Rudko

Big Data Consultant | Getindata
[image: Getindata]
M: +48 697 712 120
E: michal.rudko@getindata.com
A: Puławska 39/20, Warsaw
Website <https://getindata.com/> - Blog <https://medium.com/getindata-blog>
 - Twitter <https://twitter.com/getindata>

Re: Session windows - how to get the last value from a window using FlinkSQL?

Posted by JING ZHANG <be...@gmail.com>.
Hi,
The exception in the above StackOverflow link because built-in last_value
agg function class ( `LastValueAggFunction`) does not support merge method.
While you use session window aggregate, `merge` is required when merge two
windows into one session window.
[image: image.png]
*You could define your UserDefined AggregateFunction [1] to walk around.
Please implement `merge` method in the UserDefined Aggregate Function if
they would be used in Session Window. *

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

Best regards,
JING ZHANG


Caizhi Weng <ts...@gmail.com> 于2021年9月1日周三 上午10:42写道:

> Hi!
>
> Yes it is, by using the last_value() aggregate function. For example
>
> SELECT last_value(v) FROM T GROUP BY k, session(ts, interval '1' minute)
>
> Michał Rudko <mi...@getindata.com> 于2021年8月31日周二 下午11:40写道:
>
>> Hi,
>>
>> I had trouble to find in the documentation of Flink/Ververica which
>> aggregations or analytical functions are supported within such SESSION
>> WINDOW. In particular - I would like to capture the last value of a
>> certain field. Is it possible?
>> I have included all the details in StackOverflow here
>> <https://stackoverflow.com/questions/68925461/how-to-get-last-value-in-a-session-window-in-flinksql> -
>> so far without any answers.
>> In case it's not doable, any workarounds would be appreciated.
>>
>> Thanks!
>>
>> --
>>
>> Pozdrawiam / Regards
>>
>>
>> Michał Rudko
>>
>> Big Data Consultant | Getindata
>> [image: Getindata]
>> M: +48 697 712 120
>> E: michal.rudko@getindata.com
>> A: Puławska 39/20, Warsaw
>> Website <https://getindata.com/> - Blog
>> <https://medium.com/getindata-blog> - Twitter
>> <https://twitter.com/getindata>
>>
>

Re: Session windows - how to get the last value from a window using FlinkSQL?

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

Yes it is, by using the last_value() aggregate function. For example

SELECT last_value(v) FROM T GROUP BY k, session(ts, interval '1' minute)

Michał Rudko <mi...@getindata.com> 于2021年8月31日周二 下午11:40写道:

> Hi,
>
> I had trouble to find in the documentation of Flink/Ververica which
> aggregations or analytical functions are supported within such SESSION
> WINDOW. In particular - I would like to capture the last value of a
> certain field. Is it possible?
> I have included all the details in StackOverflow here
> <https://stackoverflow.com/questions/68925461/how-to-get-last-value-in-a-session-window-in-flinksql> -
> so far without any answers.
> In case it's not doable, any workarounds would be appreciated.
>
> Thanks!
>
> --
>
> Pozdrawiam / Regards
>
>
> Michał Rudko
>
> Big Data Consultant | Getindata
> [image: Getindata]
> M: +48 697 712 120
> E: michal.rudko@getindata.com
> A: Puławska 39/20, Warsaw
> Website <https://getindata.com/> - Blog
> <https://medium.com/getindata-blog> - Twitter
> <https://twitter.com/getindata>
>