highestMax() function
The highestMax()
function selects the maximum record from each table in the input stream and returns the top n
records. It outputs a single aggregated table containing n
records.
*Function type: Selector, Aggregate*
highestMax(
n:10,
column: "_value",
groupColumns: []
)
Empty tables
highestMax()
drops empty tables.
Parameters
n
Number of records to return.
*Data type: Integer*
column
Column by which to sort. Default is "_value"
.
*Data type: String*
groupColumns
The columns on which to group before performing the aggregation. Default is []
.
*Data type: Array of strings*
Examples
from(bucket:"example-bucket")
|> range(start:-1h)
|> filter(fn: (r) =>
r._measurement == "mem" and
r._field == "used_percent"
)
|> highestMax(n:10, groupColumns: ["host"])
Function definition
// _sortLimit is a helper function, which sorts and limits a table.
_sortLimit = (n, desc, columns=["_value"], tables=<-) =>
tables
|> sort(columns:columns, desc:desc)
|> limit(n:n)
// _highestOrLowest is a helper function which reduces all groups into a single
// group by specific tags and a reducer function. It then selects the highest or
// lowest records based on the column and the _sortLimit function.
// The default reducer assumes no reducing needs to be performed.
_highestOrLowest = (n, _sortLimit, reducer, column="_value", groupColumns=[], tables=<-) =>
tables
|> group(columns:groupColumns)
|> reducer()
|> group(columns:[])
|> _sortLimit(n:n, columns:[column])
highestMax = (n, column="_value", groupColumns=[], tables=<-) =>
tables
|> _highestOrLowest(
n:n,
column:column,
groupColumns:groupColumns,
reducer: (tables=<-) => tables |> max(column:column),
_sortLimit: top
)