From b1c174b91fc6b5b1a0d59dc234b87f592d14feff Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 24 Feb 2020 15:21:03 -0700 Subject: [PATCH 01/11] common query doc boilerplate --- content/v2.0/query-data/common-queries.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 content/v2.0/query-data/common-queries.md diff --git a/content/v2.0/query-data/common-queries.md b/content/v2.0/query-data/common-queries.md new file mode 100644 index 000000000..7153e3931 --- /dev/null +++ b/content/v2.0/query-data/common-queries.md @@ -0,0 +1,11 @@ +--- +title: Common queries +seotitle: Common Flux queries +description: > + placeholder +weight: 102 +menu: + v2_0: + parent: Query data +v2.0/tags: [query] +--- From edb079f27bc1e45370fd6381198c6074fd14f8e5 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 25 Feb 2020 09:43:08 -0700 Subject: [PATCH 02/11] WIP common flux queries --- content/v2.0/query-data/common-queries.md | 107 +++++++++++++++++++++- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/content/v2.0/query-data/common-queries.md b/content/v2.0/query-data/common-queries.md index 7153e3931..60fff6831 100644 --- a/content/v2.0/query-data/common-queries.md +++ b/content/v2.0/query-data/common-queries.md @@ -1,11 +1,112 @@ --- -title: Common queries -seotitle: Common Flux queries +title: Common Flux queries description: > placeholder -weight: 102 +weight: 103 menu: v2_0: parent: Query data + name: Common queries v2.0/tags: [query] --- + + +- SELECT-like commands +- Median +- Percentile +- Cumulative Sum +- Moving Average +- Increase +- Rate +- Delta +- Window +- First/Last +- Histogram +- Gap filling +- Last observation carried forward +- Last point + +## SELECT-like commands + +## Median + +##### Median as an aggregate +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggregateWindow(every: 5m, fn: median) +``` + +##### Median as a selector +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> median(method: "exact_selector") +``` + +## Percentile + +##### Percentile as an aggregate +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggregateWindow( + every: 5m, + fn: (tables=<-, column) => tables |> quantile(q: 0.99) + ) +``` + +##### Percentile as a selector +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> quantile(q: 0.99) +``` + +## Cumulative Sum + + +## Moving Average + + +## Increase + + +## Rate + + +## Delta + + +## Window + + +## First/Last + + +## Histogram + + +## Gap filling + + +## Last observation carried forward + + +## Last point From 26142a2499a264fbbba9971f7665b5378dd537d5 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 26 Feb 2020 13:51:10 -0700 Subject: [PATCH 03/11] WIP common queriers --- content/v2.0/query-data/common-queries.md | 52 +++++++++++++++++-- .../variables/common-variables.md | 2 +- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/content/v2.0/query-data/common-queries.md b/content/v2.0/query-data/common-queries.md index 60fff6831..de0bad895 100644 --- a/content/v2.0/query-data/common-queries.md +++ b/content/v2.0/query-data/common-queries.md @@ -80,18 +80,62 @@ from(bucket: "example-bucket") ``` ## Cumulative Sum - +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> cumulativeSum() +``` ## Moving Average - +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> movingAverage() +``` ## Increase - +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> increase() +``` ## Rate +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> derivative(unit: 1s, nonNegative: true) +``` +```js +import "experimental/aggregate" -## Delta +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggregate.rate(unit: 1s, every: 5m) +``` + +## Delta (state changes only) ## Window diff --git a/content/v2.0/visualize-data/variables/common-variables.md b/content/v2.0/visualize-data/variables/common-variables.md index 77d57e749..8338c1d9c 100644 --- a/content/v2.0/visualize-data/variables/common-variables.md +++ b/content/v2.0/visualize-data/variables/common-variables.md @@ -54,7 +54,7 @@ List all unique tag values for a specific tag in a specified bucket. The example below lists all unique values of the `host` tag. _**Flux package:** [InfluxDB v1](/v2.0/reference/flux/stdlib/influxdb-v1/)_ -_**Flux functions:** [v1.measurements()](/v2.0/reference/flux/stdlib/influxdb-v1/measurements/)_ +_**Flux functions:** [v1.tagValues()](/v2.0/reference/flux/stdlib/influxdb-v1/tagvalues/)_ ```js import "influxdata/influxdb/v1" From 879b4b1bf59fbae3ef32f00864f6c0068e4f2d90 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 2 Mar 2020 14:22:47 -0700 Subject: [PATCH 04/11] added guide for select- and where-like queries, related to #770 --- .../_index.md} | 60 ++++++++++++++++- .../query-data/common-queries/query-fields.md | 67 +++++++++++++++++++ content/v2.0/reference/glossary.md | 11 +++ 3 files changed, 135 insertions(+), 3 deletions(-) rename content/v2.0/query-data/{common-queries.md => common-queries/_index.md} (71%) create mode 100644 content/v2.0/query-data/common-queries/query-fields.md diff --git a/content/v2.0/query-data/common-queries.md b/content/v2.0/query-data/common-queries/_index.md similarity index 71% rename from content/v2.0/query-data/common-queries.md rename to content/v2.0/query-data/common-queries/_index.md index de0bad895..d5b152586 100644 --- a/content/v2.0/query-data/common-queries.md +++ b/content/v2.0/query-data/common-queries/_index.md @@ -28,6 +28,8 @@ v2.0/tags: [query] ## SELECT-like commands +Query fields from InfluxDB + ## Median ##### Median as an aggregate @@ -138,19 +140,71 @@ from(bucket: "example-bucket") ## Delta (state changes only) -## Window +## Window (time buckets) +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> window(every: 5m) +``` +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggreateWindow(every: 5m, fn: mean) +``` ## First/Last +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggreateWindow(every: 5m, fn: first) +``` +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-key" + ) + |> aggreateWindow(every: 5m, fn: last) +``` ## Histogram +Histogram docs + +```js + +``` ## Gap filling +Fill gaps in data + +```js + +``` -## Last observation carried forward +## Last observation carried forward (need) +```js + +``` -## Last point +## Last point (need) +```js + +``` diff --git a/content/v2.0/query-data/common-queries/query-fields.md b/content/v2.0/query-data/common-queries/query-fields.md new file mode 100644 index 000000000..26646ce40 --- /dev/null +++ b/content/v2.0/query-data/common-queries/query-fields.md @@ -0,0 +1,67 @@ +--- +title: Query fields and tags +seotitle: Query fields and tags in InfluxDB using Flux +description: > + Use the `filter()` function to query data based on fields, tags, or any other column value. + If familiar with InfluxQL or other SQL-like query languages, `filter()` performs + operations similar to the `SELECT` statement and `WHERE` clause. +weight: 201 +menu: + v2_0: + parent: Common queries +v2.0/tags: [query, select, where] +--- + +Use the [`filter()` function](/v2.0/reference/flux/stdlib/built-in/transformations/filter/) +to query data based on fields, tags, or any other column value. +If familiar with InfluxQL or other SQL-like query languages, `filter()` performs +operations similar to the `SELECT` statement and `WHERE` clause. + +## The filter() function +`filter()` has an `fn` parameter that expects a [predicate function](/v2.0/reference/glossary/#predicate-function), +an anonymous function comprised of one or more [predicate expressions](/v2.0/reference/glossary/#predicate-expression). +The predicate function evaluates each input row. +Rows that evaluate to `true` are **included** in the output data. +Rows that evaluate to `false` are **excluded** from the output data. + +```js +// ... + |> filter(fn: (r) => r._measurement == "example-measurement" ) +``` + +The `fn` predicate function requires an `r` argument, which represents each row +as `filter()` iterates over input data. +Key-value pairs in the row object represent columns and their values. +Use **dot notation** or **bracket notation** to reference specific column values in the predicate function. +Use [logical operators](/v2.0/reference/flux/language/operators/#logical-operators) +to chain multiple predicate expressions together. + +```js +// Row object +r = {foo: "bar", baz: "quz"} + +// Example predicate function +(r) => r.foo == "bar" and r["baz"] == "quz" + +// Evaluation results +(r) => true and true +``` + +## Filter by fields and tags +The combination of [`from()`](/v2.0/reference/flux/stdlib/built-in/inputs/from), +[`range()`](/v2.0/reference/flux/stdlib/built-in/transformations/range), +and `filter()` represent the most basic Flux query: + +1. Use `from()` to define your [bucket](/v2.0/reference/glossary/#bucket). +2. Use `range()` to limit query results by time. +3. Use `filter()` to identify what rows of data to output. + +```js +from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-field" and + r.tag == "example-tag" + ) +``` diff --git a/content/v2.0/reference/glossary.md b/content/v2.0/reference/glossary.md index 3ed8234cb..d530febcf 100644 --- a/content/v2.0/reference/glossary.md +++ b/content/v2.0/reference/glossary.md @@ -708,6 +708,17 @@ A predicate expression compares two values and returns `true` or `false` based o the relationship between the two values. A predicate expression is comprised of a left operand, a comparison operator, and a right operand. +### predicate function +A Flux predicate function is an anonymous function that returns `true` or `false` +based on one or more [predicate expressions](#predicate-expression). +Flux uses predicate functions primarily to filter records based on values of specific columns, +but predicate functions are used in other applications as well. + +###### Example predicate function +```js +(r) => r.foo == "bar" and r.baz != "quz" +``` + ### process A set of predetermined rules. From 4f5e816f0597f5efb1a55f5d94e1cddc54c884ef Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 2 Mar 2020 17:33:47 -0700 Subject: [PATCH 05/11] added median and percential/quantile guides, related to #770 --- .../query-data/common-queries/query-median.md | 94 ++++++++++++++++ .../common-queries/query-percentile.md | 102 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 content/v2.0/query-data/common-queries/query-median.md create mode 100644 content/v2.0/query-data/common-queries/query-percentile.md diff --git a/content/v2.0/query-data/common-queries/query-median.md b/content/v2.0/query-data/common-queries/query-median.md new file mode 100644 index 000000000..c9fc57880 --- /dev/null +++ b/content/v2.0/query-data/common-queries/query-median.md @@ -0,0 +1,94 @@ +--- +title: Query median values +seotitle: Query median values in Flux +description: > + placeholder +weight: 201 +menu: + v2_0: + parent: Common queries +v2.0/tags: [query, median] +related: + - /v2.0/query-data/common-queries/query-percentile/ +--- + +Use the [`median()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/) +to return all values within the `0.5` quantile (50th percentile) or the median value of input data. + +## Median calculation methods +Select from the following methods for calculating the median: + +##### estimate_tdigest +**(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) +to compute an accurate quantile estimate on large data sources. +Returns all values in the `0.5` quantile or 50th percentile. + +##### exact_mean +An aggregate method that takes the average of the two points closest to the quantile value. +Output tables consist of a single row containing the calculated median. + +##### exact_selector +A selector method that returns the data point for which at least 50% of points are less than. +Output tables consist of a single row containing the calculated median. + +{{% note %}} +#### Example data variable +To focus on using the `median()` function, the examples below use a `data` variable +which represents a base queried dataset. + +```js +data = from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-field" + ) +``` +{{% /note %}} + +## Query all values in the 50th percentile +Use the default method, `"estimate_tdigest"`, to return all rows in a table that +contain values in the 50th percentile of data in the table. + +```js +data + |> median() +``` + +## Query the average of values closest to the median +Use the `exact_mean` method to return a single row per input table containing the +average of the two values closest to the mathematical median of data in the table. + +```js +data + |> median(method: "exact_mean") +``` + +## Query the median value +Use the `exact_selector` method to return a single row per input table containing the +value that 50% of values in the table are less than. + +```js +data + |> median(method: "exact_selector") +``` + +## Use median with aggregateWindow() +[`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) +segments data into windows of time, aggregates data in each window into a single +point, then removes the time-based segmentation. +It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). + +`aggregateWindow()` expects a single point from each time window. +Use either the `exact_mean` or `exact_mode` median calculation method. + +To specify parameters of the aggregate function in `aggregateWindow()`, use the +[full function syntax](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function): + +```js +data + |> aggregateWindow( + every: 5m, + fn: (tables=<-, column) => tables |> median(method: "exact_selector") + ) +``` diff --git a/content/v2.0/query-data/common-queries/query-percentile.md b/content/v2.0/query-data/common-queries/query-percentile.md new file mode 100644 index 000000000..fd0c3e1d7 --- /dev/null +++ b/content/v2.0/query-data/common-queries/query-percentile.md @@ -0,0 +1,102 @@ +--- +title: Query percentile values +seotitle: Query percentile values in Flux +description: > + placeholder +weight: 201 +menu: + v2_0: + parent: Common queries +v2.0/tags: [query, percentile, quantile] +related: + - /v2.0/query-data/common-queries/query-median/ +--- + +Use the [`quantile()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/) +to return all values within the `q` quantile or percentile of input data. + +## Percentile versus quantile +Percentiles and quantiles are very similar, differing only in the number used to calculate return values. +A percentile is calculated using numbers between `0` and `100`. +A quantile is calculated using numbers between `0.0` and `1.0`. +For example, the **`0.5` quantile** is the same as the **50th percentile**. + +## Quantile calculation methods +Select from the following methods for calculating the quantile: + +##### estimate_tdigest +(Default) An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) +to compute an accurate quantile estimate on large data sources. +Returns all values in the `q` quantile. + +##### exact_mean +An aggregate method that takes the average of the two points closest to the quantile value. +Output tables consist of a single row containing the calculated quantile. + +##### exact_selector +A selector method that returns the data point for which at least `q` points are less than. +Output tables consist of a single row containing the calculated quantile. + +{{% note %}} +#### Example data variable +To focus on using the `quantile()` function, the examples below use a `data` variable +which represents a base queried dataset. + +```js +data = from(bucket: "example-bucket") + |> range(start: -1h) + |> filter(fn: (r) => + r._measurement == "example-measurement" and + r._field == "example-field" + ) +``` +{{% /note %}} + +## Query all values in the 50th percentile +Use the default method, `"estimate_tdigest"`, to return all rows in a table that +contain values in the 50th percentile of data in the table. + +```js +data + |> quantile(q: 0.99) +``` + +## Query the average of values closest to the quantile +Use the `exact_mean` method to return a single row per input table containing the +average of the two values closest to the mathematical quantile of data in the table. + +```js +data + |> quantile(q: 0.99, method: "exact_mean") +``` + +## Query the quantile value +Use the `exact_selector` method to return a single row per input table containing the +value that 50% of values in the table are less than. + +```js +data + |> quantile(q: 0.99, method: "exact_selector") +``` + +## Use quantile with aggregateWindow() +[`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) +segments data into windows of time, aggregates data in each window into a single +point, then removes the time-based segmentation. +It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). + +`aggregateWindow()` expects a single point from each time window. +Use either the `exact_mean` or `exact_mode` quantile calculation method. + +To specify parameters of the aggregate function in `aggregateWindow()`, use the +[full function syntax](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function): + +```js +data + |> aggregateWindow( + every: 5m, + fn: (tables=<-, column) => + tables + |> quantile(q: 0.99, method: "exact_selector") + ) +``` From af5f3be9d767f4f2029e5e51128d1b4a7a4f8bb2 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 3 Mar 2020 11:25:00 -0700 Subject: [PATCH 06/11] added cumulativeSum guide, added flex shortcodes, updates to common queries docs --- CONTRIBUTING.md | 32 ++++ assets/styles/layouts/_article.scss | 1 + assets/styles/layouts/article/_flex.scss | 24 +++ .../v2.0/query-data/common-queries/_index.md | 99 +++-------- .../common-queries/cumulativesum.md | 67 ++++++++ .../{query-median.md => median.md} | 105 +++++++++--- .../common-queries/percentile-quantile.md | 161 ++++++++++++++++++ .../query-data/common-queries/query-fields.md | 4 +- .../common-queries/query-percentile.md | 102 ----------- layouts/shortcodes/flex-content.html | 5 + layouts/shortcodes/flex.html | 4 + 11 files changed, 402 insertions(+), 202 deletions(-) create mode 100644 assets/styles/layouts/article/_flex.scss create mode 100644 content/v2.0/query-data/common-queries/cumulativesum.md rename content/v2.0/query-data/common-queries/{query-median.md => median.md} (55%) create mode 100644 content/v2.0/query-data/common-queries/percentile-quantile.md delete mode 100644 content/v2.0/query-data/common-queries/query-percentile.md create mode 100644 layouts/shortcodes/flex-content.html create mode 100644 layouts/shortcodes/flex.html diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4fabcee7..c15880cdb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -509,6 +509,38 @@ The following options are available: {{< ui-message color="green" text="The message displayed in the notification.">}} ``` +### Flexbox-formatted content blocks +CSS Flexbox formatting lets you create columns in article content that adjust and +flow based on the viewable width. +In article content, this helps if you have narrow tables that could be displayed +side-by-side, rather than stacked vertically. +Use the `{{< flex >}}` shortcode to create the Flexbox wrapper. +Use the `{{% flex-content %}}` shortcode to identify each column content block. + +```md +{{< flex >}} +{{% flex-content %}} +Column 1 +{{% /flex-content %}} +{{% flex-content %}} +Column 2 +{{% /flex-content %}} +{{< /flex >}} +``` + +`{{% flex-content %}}` has an optional width argument that determines the maximum +width of the column. + +```md +{{% flex-content "half" %}} +``` + +The following options are available: + +- half _(Default)_ +- third +- quarter + ### Reference content The InfluxDB documentation is "task-based," meaning content primarily focuses on what a user is **doing**, not what they are **using**. diff --git a/assets/styles/layouts/_article.scss b/assets/styles/layouts/_article.scss index 15997d6ce..19caeeacc 100644 --- a/assets/styles/layouts/_article.scss +++ b/assets/styles/layouts/_article.scss @@ -104,6 +104,7 @@ "article/cloud", "article/enterprise", "article/feedback", + "article/flex", "article/lists", "article/note", "article/pagination-btns", diff --git a/assets/styles/layouts/article/_flex.scss b/assets/styles/layouts/article/_flex.scss new file mode 100644 index 000000000..93ba285d0 --- /dev/null +++ b/assets/styles/layouts/article/_flex.scss @@ -0,0 +1,24 @@ +/////////////////////////// Flex Content Blocks /////////////////////////// + +.flex-wrapper { + display: flex; + flex-wrap: wrap; +} + +.flex-container { + margin-right: 1rem; + &.half { width: calc(50% - 1rem); } + &.third { width: calc(33.33% - 1rem); } + &.quarter { width: calc(25% - 1rem); } +} + +//////////////////////////////////////////////////////////////////////////////// +///////////////////////////////// MEDIA QUERIES //////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +@include media(small) { + .flex-container { + &.half, &.third { width: calc(100% - 1rem); } + &.quarter { width: calc(50% - 1rem); } + } +} diff --git a/content/v2.0/query-data/common-queries/_index.md b/content/v2.0/query-data/common-queries/_index.md index d5b152586..46505fc2d 100644 --- a/content/v2.0/query-data/common-queries/_index.md +++ b/content/v2.0/query-data/common-queries/_index.md @@ -11,86 +11,41 @@ v2.0/tags: [query] --- -- SELECT-like commands -- Median -- Percentile -- Cumulative Sum -- Moving Average -- Increase -- Rate -- Delta -- Window -- First/Last -- Histogram -- Gap filling -- Last observation carried forward -- Last point +{{% note %}} +#### Example data variable +Many of the examples provided in the following guides use a `data` variable, +which represents a basic query which filters data by measurement and field. +`data` is defined as: -## SELECT-like commands - -Query fields from InfluxDB - -## Median - -##### Median as an aggregate ```js -from(bucket: "example-bucket") +data = from(bucket: "example-bucket") |> range(start: -1h) |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggregateWindow(every: 5m, fn: median) -``` - -##### Median as a selector -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> median(method: "exact_selector") -``` - -## Percentile - -##### Percentile as an aggregate -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggregateWindow( - every: 5m, - fn: (tables=<-, column) => tables |> quantile(q: 0.99) + r._measurement == "example-measurement" and + r._field == "example-field" ) ``` +{{% /note %}} -##### Percentile as a selector -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> quantile(q: 0.99) -``` +{{< children >}} + +--- + +- [x] SELECT-like commands +- [x] Median +- [x] Percentile +- [ ] Cumulative Sum +- [ ] Moving Average +- [ ] Increase +- [ ] Rate +- [ ] Delta +- [ ] Window +- [ ] First/Last +- [ ] Histogram +- [ ] Gap filling +- [ ] Last observation carried forward +- [ ] Last point -## Cumulative Sum -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> cumulativeSum() -``` ## Moving Average ```js diff --git a/content/v2.0/query-data/common-queries/cumulativesum.md b/content/v2.0/query-data/common-queries/cumulativesum.md new file mode 100644 index 000000000..7ed9db61c --- /dev/null +++ b/content/v2.0/query-data/common-queries/cumulativesum.md @@ -0,0 +1,67 @@ +--- +title: Query cumulative sum +seotitle: Query cumulative sum in Flux +list_title: Cumulative sum +description: > + Use the `cumulativeSum()` function to calculate a running total of values. +weight: 204 +menu: + v2_0: + parent: Common queries + name: Cumulative sum +v2.0/tags: [query, cumulative sum] +--- + +Use the [`cumulativeSum()` function](/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum/) +to calculate a running total of values. +`cumulativeSum` sums the values of subsequent records and returns each row updated with the summed total. + +{{< flex >}} +{{% flex-content "half" %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1 | +| 0002 | 2 | +| 0003 | 1 | +| 0004 | 3 | +{{% /flex-content %}} +{{% flex-content "half" %}} +**`cumulativeSum()` returns:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1 | +| 0002 | 3 | +| 0003 | 4 | +| 0004 | 7 | +{{% /flex-content %}} +{{< /flex >}} + +{{% note %}} +The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). +{{% /note %}} + +##### Calculate the running total of values +```js +data + |> cumulativeSum() +``` + +## Use cumulativeSum() with aggregateWindow() +[`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) +segments data into windows of time, aggregates data in each window into a single +point, then removes the time-based segmentation. +It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). + +`aggregateWindow()` expects an aggregate function that returns a single row for each time window. +To use `cumulativeSum()` with `aggregateWindow`, use `sum` in `aggregateWindow()`, +then calculate the running total of the aggregate values with `cumulativeSum()`. + + +```js +data + |> aggregateWindow(every: 5m, fn: sum) + |> cumulativeSum() +``` diff --git a/content/v2.0/query-data/common-queries/query-median.md b/content/v2.0/query-data/common-queries/median.md similarity index 55% rename from content/v2.0/query-data/common-queries/query-median.md rename to content/v2.0/query-data/common-queries/median.md index c9fc57880..97a41ae50 100644 --- a/content/v2.0/query-data/common-queries/query-median.md +++ b/content/v2.0/query-data/common-queries/median.md @@ -1,15 +1,18 @@ --- title: Query median values seotitle: Query median values in Flux +list_title: Median description: > - placeholder -weight: 201 + Use the `median()` function to return all values within the `0.5` quantile + (50th percentile) or the median value of input data. +weight: 202 menu: v2_0: parent: Common queries + name: Median v2.0/tags: [query, median] related: - - /v2.0/query-data/common-queries/query-percentile/ + - /v2.0/query-data/common-queries/percentile-quantile/ --- Use the [`median()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/) @@ -18,35 +21,88 @@ to return all values within the `0.5` quantile (50th percentile) or the median v ## Median calculation methods Select from the following methods for calculating the median: -##### estimate_tdigest +- [estimate_tdigest](#estimate-tdigest) +- [exact_mean](#exact-mean) +- [exact_selector](#exact-selector) + +### estimate_tdigest **(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) to compute an accurate quantile estimate on large data sources. -Returns all values in the `0.5` quantile or 50th percentile. +Output tables consist of a single row containing the calculated median. -##### exact_mean +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`estimate_tdigest` returns:** + +| _value | +|:------:| +| 1.5 | +{{% /flex-content %}} +{{< /flex >}} + +### exact_mean An aggregate method that takes the average of the two points closest to the quantile value. Output tables consist of a single row containing the calculated median. -##### exact_selector +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`exact_mean` returns:** + +| _value | +|:------:| +| 1.5 | +{{% /flex-content %}} +{{< /flex >}} + +### exact_selector A selector method that returns the data point for which at least 50% of points are less than. Output tables consist of a single row containing the calculated median. -{{% note %}} -#### Example data variable -To focus on using the `median()` function, the examples below use a `data` variable -which represents a base queried dataset. +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** -```js -data = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-field" - ) -``` +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`exact_selector` returns:** + +| _time | _value | +| ----- |:------:| +| 0002 | 1.0 | +{{% /flex-content %}} +{{< /flex >}} + +{{% note %}} +The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). {{% /note %}} -## Query all values in the 50th percentile +## Query the value that represents the median Use the default method, `"estimate_tdigest"`, to return all rows in a table that contain values in the 50th percentile of data in the table. @@ -64,7 +120,7 @@ data |> median(method: "exact_mean") ``` -## Query the median value +## Query the point with the median value Use the `exact_selector` method to return a single row per input table containing the value that 50% of values in the table are less than. @@ -73,16 +129,13 @@ data |> median(method: "exact_selector") ``` -## Use median with aggregateWindow() +## Use median() with aggregateWindow() [`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) segments data into windows of time, aggregates data in each window into a single point, then removes the time-based segmentation. It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). -`aggregateWindow()` expects a single point from each time window. -Use either the `exact_mean` or `exact_mode` median calculation method. - -To specify parameters of the aggregate function in `aggregateWindow()`, use the +To specify the [median calculation method](#median-calculation-methods) in `aggregateWindow()`, use the [full function syntax](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function): ```js diff --git a/content/v2.0/query-data/common-queries/percentile-quantile.md b/content/v2.0/query-data/common-queries/percentile-quantile.md new file mode 100644 index 000000000..a6f5ac51b --- /dev/null +++ b/content/v2.0/query-data/common-queries/percentile-quantile.md @@ -0,0 +1,161 @@ +--- +title: Query percentile and quantile values +seotitle: Query percentile and quantile values in Flux +list_title: Percentile & quantile +description: > + Use the `quantile()` function to return all values within the `q` quantile or + percentile of input data. +weight: 203 +menu: + v2_0: + parent: Common queries + name: Percentile & quantile +v2.0/tags: [query, percentile, quantile] +related: + - /v2.0/query-data/common-queries/query-median/ +--- + +Use the [`quantile()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/) +to return all values within the `q` quantile or percentile of input data. + +## Percentile versus quantile +Percentiles and quantiles are very similar, differing only in the number used to calculate return values. +A percentile is calculated using numbers between `0` and `100`. +A quantile is calculated using numbers between `0.0` and `1.0`. +For example, the **`0.5` quantile** is the same as the **50th percentile**. + +## Quantile calculation methods +Select from the following methods for calculating the quantile: + +- [estimate_tdigest](#estimate-tdigest) +- [exact_mean](#exact-mean) +- [exact_selector](#exact-selector) + +### estimate_tdigest +**(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) +to compute an accurate quantile estimate on large data sources. +Output tables consist of a single row containing the calculated quantile. + +If calculating the `0.5` quantile or 50th percentile: + +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`estimate_tdigest` returns:** + +| _value | +|:------:| +| 1.5 | +{{% /flex-content %}} +{{< /flex >}} + +### exact_mean +An aggregate method that takes the average of the two points closest to the quantile value. +Output tables consist of a single row containing the calculated quantile. + +If calculating the `0.5` quantile or 50th percentile: + +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`exact_mean` returns:** + +| _value | +|:------:| +| 1.5 | +{{% /flex-content %}} +{{< /flex >}} + +### exact_selector +A selector method that returns the data point for which at least `q` points are less than. +Output tables consist of a single row containing the calculated quantile. + +If calculating the `0.5` quantile or 50th percentile: + +{{< flex >}} +{{% flex-content %}} +**Given the following input table:** + +| _time | _value | +| ----- |:------:| +| 0001 | 1.0 | +| 0002 | 1.0 | +| 0003 | 2.0 | +| 0004 | 3.0 | +{{% /flex-content %}} +{{% flex-content %}} +**`exact_selector` returns:** + +| _time | _value | +| ----- |:------:| +| 0002 | 1.0 | +{{% /flex-content %}} +{{< /flex >}} + +{{% note %}} +The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). +{{% /note %}} + +## Query the value representing the 99th percentile +Use the default method, `"estimate_tdigest"`, to return all rows in a table that +contain values in the 50th percentile of data in the table. + +```js +data + |> quantile(q: 0.99) +``` + +## Query the average of values closest to the quantile +Use the `exact_mean` method to return a single row per input table containing the +average of the two values closest to the mathematical quantile of data in the table. + +```js +data + |> quantile(q: 0.99, method: "exact_mean") +``` + +## Query the point with the quantile value +Use the `exact_selector` method to return a single row per input table containing the +value that `q * 100`% of values in the table are less than. + +```js +data + |> quantile(q: 0.99, method: "exact_selector") +``` + +## Use quantile() with aggregateWindow() +[`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) +segments data into windows of time, aggregates data in each window into a single +point, then removes the time-based segmentation. +It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). + +To specify the [quantile calculation method](#quantile-calculation-methods) in +`aggregateWindow()`, use the [full function syntax](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function): + +```js +data + |> aggregateWindow( + every: 5m, + fn: (tables=<-, column) => + tables + |> quantile(q: 0.99, method: "exact_selector") + ) +``` diff --git a/content/v2.0/query-data/common-queries/query-fields.md b/content/v2.0/query-data/common-queries/query-fields.md index 26646ce40..04e0bad02 100644 --- a/content/v2.0/query-data/common-queries/query-fields.md +++ b/content/v2.0/query-data/common-queries/query-fields.md @@ -4,7 +4,7 @@ seotitle: Query fields and tags in InfluxDB using Flux description: > Use the `filter()` function to query data based on fields, tags, or any other column value. If familiar with InfluxQL or other SQL-like query languages, `filter()` performs - operations similar to the `SELECT` statement and `WHERE` clause. + operations similar to the `SELECT` statement and the `WHERE` clause. weight: 201 menu: v2_0: @@ -15,7 +15,7 @@ v2.0/tags: [query, select, where] Use the [`filter()` function](/v2.0/reference/flux/stdlib/built-in/transformations/filter/) to query data based on fields, tags, or any other column value. If familiar with InfluxQL or other SQL-like query languages, `filter()` performs -operations similar to the `SELECT` statement and `WHERE` clause. +operations similar to the `SELECT` statement and the `WHERE` clause. ## The filter() function `filter()` has an `fn` parameter that expects a [predicate function](/v2.0/reference/glossary/#predicate-function), diff --git a/content/v2.0/query-data/common-queries/query-percentile.md b/content/v2.0/query-data/common-queries/query-percentile.md deleted file mode 100644 index fd0c3e1d7..000000000 --- a/content/v2.0/query-data/common-queries/query-percentile.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: Query percentile values -seotitle: Query percentile values in Flux -description: > - placeholder -weight: 201 -menu: - v2_0: - parent: Common queries -v2.0/tags: [query, percentile, quantile] -related: - - /v2.0/query-data/common-queries/query-median/ ---- - -Use the [`quantile()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/) -to return all values within the `q` quantile or percentile of input data. - -## Percentile versus quantile -Percentiles and quantiles are very similar, differing only in the number used to calculate return values. -A percentile is calculated using numbers between `0` and `100`. -A quantile is calculated using numbers between `0.0` and `1.0`. -For example, the **`0.5` quantile** is the same as the **50th percentile**. - -## Quantile calculation methods -Select from the following methods for calculating the quantile: - -##### estimate_tdigest -(Default) An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) -to compute an accurate quantile estimate on large data sources. -Returns all values in the `q` quantile. - -##### exact_mean -An aggregate method that takes the average of the two points closest to the quantile value. -Output tables consist of a single row containing the calculated quantile. - -##### exact_selector -A selector method that returns the data point for which at least `q` points are less than. -Output tables consist of a single row containing the calculated quantile. - -{{% note %}} -#### Example data variable -To focus on using the `quantile()` function, the examples below use a `data` variable -which represents a base queried dataset. - -```js -data = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-field" - ) -``` -{{% /note %}} - -## Query all values in the 50th percentile -Use the default method, `"estimate_tdigest"`, to return all rows in a table that -contain values in the 50th percentile of data in the table. - -```js -data - |> quantile(q: 0.99) -``` - -## Query the average of values closest to the quantile -Use the `exact_mean` method to return a single row per input table containing the -average of the two values closest to the mathematical quantile of data in the table. - -```js -data - |> quantile(q: 0.99, method: "exact_mean") -``` - -## Query the quantile value -Use the `exact_selector` method to return a single row per input table containing the -value that 50% of values in the table are less than. - -```js -data - |> quantile(q: 0.99, method: "exact_selector") -``` - -## Use quantile with aggregateWindow() -[`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) -segments data into windows of time, aggregates data in each window into a single -point, then removes the time-based segmentation. -It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). - -`aggregateWindow()` expects a single point from each time window. -Use either the `exact_mean` or `exact_mode` quantile calculation method. - -To specify parameters of the aggregate function in `aggregateWindow()`, use the -[full function syntax](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function): - -```js -data - |> aggregateWindow( - every: 5m, - fn: (tables=<-, column) => - tables - |> quantile(q: 0.99, method: "exact_selector") - ) -``` diff --git a/layouts/shortcodes/flex-content.html b/layouts/shortcodes/flex-content.html new file mode 100644 index 000000000..8458f6fa4 --- /dev/null +++ b/layouts/shortcodes/flex-content.html @@ -0,0 +1,5 @@ +{{ $width := .Get 0 | default "half" }} +{{ $_hugo_config := `{ "version": 1 }` }} +
+ {{ .Inner }} +
diff --git a/layouts/shortcodes/flex.html b/layouts/shortcodes/flex.html new file mode 100644 index 000000000..5943fba4b --- /dev/null +++ b/layouts/shortcodes/flex.html @@ -0,0 +1,4 @@ +{{ $_hugo_config := `{ "version": 1 }` }} +
+ {{ .Inner }} +
From 5817876fdc79657ed7155d77a8e18fe8605e74c3 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 5 Mar 2020 11:57:03 -0700 Subject: [PATCH 07/11] removed placeholder examples from common queries landing page --- .../v2.0/query-data/common-queries/_index.md | 118 ------------------ 1 file changed, 118 deletions(-) diff --git a/content/v2.0/query-data/common-queries/_index.md b/content/v2.0/query-data/common-queries/_index.md index 46505fc2d..6a4130a2a 100644 --- a/content/v2.0/query-data/common-queries/_index.md +++ b/content/v2.0/query-data/common-queries/_index.md @@ -45,121 +45,3 @@ data = from(bucket: "example-bucket") - [ ] Gap filling - [ ] Last observation carried forward - [ ] Last point - - -## Moving Average -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> movingAverage() -``` - -## Increase -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> increase() -``` - -## Rate -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> derivative(unit: 1s, nonNegative: true) -``` - -```js -import "experimental/aggregate" - -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggregate.rate(unit: 1s, every: 5m) -``` - -## Delta (state changes only) - - -## Window (time buckets) -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> window(every: 5m) -``` - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggreateWindow(every: 5m, fn: mean) -``` - -## First/Last -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggreateWindow(every: 5m, fn: first) -``` - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => - r._measurement == "example-measurement" and - r._field == "example-key" - ) - |> aggreateWindow(every: 5m, fn: last) -``` - -## Histogram -Histogram docs - -```js - -``` - - -## Gap filling -Fill gaps in data - -```js - -``` - - -## Last observation carried forward (need) -```js - -``` - - -## Last point (need) -```js - -``` From 598921dddb8e19b3e429f3df1ac5b0c4e0f99b40 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 5 Mar 2020 15:11:42 -0700 Subject: [PATCH 08/11] updates to address PR feedback --- .../v2.0/query-data/common-queries/_index.md | 2 +- .../v2.0/query-data/common-queries/median.md | 22 +++++++++---------- .../common-queries/percentile-quantile.md | 20 +++++++++-------- .../query-data/common-queries/query-fields.md | 8 +++---- content/v2.0/reference/glossary.md | 2 +- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/content/v2.0/query-data/common-queries/_index.md b/content/v2.0/query-data/common-queries/_index.md index 6a4130a2a..f99f574fa 100644 --- a/content/v2.0/query-data/common-queries/_index.md +++ b/content/v2.0/query-data/common-queries/_index.md @@ -14,7 +14,7 @@ v2.0/tags: [query] {{% note %}} #### Example data variable Many of the examples provided in the following guides use a `data` variable, -which represents a basic query which filters data by measurement and field. +which represents a basic query that filters data by measurement and field. `data` is defined as: ```js diff --git a/content/v2.0/query-data/common-queries/median.md b/content/v2.0/query-data/common-queries/median.md index 97a41ae50..89d4a4b3e 100644 --- a/content/v2.0/query-data/common-queries/median.md +++ b/content/v2.0/query-data/common-queries/median.md @@ -3,8 +3,8 @@ title: Query median values seotitle: Query median values in Flux list_title: Median description: > - Use the `median()` function to return all values within the `0.5` quantile - (50th percentile) or the median value of input data. + Use the `median()` function to return a value representing the `0.5` quantile + (50th percentile) or median of input data. weight: 202 menu: v2_0: @@ -16,10 +16,10 @@ related: --- Use the [`median()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/) -to return all values within the `0.5` quantile (50th percentile) or the median value of input data. +to return a value representing the `0.5` quantile (50th percentile) or median of input data. -## Median calculation methods -Select from the following methods for calculating the median: +## Select a method for calculating the median +Select one of the following methods to calculate the median: - [estimate_tdigest](#estimate-tdigest) - [exact_mean](#exact-mean) @@ -27,7 +27,7 @@ Select from the following methods for calculating the median: ### estimate_tdigest **(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) -to compute an accurate quantile estimate on large data sources. +to compute an accurate `0.5` quantile estimate on large data sources. Output tables consist of a single row containing the calculated median. {{< flex >}} @@ -51,7 +51,7 @@ Output tables consist of a single row containing the calculated median. {{< /flex >}} ### exact_mean -An aggregate method that takes the average of the two points closest to the quantile value. +An aggregate method that takes the average of the two points closest to the `0.5` quantile value. Output tables consist of a single row containing the calculated median. {{< flex >}} @@ -102,7 +102,7 @@ Output tables consist of a single row containing the calculated median. The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). {{% /note %}} -## Query the value that represents the median +## Find the value that represents the median Use the default method, `"estimate_tdigest"`, to return all rows in a table that contain values in the 50th percentile of data in the table. @@ -111,7 +111,7 @@ data |> median() ``` -## Query the average of values closest to the median +## Find the average of values closest to the median Use the `exact_mean` method to return a single row per input table containing the average of the two values closest to the mathematical median of data in the table. @@ -120,7 +120,7 @@ data |> median(method: "exact_mean") ``` -## Query the point with the median value +## Find the point with the median value Use the `exact_selector` method to return a single row per input table containing the value that 50% of values in the table are less than. @@ -132,7 +132,7 @@ data ## Use median() with aggregateWindow() [`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) segments data into windows of time, aggregates data in each window into a single -point, then removes the time-based segmentation. +point, and then removes the time-based segmentation. It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). To specify the [median calculation method](#median-calculation-methods) in `aggregateWindow()`, use the diff --git a/content/v2.0/query-data/common-queries/percentile-quantile.md b/content/v2.0/query-data/common-queries/percentile-quantile.md index a6f5ac51b..dcf4308ef 100644 --- a/content/v2.0/query-data/common-queries/percentile-quantile.md +++ b/content/v2.0/query-data/common-queries/percentile-quantile.md @@ -16,7 +16,7 @@ related: --- Use the [`quantile()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/) -to return all values within the `q` quantile or percentile of input data. +to return a value representing the `q` quantile or percentile of input data. ## Percentile versus quantile Percentiles and quantiles are very similar, differing only in the number used to calculate return values. @@ -24,8 +24,8 @@ A percentile is calculated using numbers between `0` and `100`. A quantile is calculated using numbers between `0.0` and `1.0`. For example, the **`0.5` quantile** is the same as the **50th percentile**. -## Quantile calculation methods -Select from the following methods for calculating the quantile: +## Select a method for calculating the quantile +Select one of the following methods to calculate the quantile: - [estimate_tdigest](#estimate-tdigest) - [exact_mean](#exact-mean) @@ -33,7 +33,7 @@ Select from the following methods for calculating the quantile: ### estimate_tdigest **(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) -to compute an accurate quantile estimate on large data sources. +to compute a quantile estimate on large data sources. Output tables consist of a single row containing the calculated quantile. If calculating the `0.5` quantile or 50th percentile: @@ -114,27 +114,29 @@ If calculating the `0.5` quantile or 50th percentile: The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). {{% /note %}} -## Query the value representing the 99th percentile +## Find the value representing the 99th percentile Use the default method, `"estimate_tdigest"`, to return all rows in a table that -contain values in the 50th percentile of data in the table. +contain values in the 99th percentile of data in the table. ```js data |> quantile(q: 0.99) ``` -## Query the average of values closest to the quantile +## Find the average of values closest to the quantile Use the `exact_mean` method to return a single row per input table containing the average of the two values closest to the mathematical quantile of data in the table. +For example, to calculate the `0.99` quantile: ```js data |> quantile(q: 0.99, method: "exact_mean") ``` -## Query the point with the quantile value +## Find the point with the quantile value Use the `exact_selector` method to return a single row per input table containing the value that `q * 100`% of values in the table are less than. +For example, to calculate the `0.99` quantile: ```js data @@ -144,7 +146,7 @@ data ## Use quantile() with aggregateWindow() [`aggregateWindow()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/) segments data into windows of time, aggregates data in each window into a single -point, then removes the time-based segmentation. +point, and then removes the time-based segmentation. It is primarily used to [downsample data](/v2.0/process-data/common-tasks/downsample-data/). To specify the [quantile calculation method](#quantile-calculation-methods) in diff --git a/content/v2.0/query-data/common-queries/query-fields.md b/content/v2.0/query-data/common-queries/query-fields.md index 04e0bad02..3071edd49 100644 --- a/content/v2.0/query-data/common-queries/query-fields.md +++ b/content/v2.0/query-data/common-queries/query-fields.md @@ -3,8 +3,8 @@ title: Query fields and tags seotitle: Query fields and tags in InfluxDB using Flux description: > Use the `filter()` function to query data based on fields, tags, or any other column value. - If familiar with InfluxQL or other SQL-like query languages, `filter()` performs - operations similar to the `SELECT` statement and the `WHERE` clause. + `filter()` performs operations similar to the `SELECT` statement and the `WHERE` + clause in InfluxQL and other SQL-like query languages. weight: 201 menu: v2_0: @@ -14,8 +14,8 @@ v2.0/tags: [query, select, where] Use the [`filter()` function](/v2.0/reference/flux/stdlib/built-in/transformations/filter/) to query data based on fields, tags, or any other column value. -If familiar with InfluxQL or other SQL-like query languages, `filter()` performs -operations similar to the `SELECT` statement and the `WHERE` clause. +`filter()` performs operations similar to the `SELECT` statement and the `WHERE` +clause in InfluxQL and other SQL-like query languages. ## The filter() function `filter()` has an `fn` parameter that expects a [predicate function](/v2.0/reference/glossary/#predicate-function), diff --git a/content/v2.0/reference/glossary.md b/content/v2.0/reference/glossary.md index d530febcf..cc61d24a3 100644 --- a/content/v2.0/reference/glossary.md +++ b/content/v2.0/reference/glossary.md @@ -712,7 +712,7 @@ A predicate expression is comprised of a left operand, a comparison operator, an A Flux predicate function is an anonymous function that returns `true` or `false` based on one or more [predicate expressions](#predicate-expression). Flux uses predicate functions primarily to filter records based on values of specific columns, -but predicate functions are used in other applications as well. +but predicate functions can be used in other applications as well. ###### Example predicate function ```js From 8128b2573588b2f148b71d391791001ae071e811 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 5 Mar 2020 15:18:48 -0700 Subject: [PATCH 09/11] removed mention of alternate users for predicate functions --- content/v2.0/reference/glossary.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/content/v2.0/reference/glossary.md b/content/v2.0/reference/glossary.md index cc61d24a3..fa47ddc8d 100644 --- a/content/v2.0/reference/glossary.md +++ b/content/v2.0/reference/glossary.md @@ -711,8 +711,6 @@ A predicate expression is comprised of a left operand, a comparison operator, an ### predicate function A Flux predicate function is an anonymous function that returns `true` or `false` based on one or more [predicate expressions](#predicate-expression). -Flux uses predicate functions primarily to filter records based on values of specific columns, -but predicate functions can be used in other applications as well. ###### Example predicate function ```js From 016c0aae2c2f02e0c748408bc9c34dbc3db8994f Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 6 Mar 2020 08:40:37 -0700 Subject: [PATCH 10/11] restructured query guides --- content/v2.0/cloud/pricing-calculator.md | 2 +- content/v2.0/query-data/execute-queries.md | 2 +- .../{common-queries => flux}/_index.md | 31 ++++++------------- .../{guides => flux}/conditional-logic.md | 7 +++-- .../{common-queries => flux}/cumulativesum.md | 4 +-- .../custom-functions/_index.md | 4 ++- .../custom-functions/custom-aggregate.md | 2 ++ .../query-data/{guides => flux}/exists.md | 4 ++- .../query-data/{guides => flux}/group-data.md | 5 ++- .../query-data/{guides => flux}/histograms.md | 5 ++- .../v2.0/query-data/{guides => flux}/join.md | 5 ++- .../{guides => flux}/manipulate-timestamps.md | 5 ++- .../{guides => flux}/mathematic-operations.md | 5 ++- .../{common-queries => flux}/median.md | 6 ++-- .../{guides => flux}/monitor-states.md | 12 ++++--- .../percentile-quantile.md | 6 ++-- .../{common-queries => flux}/query-fields.md | 2 +- .../{guides => flux}/regular-expressions.md | 5 ++- .../{guides => flux}/scalar-values.md | 3 ++ .../query-data/{guides => flux}/sort-limit.md | 5 ++- .../v2.0/query-data/{guides => flux}/sql.md | 4 ++- .../{guides => flux}/window-aggregate.md | 7 +++-- content/v2.0/query-data/guides/_index.md | 14 --------- .../v2.0/reference/flux/language/operators.md | 2 +- content/v2.0/reference/glossary.md | 10 +++--- .../reference/key-concepts/data-elements.md | 4 +-- .../reference/key-concepts/table-structure.md | 2 +- .../v2.0/visualize-data/explore-metrics.md | 2 +- 28 files changed, 90 insertions(+), 75 deletions(-) rename content/v2.0/query-data/{common-queries => flux}/_index.md (56%) rename content/v2.0/query-data/{guides => flux}/conditional-logic.md (97%) rename content/v2.0/query-data/{common-queries => flux}/cumulativesum.md (96%) rename content/v2.0/query-data/{guides => flux}/custom-functions/_index.md (97%) rename content/v2.0/query-data/{guides => flux}/custom-functions/custom-aggregate.md (99%) rename content/v2.0/query-data/{guides => flux}/exists.md (96%) rename content/v2.0/query-data/{guides => flux}/group-data.md (99%) rename content/v2.0/query-data/{guides => flux}/histograms.md (99%) rename content/v2.0/query-data/{guides => flux}/join.md (99%) rename content/v2.0/query-data/{guides => flux}/manipulate-timestamps.md (97%) rename content/v2.0/query-data/{guides => flux}/mathematic-operations.md (98%) rename content/v2.0/query-data/{common-queries => flux}/median.md (96%) rename content/v2.0/query-data/{guides => flux}/monitor-states.md (98%) rename content/v2.0/query-data/{common-queries => flux}/percentile-quantile.md (97%) rename content/v2.0/query-data/{common-queries => flux}/query-fields.md (98%) rename content/v2.0/query-data/{guides => flux}/regular-expressions.md (96%) rename content/v2.0/query-data/{guides => flux}/scalar-values.md (98%) rename content/v2.0/query-data/{guides => flux}/sort-limit.md (95%) rename content/v2.0/query-data/{guides => flux}/sql.md (99%) rename content/v2.0/query-data/{guides => flux}/window-aggregate.md (99%) delete mode 100644 content/v2.0/query-data/guides/_index.md diff --git a/content/v2.0/cloud/pricing-calculator.md b/content/v2.0/cloud/pricing-calculator.md index 0ed972557..08645f9d7 100644 --- a/content/v2.0/cloud/pricing-calculator.md +++ b/content/v2.0/cloud/pricing-calculator.md @@ -45,4 +45,4 @@ Guidelines used to estimate costs for default configurations: - **Professional**. For teams monitoring multiple disparate systems or use cases. - **Enterprise**. For teams monitoring multiple domains and use cases accessing a variety of dashboards. 5. Adjust the default configuration values to match your number of devices, plugins, metrics, and so on. The **Projected Usage** costs are automatically updated as you adjust your configuration. -6. Click **Get started with InfluxDB Cloud** [to get started](https://v2.docs.influxdata.com/v2.0/cloud/get-started/). +6. Click **Get started with InfluxDB Cloud** [to get started](/v2.0/cloud/get-started/). diff --git a/content/v2.0/query-data/execute-queries.md b/content/v2.0/query-data/execute-queries.md index 68c76332f..05516e9b2 100644 --- a/content/v2.0/query-data/execute-queries.md +++ b/content/v2.0/query-data/execute-queries.md @@ -2,7 +2,7 @@ title: Execute queries seotitle: Different ways to query InfluxDB description: There are multiple ways to query data from InfluxDB including the InfluxDB UI, CLI, and API. -weight: 102 +weight: 103 menu: v2_0: name: Execute queries diff --git a/content/v2.0/query-data/common-queries/_index.md b/content/v2.0/query-data/flux/_index.md similarity index 56% rename from content/v2.0/query-data/common-queries/_index.md rename to content/v2.0/query-data/flux/_index.md index f99f574fa..f9dc8dd20 100644 --- a/content/v2.0/query-data/common-queries/_index.md +++ b/content/v2.0/query-data/flux/_index.md @@ -1,15 +1,17 @@ --- -title: Common Flux queries -description: > - placeholder -weight: 103 +title: Query data with Flux +description: Guides that walk through both common and complex queries and use cases for Flux. +weight: 102 +v2.0/tags: [flux, query] menu: v2_0: + name: Query with Flux parent: Query data - name: Common queries -v2.0/tags: [query] +alias: + - /v2.0/query-data/guides/ --- +The following guides walk through both common and complex queries and use cases for Flux. {{% note %}} #### Example data variable @@ -27,21 +29,8 @@ data = from(bucket: "example-bucket") ``` {{% /note %}} -{{< children >}} +## Flux query guides --- -- [x] SELECT-like commands -- [x] Median -- [x] Percentile -- [ ] Cumulative Sum -- [ ] Moving Average -- [ ] Increase -- [ ] Rate -- [ ] Delta -- [ ] Window -- [ ] First/Last -- [ ] Histogram -- [ ] Gap filling -- [ ] Last observation carried forward -- [ ] Last point +{{< children >}} diff --git a/content/v2.0/query-data/guides/conditional-logic.md b/content/v2.0/query-data/flux/conditional-logic.md similarity index 97% rename from content/v2.0/query-data/guides/conditional-logic.md rename to content/v2.0/query-data/flux/conditional-logic.md index 5da8eb448..bbfc26821 100644 --- a/content/v2.0/query-data/guides/conditional-logic.md +++ b/content/v2.0/query-data/flux/conditional-logic.md @@ -1,15 +1,18 @@ --- title: Query using conditional logic seotitle: Query using conditional logic in Flux +list_title: Use conditional logic description: > This guide describes how to use Flux conditional expressions, such as `if`, `else`, and `then`, to query and transform data. v2.0/tags: [conditionals, flux] menu: v2_0: - name: Query using conditionals - parent: How-to guides + name: Use conditional logic + parent: Query with Flux weight: 209 +aliases: + - /v2.0/query-data/guides/conditional-logic/ --- Flux provides `if`, `then`, and `else` conditional expressions that allow for powerful and flexible Flux queries. diff --git a/content/v2.0/query-data/common-queries/cumulativesum.md b/content/v2.0/query-data/flux/cumulativesum.md similarity index 96% rename from content/v2.0/query-data/common-queries/cumulativesum.md rename to content/v2.0/query-data/flux/cumulativesum.md index 7ed9db61c..0501b4a35 100644 --- a/content/v2.0/query-data/common-queries/cumulativesum.md +++ b/content/v2.0/query-data/flux/cumulativesum.md @@ -7,7 +7,7 @@ description: > weight: 204 menu: v2_0: - parent: Common queries + parent: Query with Flux name: Cumulative sum v2.0/tags: [query, cumulative sum] --- @@ -40,7 +40,7 @@ to calculate a running total of values. {{< /flex >}} {{% note %}} -The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). +The examples below use the [example data variable](/v2.0/query-data/flux/#example-data-variable). {{% /note %}} ##### Calculate the running total of values diff --git a/content/v2.0/query-data/guides/custom-functions/_index.md b/content/v2.0/query-data/flux/custom-functions/_index.md similarity index 97% rename from content/v2.0/query-data/guides/custom-functions/_index.md rename to content/v2.0/query-data/flux/custom-functions/_index.md index d15716bcd..0cd0dd7c7 100644 --- a/content/v2.0/query-data/guides/custom-functions/_index.md +++ b/content/v2.0/query-data/flux/custom-functions/_index.md @@ -5,8 +5,10 @@ v2.0/tags: [functions, custom, flux] menu: v2_0: name: Create custom functions - parent: How-to guides + parent: Query with Flux weight: 208 +aliases: + - /v2.0/query-data/guides/custom-functions/ --- Flux's functional syntax allows for custom functions. diff --git a/content/v2.0/query-data/guides/custom-functions/custom-aggregate.md b/content/v2.0/query-data/flux/custom-functions/custom-aggregate.md similarity index 99% rename from content/v2.0/query-data/guides/custom-functions/custom-aggregate.md rename to content/v2.0/query-data/flux/custom-functions/custom-aggregate.md index 94c8843da..525a66734 100644 --- a/content/v2.0/query-data/guides/custom-functions/custom-aggregate.md +++ b/content/v2.0/query-data/flux/custom-functions/custom-aggregate.md @@ -7,6 +7,8 @@ menu: name: Custom aggregate functions parent: Create custom functions weight: 301 +aliases: + - /v2.0/query-data/guides/custom-functions/custom-aggregate/ --- To aggregate your data, use the Flux diff --git a/content/v2.0/query-data/guides/exists.md b/content/v2.0/query-data/flux/exists.md similarity index 96% rename from content/v2.0/query-data/guides/exists.md rename to content/v2.0/query-data/flux/exists.md index 2d7794e54..5758ee220 100644 --- a/content/v2.0/query-data/guides/exists.md +++ b/content/v2.0/query-data/flux/exists.md @@ -8,8 +8,10 @@ v2.0/tags: [exists] menu: v2_0: name: Check if a value exists - parent: How-to guides + parent: Query with Flux weight: 209 +aliases: + - /v2.0/query-data/guides/exists/ --- Use the Flux `exists` operator to check if an object contains a key or if that diff --git a/content/v2.0/query-data/guides/group-data.md b/content/v2.0/query-data/flux/group-data.md similarity index 99% rename from content/v2.0/query-data/guides/group-data.md rename to content/v2.0/query-data/flux/group-data.md index 49eb473af..a8388daec 100644 --- a/content/v2.0/query-data/guides/group-data.md +++ b/content/v2.0/query-data/flux/group-data.md @@ -1,5 +1,6 @@ --- title: Group data in InfluxDB with Flux +list_title: Group data description: > This guide walks through grouping data with Flux by providing examples and illustrating how data is shaped throughout the process. @@ -7,8 +8,10 @@ v2.0/tags: [group] menu: v2_0: name: Group data - parent: How-to guides + parent: Query with Flux weight: 203 +aliases: + - /v2.0/query-data/guides/group-data/ --- With Flux, you can group data by any column in your queried data set. diff --git a/content/v2.0/query-data/guides/histograms.md b/content/v2.0/query-data/flux/histograms.md similarity index 99% rename from content/v2.0/query-data/guides/histograms.md rename to content/v2.0/query-data/flux/histograms.md index f9a9232b0..569b3e8d3 100644 --- a/content/v2.0/query-data/guides/histograms.md +++ b/content/v2.0/query-data/flux/histograms.md @@ -1,12 +1,15 @@ --- title: Create histograms with Flux +list_title: Create histograms description: This guide walks through using the `histogram()` function to create cumulative histograms with Flux. v2.0/tags: [histogram] menu: v2_0: name: Create histograms - parent: How-to guides + parent: Query with Flux weight: 208 +aliases: + - /v2.0/query-data/guides/histograms/ --- Histograms provide valuable insight into the distribution of your data. diff --git a/content/v2.0/query-data/guides/join.md b/content/v2.0/query-data/flux/join.md similarity index 99% rename from content/v2.0/query-data/guides/join.md rename to content/v2.0/query-data/flux/join.md index cf0075091..cbcfe20af 100644 --- a/content/v2.0/query-data/guides/join.md +++ b/content/v2.0/query-data/flux/join.md @@ -1,13 +1,16 @@ --- title: Join data with Flux seotitle: Join data in InfluxDB with Flux +list_title: Join data description: This guide walks through joining data with Flux and outlines how it shapes your data in the process. v2.0/tags: [join, flux] menu: v2_0: name: Join data - parent: How-to guides + parent: Query with Flux weight: 205 +aliases: + - /v2.0/query-data/guides/join/ --- The [`join()` function](/v2.0/reference/flux/stdlib/built-in/transformations/join) merges two or more diff --git a/content/v2.0/query-data/guides/manipulate-timestamps.md b/content/v2.0/query-data/flux/manipulate-timestamps.md similarity index 97% rename from content/v2.0/query-data/guides/manipulate-timestamps.md rename to content/v2.0/query-data/flux/manipulate-timestamps.md index 87bcc1d6b..3edec16a1 100644 --- a/content/v2.0/query-data/guides/manipulate-timestamps.md +++ b/content/v2.0/query-data/flux/manipulate-timestamps.md @@ -1,12 +1,15 @@ --- title: Manipulate timestamps with Flux +list_title: Manipulate timestamps description: > Use Flux to process and manipulate timestamps. menu: v2_0: name: Manipulate timestamps - parent: How-to guides + parent: Query with Flux weight: 209 +aliases: + - /v2.0/query-data/guides/manipulate-timestamps/ --- Every point stored in InfluxDB has an associated timestamp. diff --git a/content/v2.0/query-data/guides/mathematic-operations.md b/content/v2.0/query-data/flux/mathematic-operations.md similarity index 98% rename from content/v2.0/query-data/guides/mathematic-operations.md rename to content/v2.0/query-data/flux/mathematic-operations.md index 87a268686..c5c3d0dea 100644 --- a/content/v2.0/query-data/guides/mathematic-operations.md +++ b/content/v2.0/query-data/flux/mathematic-operations.md @@ -1,13 +1,16 @@ --- title: Transform data with mathematic operations seotitle: Transform data with mathematic operations in Flux +list_title: Transform data with math description: This guide describes how to use Flux to transform data with mathematic operations. v2.0/tags: [math, flux] menu: v2_0: name: Transform data with math - parent: How-to guides + parent: Query with Flux weight: 209 +aliases: + - /v2.0/query-data/guides/mathematic-operations/ --- [Flux](/v2.0/reference/flux), InfluxData's data scripting and query language, diff --git a/content/v2.0/query-data/common-queries/median.md b/content/v2.0/query-data/flux/median.md similarity index 96% rename from content/v2.0/query-data/common-queries/median.md rename to content/v2.0/query-data/flux/median.md index 89d4a4b3e..f8d469bff 100644 --- a/content/v2.0/query-data/common-queries/median.md +++ b/content/v2.0/query-data/flux/median.md @@ -8,11 +8,11 @@ description: > weight: 202 menu: v2_0: - parent: Common queries + parent: Query with Flux name: Median v2.0/tags: [query, median] related: - - /v2.0/query-data/common-queries/percentile-quantile/ + - /v2.0/query-data/flux/percentile-quantile/ --- Use the [`median()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/) @@ -99,7 +99,7 @@ Output tables consist of a single row containing the calculated median. {{< /flex >}} {{% note %}} -The examples below use the [example data variable](/v2.0/query-data/common-queries/#example-data-variable). +The examples below use the [example data variable](/v2.0/query-data/flux/#example-data-variable). {{% /note %}} ## Find the value that represents the median diff --git a/content/v2.0/query-data/guides/monitor-states.md b/content/v2.0/query-data/flux/monitor-states.md similarity index 98% rename from content/v2.0/query-data/guides/monitor-states.md rename to content/v2.0/query-data/flux/monitor-states.md index da62068f2..d2fb3c0c8 100644 --- a/content/v2.0/query-data/guides/monitor-states.md +++ b/content/v2.0/query-data/flux/monitor-states.md @@ -6,8 +6,10 @@ v2.0/tags: [states, monitor, flux] menu: v2_0: name: Monitor states - parent: How-to guides + parent: Query with Flux weight: 209 +aliases: + - /v2.0/query-data/guides/monitor-states/ --- Flux helps you monitor states in your metrics and events: @@ -24,7 +26,7 @@ If you're just getting started with Flux queries, check out the following: ## Find how long a state persists 1. Use the [`stateDuration()`](/v2.0/reference/flux/stdlib/built-in/transformations/stateduration/) function to calculate how long a column value has remained the same value (or state). Include the following information: - + - **Column to search:** any tag key, tag value, field key, field value, or measurement. - **Value:** the value (or state) to search for in the specified column. - **State duration column:** a new column to store the state duration─the length of time that the specified value persists. @@ -83,7 +85,7 @@ _time _value door_closed ```js |> stateCount - (fn: (r) => + (fn: (r) => r._column_to_search == "value_to_search_for", column: "state_count"` ) @@ -148,9 +150,9 @@ Detect state changes with the `monitor.stateChanges()` function. To use the `mon {{< nav-icon "alerts" >}} -2. If you haven't already, [create a check](/v2.0/monitor-alert/checks/create/) that stores statuses (`CRIT`, `WARN`, `INFO`, `OK` or `ANY`) in the `_level` column.