Window Top-N
Window Top-N is a special Top-N which returns the N smallest or largest values for each window and other partitioned keys.
For streaming queries, unlike regular Top-N on continuous tables, window Top-N does not emit intermediate results but only a final result, the total top N records at the end of the window. Moreover, window Top-N purges all intermediate state when no longer needed. Therefore, window Top-N queries have better performance if users don’t need results updated per record. Usually, Window Top-N is used with directly. Besides, Window Top-N could be used with other operations based on Windowing TVF, such as , Window TopN and .
The following shows the syntax of the Window Top-N statement:
The following example shows how to calculate Top 3 suppliers who have the highest sales for every tumbling 10 minutes window.
Window Top-N follows after Windowing TVF
The following example shows how to calculate Top 3 items which have the highest price for every tumbling 10 minutes window.
Note: in order to better understand the behavior of windowing, we simplify the displaying of timestamp values to not show the trailing zeros, e.g. should be displayed as 2020-04-15 08:05:00.000
in Flink SQL Client if the type is TIMESTAMP(3)
.