In KSQL, How to select max window record after win

2019-08-04 08:50发布

问题:

ksql> CREATE TABLE HOPPING_TABLE AS SELECT ID, WINDOWSTART() AS WINSTART, COUNT(*) AS CNT FROM MY_STREAM HOPPING WINDOW (SIZE 30 DAYS, ADVANCED BY 1 DAYS) GROUP BY ID;

ksql> SELECT ID, WINSTART, CNT FROM HOPPING_TABLE;

id                    winstart        cnt
-------------------------------------------

874163197805291909    1547164800000    23
874163197805291909    1547424000000    11
874163197805291909    1547510400000    26
874163197805291909    1547683200000    12

660071199310134801    1545868800000    6
660071199310134801    1546560000000    7
660071199310134801    1547251200000    3

Now, I just care about the cnt of window with max winstart value for each ID grouped, how to achieve that by KSQL then? Considering above example (2 IDs grouped), I hope a table can be generated from above HOPPING TABLE with the following records:

id                    winstart        cnt
-------------------------------------------

874163197805291909    1547683200000    12

660071199310134801    1547251200000    3
标签: ksql