topkw
This page explains how to use the topkw aggregation function in APL.
topkw returns an estimated top k list of string values weighted by an integer frequency when each row represents multiple observations.
Usage
Syntax
APL
Parameters
expr: The string field or expression to rank.k: The number of top values to return (maximum100,000).weight: An integer expression representing the frequency weight for each record. Records with a weight less than or equal to0are skipped. Records with anullweight are counted once (weight1).GroupingColumn(optional): A column to group the results by.
Returns
Returns one array column per group (named topkw_<expr> by default) containing up to k objects with the shape {"key": string, "count": int, "error": int}.
Use case examples
Top weighted HTTP methods
This example finds the most frequent HTTP method when each row carries a pre-aggregated count.
Query
APL
Output
| top_method | weighted_count |
|---|---|
| GET | 4 |