3.1 KiB
title | description | aliases | menu | weight | flux/v0.x/tags | related | introduced | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tail() function | The `tail()` function limits each output table to the last `n` records. |
|
|
102 |
|
|
0.39.0 |
The tail()
function limits each output table to the last n
records.
The function produces one output table for each input table.
Each output table contains the last n
records before the offset
.
If the input table has less than offset + n
records, tail()
outputs all records before the offset
.
tail(n: 10, offset: 0)
Parameters
n
({{< req >}}) The maximum number of records to output.
offset
The number of records to skip at the end of a table table before limiting to n
.
Default is 0
.
tables
Input data.
Default is piped-forward data (<-
).
Examples
{{% flux/sample-example-intro %}}
- Output the last three rows in each input table
- Output the last three rows before the last row in each input table
Output the last three rows in each input table
import "sampledata"
sampledata.int()
|> tail(n: 3)
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "int" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:30Z | t1 | 17 |
2021-01-01T00:00:40Z | t1 | 15 |
2021-01-01T00:00:50Z | t1 | 4 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:30Z | t2 | 19 |
2021-01-01T00:00:40Z | t2 | 13 |
2021-01-01T00:00:50Z | t2 | 1 |
{{% /flex-content %}} | ||
{{< /flex >}} | ||
{{% /expand %}} | ||
{{< /expand-wrapper >}} |
Output the last three rows before the last row in each input table
import "sampledata"
sampledata.int()
|> tail(n: 3, offset: 1)
{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}
Input data
{{% flux/sample "int" %}}
{{% /flex-content %}} {{% flex-content %}}
Output data
_time | tag | _value |
---|---|---|
2021-01-01T00:00:20Z | t1 | 7 |
2021-01-01T00:00:30Z | t1 | 17 |
2021-01-01T00:00:40Z | t1 | 15 |
_time | tag | _value |
---|---|---|
2021-01-01T00:00:20Z | t2 | -3 |
2021-01-01T00:00:30Z | t2 | 19 |
2021-01-01T00:00:40Z | t2 | 13 |
{{% /flex-content %}} | ||
{{< /flex >}} | ||
{{% /expand %}} | ||
{{< /expand-wrapper >}} |