highestCurrent() function
The highestCurrent()
function selects the last record of 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
highestCurrent(
n:10,
column: "_value",
groupColumns: []
)
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"
)
|> highestCurrent(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])
highestCurrent = (n, column="_value", groupColumns=[], tables=<-) =>
tables
|> _highestOrLowest(
n:n,
column:column,
groupColumns:groupColumns,
reducer: (tables=<-) => tables |> last(column:column),
_sortLimit: top,
)
Bug Reports and Feedback
Thank you for being willing to help test InfluxDB v2.0 alpha! Feedback and bug reports are welcome and encouraged both for InfluxDB and this documentation. Submit feedback using one of the following methods:
- Post in the InfluxData Community
- In the InfluxDB UI, click Feedback in the left navigation bar.
- Submit documentation issues to the InfluxDB 2.0 documentation repository.
- Submit InfluxDB issues to the InfluxDB repository.