From 76dba6db644782cf372ffb80e539fbcc2a17ae4e Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 9 Aug 2019 14:42:32 -0600 Subject: [PATCH 1/2] added flux tail function, resolves #374 --- .../built-in/transformations/limit.md | 21 ++++---- .../built-in/transformations/tail.md | 51 +++++++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 content/v2.0/reference/flux/functions/built-in/transformations/tail.md diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/limit.md b/content/v2.0/reference/flux/functions/built-in/transformations/limit.md index 8a216e38f..5c70399c7 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/limit.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/limit.md @@ -1,6 +1,6 @@ --- title: limit() function -description: The `limit()` function limits the number of records in output tables to a fixed number (n). +description: The `limit()` function limits records in each output table to the first `n` records. aliases: - /v2.0/reference/flux/functions/transformations/limit menu: @@ -8,15 +8,17 @@ menu: name: limit parent: built-in-transformations weight: 401 +related: + - /v2.0/reference/flux/functions/built-in/transformations/tail/ + - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-limit-and-slimit-clauses, InfluxQL LIMIT --- -The `limit()` function limits the number of records in output tables to a fixed number ([`n`](#n)). -One output table is produced for each input table. -Each output table contains the first `n` records after the first `offset` records of the input table. -If the input table has less than `offset + n` records, all records except the first `offset` ones are output. +The `limit()` function limits records in each output table to the first [`n`](#n) records. +The function produces one output table for each input table. +Each output table contains the first `n` records after the [`offset`](#offset). +If the input table has less than `offset + n` records, `limit()` outputs all records after the `offset`. -_**Function type:** Filter_ -_**Output data type:** Object_ +_**Function type:** Filter_ ```js limit(n:10, offset: 0) @@ -41,8 +43,3 @@ from(bucket:"example-bucket") |> range(start:-1h) |> limit(n:10, offset: 1) ``` - -
- -##### Related InfluxQL functions and statements: -[LIMIT](https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-limit-and-slimit-clauses) diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/tail.md b/content/v2.0/reference/flux/functions/built-in/transformations/tail.md new file mode 100644 index 000000000..8f3c65246 --- /dev/null +++ b/content/v2.0/reference/flux/functions/built-in/transformations/tail.md @@ -0,0 +1,51 @@ +--- +title: tail() function +description: The `tail()` function limits records in each output table to the last `n` records. +menu: + v2_0_ref: + name: tail + parent: built-in-transformations +weight: 401 +related: + - /v2.0/reference/flux/functions/built-in/transformations/limit/ +--- + +The `tail()` function limits records in each output table to the last [`n`](#n) records. +The function produces one output table for each input table. +Each output table contains the last `n` records before the [`offset`](#offset). +If the input table has less than `offset + n` records, `tail()` outputs all records before the `offset`. + +_**Function type:** Filter_ + +```js +tail(n:10, offset: 0) +``` + +## Parameters + +### n +The maximum number of records to output. + +_**Data type:** Integer_ + +### offset +The number of records to skip at the end of a table table before limiting to `n`. +Defaults to `0`. + +_**Data type:** Integer_ + +## Examples + +##### Output the last ten records in each table +```js +from(bucket:"example-bucket") + |> range(start:-1h) + |> tail(n:10) +``` + +##### Output the last ten records in each table +```js +from(bucket:"example-bucket") + |> range(start:-1h) + |> tail(n:5, offset: 1) +``` From 92c5413e96297aea05f17c41e50df675e562c096 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 9 Aug 2019 14:47:25 -0600 Subject: [PATCH 2/2] minor updates to limit and tail function docs --- .../functions/built-in/transformations/limit.md | 13 +++++++++---- .../functions/built-in/transformations/tail.md | 16 ++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/limit.md b/content/v2.0/reference/flux/functions/built-in/transformations/limit.md index 5c70399c7..b0e3b0741 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/limit.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/limit.md @@ -1,6 +1,6 @@ --- title: limit() function -description: The `limit()` function limits records in each output table to the first `n` records. +description: The `limit()` function limits each output table to the first `n` records. aliases: - /v2.0/reference/flux/functions/transformations/limit menu: @@ -13,7 +13,7 @@ related: - https://docs.influxdata.com/influxdb/latest/query_language/data_exploration/#the-limit-and-slimit-clauses, InfluxQL LIMIT --- -The `limit()` function limits records in each output table to the first [`n`](#n) records. +The `limit()` function limits each output table to the first [`n`](#n) records. The function produces one output table for each input table. Each output table contains the first `n` records after the [`offset`](#offset). If the input table has less than `offset + n` records, `limit()` outputs all records after the `offset`. @@ -21,7 +21,10 @@ If the input table has less than `offset + n` records, `limit()` outputs all rec _**Function type:** Filter_ ```js -limit(n:10, offset: 0) +limit( + n:10, + offset: 0 +) ``` ## Parameters @@ -38,8 +41,10 @@ Defaults to `0`. _**Data type:** Integer_ ## Examples + +##### Output the first ten records in each table ```js from(bucket:"example-bucket") |> range(start:-1h) - |> limit(n:10, offset: 1) + |> limit(n:10) ``` diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/tail.md b/content/v2.0/reference/flux/functions/built-in/transformations/tail.md index 8f3c65246..330d90a68 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/tail.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/tail.md @@ -1,6 +1,6 @@ --- title: tail() function -description: The `tail()` function limits records in each output table to the last `n` records. +description: The `tail()` function limits each output table to the last `n` records. menu: v2_0_ref: name: tail @@ -10,7 +10,7 @@ related: - /v2.0/reference/flux/functions/built-in/transformations/limit/ --- -The `tail()` function limits records in each output table to the last [`n`](#n) records. +The `tail()` function limits each output table to the last [`n`](#n) records. The function produces one output table for each input table. Each output table contains the last `n` records before the [`offset`](#offset). If the input table has less than `offset + n` records, `tail()` outputs all records before the `offset`. @@ -18,7 +18,10 @@ If the input table has less than `offset + n` records, `tail()` outputs all reco _**Function type:** Filter_ ```js -tail(n:10, offset: 0) +tail( + n:10, + offset: 0 +) ``` ## Parameters @@ -42,10 +45,3 @@ from(bucket:"example-bucket") |> range(start:-1h) |> tail(n:10) ``` - -##### Output the last ten records in each table -```js -from(bucket:"example-bucket") - |> range(start:-1h) - |> tail(n:5, offset: 1) -```