topk¶
Type of operation: Filter
Description¶
Selects all data for each of top k ranked groups. If no rank method is provided, a default one will be used. Default ranking method sorts groups by the first found numeric column which is not part of the grouping. Groups are sorted by all grouping keys if no such column is found. If no grouping is specified, the set of primary key columns will be used as the grouping.
Usage¶
topk k [ , rank ] [ , groupby ]
Argument |
Type |
Required |
Multiple |
---|---|---|---|
k |
int64 |
Required |
Only one |
rank |
expression |
Optional |
Only one |
groupby |
fieldref |
Optional |
Only one |
Accelerable¶
topk is never accelerable. A dataset that only uses accelerable verbs can be accelerated, making queries on the dataset respond faster.
Examples¶
topk 100
Select the top 100 groups using the default rank method: sorting by the first suitable numeric field, or by all the group identifiers when no suitable numeric field is found. Primary key columns are used here as default group identifiers.
topk 100, group_by(clusterUid, namespace)
Similar to the first example, but explicitly specifying the grouping
topk 100, max(memory_used)
Select the 100 groups with the highest memory usage in the query window.
topk 1, group_by()
This topk operates on empty grouping, where all rows belong to the same group, and hence all rows will be selected
topk 100, max(memory_used), group_by(clusterUid, namespace)
Rank the maximum memory_used
during the query window for each Kubernetes namespace, and select the highest 100 namespaces.