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*

  1. highestMax(
  2. n:10,
  3. column: "_value",
  4. groupColumns: []
  5. )

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

  1. from(bucket:"example-bucket")
  2. |> range(start:-1h)
  3. |> filter(fn: (r) =>
  4. r._measurement == "mem" and
  5. r._field == "used_percent"
  6. )
  7. |> highestMax(n:10, groupColumns: ["host"])

Function definition

  1. // _sortLimit is a helper function, which sorts and limits a table.
  2. _sortLimit = (n, desc, columns=["_value"], tables=<-) =>
  3. tables
  4. |> sort(columns:columns, desc:desc)
  5. |> limit(n:n)
  6. // _highestOrLowest is a helper function which reduces all groups into a single
  7. // group by specific tags and a reducer function. It then selects the highest or
  8. // lowest records based on the column and the _sortLimit function.
  9. // The default reducer assumes no reducing needs to be performed.
  10. _highestOrLowest = (n, _sortLimit, reducer, column="_value", groupColumns=[], tables=<-) =>
  11. tables
  12. |> group(columns:groupColumns)
  13. |> reducer()
  14. |> group(columns:[])
  15. |> _sortLimit(n:n, columns:[column])
  16. highestMax = (n, column="_value", groupColumns=[], tables=<-) =>
  17. tables
  18. |> _highestOrLowest(
  19. n:n,
  20. column:column,
  21. groupColumns:groupColumns,
  22. reducer: (tables=<-) => tables |> max(column:column),
  23. _sortLimit: top
  24. )