PARTITION BY clause to fetch top N rows per group.
Syntax
ranking_function_clause is:
rank cannot be included in column_list.You must follow the pattern exactly to construct a valid Top-N query.
Example
Create a table
Insert data
Run a top-N query
Converting StreamOverWindow to StreamGroupTopN
Given the following table:v1 and order by v2:
StreamOverWindow. This is a streaming operator that maintains the state of the window and computes the row number for each row in the partition.
This can be quite expensive, especially if the partition is large.
If you only need the top N rows from each partition, you can use the StreamGroupTopN operator instead.
This can be done by simply adding a WHERE clause to the query, and applying it to the row column (r in the above example).
You can view the following query as an example, which maintains top 10 rows for each partition:
StreamGroupTopN operator is much more efficient than the StreamOverWindow operator.