topk¶
Type of operation: Filter
Description¶
Selects all data for each of the top k ranked groups. When multiple groups get equivalent result from the scoring method, they will be ordered by the grouping keys to break ties.
If no scoring method is provided, a default ordering will be used. Default ordering sorts groups by the first numeric column which is not part of the grouping. If no such column is found, groups are sorted by all grouping keys.
Group ranks are exposed as the _c_rank
field.
Usage¶
topk k, [ score ], [ groupby ]
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
k |
int64 |
no |
no |
none |
score |
expression |
yes |
no |
none |
groupby |
storable |
yes |
no |
column |
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 ordering method: sorting by the first suitable numeric field and all the group identifiers, or only 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.