Merge pull request #982 from influxdata/query/list-query-examples

Query/list query examples
pull/987/head
Scott Anderson 2020-04-27 14:27:08 -06:00 committed by GitHub
commit b022da3888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 701 additions and 264 deletions

View File

@ -72,6 +72,8 @@ external_url: # Used in children shortcode type="list" for page links that are e
list_image: # Image included with article descriptions in children type="articles" shortcode
list_note: # Used in children shortcode type="list" to add a small note next to listed links
list_code_example: # Code example included with article descriptions in children type="articles" shortcode
list_query_example: # Code examples included with article descriptions in children type="articles" shortcode,
# References to examples in data/query_examples
products: # List of products that the page specifically applies to: [oss, cloud, enterprise]
```
@ -368,8 +370,26 @@ The following list types are available:
- **articles:** lists article titles as headers with the description or summary
of the article as a paragraph. Article headers link to the articles.
- **list:** lists children article links in an unordered list.
- **anchored-list:** lists anchored children article links in an unordered list
meant to act as a page navigation and link to children header.
- **functions:** a special use-case designed for listing Flux functions.
#### Include a "Read more" link
To include a "Read more" link with each child summary, set `readmore=true`.
_Only the `articles` list type supports "Read more" links._
```md
{{< children readmore=true >}}
```
#### Include a horizontal rule
To include a horizontal rule after each child summary, set `hr=true`.
_Only the `articles` list type supports horizontal rules._
```md
{{< children readmore=true >}}
```
#### Include a code example with a child summary
Use the `list_code_example` frontmatter to provide a code example with an article
in an articles list.
@ -381,18 +401,28 @@ list_code_example: |
```
~~~
#### Reference a query example in children
To include a query example with the children in your list, update `data/query_examples.yml`
with the example code, input, and output, and use the `list_query_example`
frontmatter to reference the corresponding example.
```yaml
list_query_example: cumulative_sum
```
#### Children frontmatter
Each children list `type` uses [frontmatter properties](#page-frontmatter) when generating the list of articles.
The following table shows which children types use which frontmatter properties:
| Frontmatter | articles | list | functions |
|:----------- |:--------:|:----:|:---------:|
| `list_title` | ✓ | ✓ | ✓ |
| `description` | ✓ | | |
| `external_url` | ✓ | ✓ | |
| `list_image` | ✓ | | |
| `list_note` | | ✓ | |
| `list_code_example` | ✓ | | |
| Frontmatter | articles | list | functions |
|:----------- |:--------:|:----:|:---------:|
| `list_title` | ✓ | ✓ | ✓ |
| `description` | ✓ | | |
| `external_url` | ✓ | ✓ | |
| `list_image` | ✓ | | |
| `list_note` | | ✓ | |
| `list_code_example` | ✓ | | |
| `list_query_example` | ✓ | | |
### Inline icons
The `icon` shortcode allows you to inject icons in paragraph text.

View File

@ -5,7 +5,7 @@
}
.article--content{
max-width: 760px;
max-width: 820px;
h1,h2,h3,h4,h5,h6 {
color: $article-heading;
a {

View File

@ -11,6 +11,10 @@
&.half { width: calc(50% - 1rem); }
&.third { width: calc(33.33% - 1rem); }
&.quarter { width: calc(25% - 1rem); }
table {
margin-bottom: 1rem;
}
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -31,6 +31,8 @@ data = from(bucket: "example-bucket")
## Flux query guides
{{< children type="anchored-list" pages="all" >}}
---
{{< children pages="all" >}}
{{< children pages="all" readmore=true hr=true >}}

View File

@ -12,11 +12,7 @@ menu:
v2.0/tags: [query, cumulative sum]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum/
list_code_example: |
```js
data
|> cumulativeSum()
```
list_query_example: cumulative_sum
---
Use the [`cumulativeSum()` function](/v2.0/reference/flux/stdlib/built-in/transformations/cumulativesum/)

View File

@ -60,15 +60,13 @@ when mapping values in the `r` object.
To illustrate how this function works, take this simplified table for example:
```txt
_time _value
----------------------- -------
2019-04-23T16:10:49.00Z 1.6
2019-04-23T16:10:59.00Z 2.3
2019-04-23T16:11:09.00Z 0.7
2019-04-23T16:11:19.00Z 1.2
2019-04-23T16:11:29.00Z 3.8
```
| _time | _value |
|:----- | ------:|
| 2019-04-23T16:10:49Z | 1.6 |
| 2019-04-23T16:10:59Z | 2.3 |
| 2019-04-23T16:11:09Z | 0.7 |
| 2019-04-23T16:11:19Z | 1.2 |
| 2019-04-23T16:11:29Z | 3.8 |
###### Input objects
The `fn` function uses the data in the first row to define the `r` object.
@ -124,16 +122,16 @@ This cycle continues until all rows in the table are processed.
After all records in the table are processed, `reduce()` uses the final output object
to create a transformed table with one row and columns for each mapped key.
###### Final output object
```js
// Final output object
{ sum: 9.6, product: 11.74656 }
// Output table
sum product
---- ---------
9.6 11.74656
```
###### Output table
| sum | product |
| --- | -------- |
| 9.6 | 11.74656 |
{{% note %}}
#### What happened to the \_time column?
The `reduce()` function only keeps columns that are:

View File

@ -13,11 +13,7 @@ menu:
v2.0/tags: [query, fill]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/fill/
list_code_example: |
```js
data
|> fill(usePrevious: true)
```
list_query_example: fill_null
---
Use the [`fill()` function](/v2.0/reference/flux/stdlib/built-in/transformations/fill/)
@ -61,24 +57,24 @@ data
{{% flex-content %}}
**Given the following input:**
| _time | _value |
|:----- | ------:|
| 0001 | null |
| 0002 | 0.8 |
| 0003 | null |
| 0004 | null |
| 0005 | 1.4 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | null |
| 2020-01-01T00:04:00Z | null |
| 2020-01-01T00:05:00Z | 1.4 |
{{% /flex-content %}}
{{% flex-content %}}
**`fill(usePrevious: true)` returns:**
| _time | _value |
|:----- | ------:|
| 0001 | null |
| 0002 | 0.8 |
| 0003 | 0.8 |
| 0004 | 0.8 |
| 0005 | 1.4 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | 0.8 |
| 2020-01-01T00:04:00Z | 0.8 |
| 2020-01-01T00:05:00Z | 1.4 |
{{% /flex-content %}}
{{< /flex >}}
@ -96,23 +92,23 @@ data
{{% flex-content %}}
**Given the following input:**
| _time | _value |
|:----- | ------:|
| 0001 | null |
| 0002 | 0.8 |
| 0003 | null |
| 0004 | null |
| 0005 | 1.4 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | null |
| 2020-01-01T00:04:00Z | null |
| 2020-01-01T00:05:00Z | 1.4 |
{{% /flex-content %}}
{{% flex-content %}}
**`fill(value: 0.0)` returns:**
| _time | _value |
|:----- | ------:|
| 0001 | 0.0 |
| 0002 | 0.8 |
| 0003 | 0.0 |
| 0004 | 0.0 |
| 0005 | 1.4 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 0.0 |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | 0.0 |
| 2020-01-01T00:04:00Z | 0.0 |
| 2020-01-01T00:05:00Z | 1.4 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -15,16 +15,7 @@ v2.0/tags: [query]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/selectors/first/
- /v2.0/reference/flux/stdlib/built-in/transformations/selectors/last/
list_code_example: |
```js
data
|> first()
// OR
data
|> last()
```
list_query_example: first_last
---
Use the [`first()`](/v2.0/reference/flux/stdlib/built-in/transformations/selectors/first/) or
@ -56,12 +47,12 @@ based on the order they are received in.
{{% flex-content %}}
**Given the following input:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**The following function returns:**
@ -69,9 +60,9 @@ based on the order they are received in.
|> first()
```
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
{{% /flex-content %}}
{{< /flex >}}
@ -83,11 +74,11 @@ based on the order they are received in.
**Given the following input:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**The following function returns:**
@ -96,9 +87,9 @@ based on the order they are received in.
|> last()
```
| _time | _value |
| ----- |:------:|
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -15,11 +15,7 @@ aliases:
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/group
- /v2.0/reference/flux/stdlib/experimental/group
list_code_example: |
```js
data
|> group(columns: ["cpu", "host"], mode: "by")
```
list_query_example: group
---
With Flux, you can group data by any column in your queried data set.

View File

@ -14,17 +14,7 @@ aliases:
- /v2.0/query-data/guides/histograms/
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/histogram
list_code_example: |
```js
data
|> histogram(
column: "_value",
upperBoundColumn: "le",
countColumn: "_value",
bins: [50.0, 75.0, 90.0],
normalize: false)
)
```
list_query_example: histogram
---
Histograms provide valuable insight into the distribution of your data.

View File

@ -15,11 +15,7 @@ menu:
v2.0/tags: [query, increase, counters]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase/
list_code_example: |
```js
data
|> increase()
```
list_query_example: increase
---
Use the [`increase()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase/)
@ -39,24 +35,24 @@ For example:
{{% flex-content %}}
**Given the following input:**
| _time | _value |
|:----- | ------:|
| 0001 | 1 |
| 0002 | 2 |
| 0003 | 8 |
| 0004 | 10 |
| 0005 | 0 |
| 0006 | 4 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1 |
| 2020-01-01T00:02:00Z | 2 |
| 2020-01-01T00:03:00Z | 8 |
| 2020-01-01T00:04:00Z | 10 |
| 2020-01-01T00:05:00Z | 0 |
| 2020-01-01T00:06:00Z | 4 |
{{% /flex-content %}}
{{% flex-content %}}
**`increase()` returns:**
| _time | _value |
|:----- | ------:|
| 0002 | 1 |
| 0003 | 7 |
| 0004 | 9 |
| 0005 | 9 |
| 0006 | 13 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:02:00Z | 1 |
| 2020-01-01T00:03:00Z | 7 |
| 2020-01-01T00:04:00Z | 9 |
| 2020-01-01T00:05:00Z | 9 |
| 2020-01-01T00:06:00Z | 13 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -13,13 +13,7 @@ aliases:
- /v2.0/query-data/guides/join/
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/join
list_code_example: |
```js
join(
tables: {t1: stream1, t2: stream2},
on: ["_time"]
)
```
list_query_example: join
---
The [`join()` function](/v2.0/reference/flux/stdlib/built-in/transformations/join) merges two or more

View File

@ -18,11 +18,7 @@ related:
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/reduce/
- /v2.0/reference/flux/language/operators/
- /v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/
list_code_example: |
```js
data
|> map(fn: (r) => ({ r with _value: r._value * r._value }))
```
list_query_example: map_math
---
[Flux](/v2.0/reference/flux), InfluxData's data scripting and query language,

View File

@ -15,11 +15,7 @@ related:
- /v2.0/query-data/flux/percentile-quantile/
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/
list_code_example: |
```js
data
|> median()
```
list_query_example: median
---
Use the [`median()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/median/)
@ -41,12 +37,12 @@ Output tables consist of a single row containing the calculated median.
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`estimate_tdigest` returns:**
@ -65,12 +61,12 @@ Output tables consist of a single row containing the calculated median.
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`exact_mean` returns:**
@ -89,19 +85,19 @@ Output tables consist of a single row containing the calculated median.
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`exact_selector` returns:**
| _time | _value |
| ----- |:------:|
| 0002 | 1.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:02:00Z | 1.0 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -15,16 +15,7 @@ v2.0/tags: [query, moving average]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/
list_code_example: |
```js
data
|> movingAverage(n: 5)
// OR
data
|> timedMovingAverage(every: 5m, period: 10m)
```
list_query_example: moving_average
---
Use the [`movingAverage()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/)

View File

@ -14,11 +14,7 @@ v2.0/tags: [query, percentile, quantile]
related:
- /v2.0/query-data/flux/query-median/
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/
list_code_example: |
```js
data
|> quantile(q: 0.99)
```
list_query_example: quantile
---
Use the [`quantile()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/quantile/)
@ -48,12 +44,12 @@ If calculating the `0.5` quantile or 50th percentile:
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`estimate_tdigest` returns:**
@ -74,12 +70,12 @@ If calculating the `0.5` quantile or 50th percentile:
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`exact_mean` returns:**
@ -100,19 +96,19 @@ If calculating the `0.5` quantile or 50th percentile:
{{% flex-content %}}
**Given the following input table:**
| _time | _value |
| ----- |:------:|
| 0001 | 1.0 |
| 0002 | 1.0 |
| 0003 | 2.0 |
| 0004 | 3.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
{{% /flex-content %}}
{{% flex-content %}}
**`exact_selector` returns:**
| _time | _value |
| ----- |:------:|
| 0002 | 1.0 |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:02:00Z | 1.0 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -18,17 +18,7 @@ v2.0/tags: [query, rate]
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative/
- /v2.0/reference/flux/stdlib/experimental/aggregate/rate/
list_code_example: |
```js
data
|> derivative(unit: 1s, nonNegative: true)
```
```js
import "experimental/aggregate"
data
|> aggregate.rate(every: 1m, unit: 1s)
```
list_query_example: rate_of_change
---

View File

@ -13,11 +13,7 @@ aliases:
related:
- /v2.0/query-data/flux/query-fields/
- /v2.0/reference/flux/stdlib/regexp/
list_code_example: |
```js
data
|> filter(fn: (r) => r.tag =~ /^foo[0-9]/)
```
list_query_example: regular_expressions
---
Regular expressions (regexes) are incredibly powerful when matching patterns in large collections of data.

View File

@ -18,12 +18,7 @@ aliases:
related:
- /v2.0/reference/flux/stdlib/built-in/transformations/sort
- /v2.0/reference/flux/stdlib/built-in/transformations/limit
list_code_example: |
```js
data
|> sort(columns: ["host", "_value"])
|> limit(n: 10)
```
list_query_example: sort_limit
---
Use the [`sort()`function](/v2.0/reference/flux/stdlib/built-in/transformations/sort)

View File

@ -18,11 +18,7 @@ related:
- /v2.0/reference/flux/stdlib/built-in/transformations/window
- /v2.0/reference/flux/stdlib/built-in/transformations/aggregates
- /v2.0/reference/flux/stdlib/built-in/transformations/selectors
list_code_example: |
```js
data
|> aggregateWindow(every: 5m, fn: mean)
```
list_query_example: aggregate_window
---
A common operation performed with time series data is grouping data into windows of time,

452
data/query_examples.yml Normal file
View File

@ -0,0 +1,452 @@
aggregate_window:
-
code: |
```js
data
|> aggregateWindow(every: 20m, fn: mean)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:00:00Z | 250 |
| 2020-01-01T00:04:00Z | 160 |
| 2020-01-01T00:12:00Z | 150 |
| 2020-01-01T00:19:00Z | 220 |
| 2020-01-01T00:32:00Z | 200 |
| 2020-01-01T00:51:00Z | 290 |
| 2020-01-01T01:00:00Z | 340 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:20:00Z | 195 |
| 2020-01-01T00:40:00Z | 200 |
| 2020-01-01T01:00:00Z | 290 |
| 2020-01-01T01:20:00Z | 340 |
cumulative_sum:
-
code: |
```js
data
|> cumulativeSum()
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1 |
| 2020-01-01T00:02:00Z | 2 |
| 2020-01-01T00:03:00Z | 1 |
| 2020-01-01T00:04:00Z | 3 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1 |
| 2020-01-01T00:02:00Z | 3 |
| 2020-01-01T00:03:00Z | 4 |
| 2020-01-01T00:04:00Z | 7 |
fill_null:
-
code: |
```js
data
|> fill(usePrevious: true)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | null |
| 2020-01-01T00:04:00Z | null |
| 2020-01-01T00:05:00Z | 1.4 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | 0.8 |
| 2020-01-01T00:04:00Z | 0.8 |
| 2020-01-01T00:05:00Z | 1.4 |
-
code: |
```js
data
|> fill(value: 0.0)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | null |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | null |
| 2020-01-01T00:04:00Z | null |
| 2020-01-01T00:05:00Z | 1.4 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 0.0 |
| 2020-01-01T00:02:00Z | 0.8 |
| 2020-01-01T00:03:00Z | 0.0 |
| 2020-01-01T00:04:00Z | 0.0 |
| 2020-01-01T00:05:00Z | 1.4 |
first_last:
-
code: |
```js
data
|> first()
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
-
code: |
```js
data
|> last()
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:04:00Z | 3.0 |
group:
-
code: |
```js
data
|> group(columns: ["host"], mode: "by")
```
input: |
| _time | host | _value |
|:----- |:----: | ------:|
| 2020-01-01T00:01:00Z | host1 | 1.0 |
| 2020-01-01T00:01:00Z | host2 | 2.0 |
| 2020-01-01T00:02:00Z | host1 | 1.0 |
| 2020-01-01T00:02:00Z | host2 | 3.0 |
output: |
| _time | host | _value |
|:----- |:----: | ------:|
| 2020-01-01T00:01:00Z | host1 | 1.0 |
| 2020-01-01T00:02:00Z | host1 | 1.0 |
| _time | host | _value |
|:----- |:----: | ------:|
| 2020-01-01T00:01:00Z | host2 | 2.0 |
| 2020-01-01T00:02:00Z | host2 | 3.0 |
histogram:
-
code: |
```js
data
|> histogram(
column: "_value",
upperBoundColumn: "le",
countColumn: "_value",
bins: [100.0, 200.0, 300.0, 400.0],
)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:00:00Z | 250.0 |
| 2020-01-01T00:01:00Z | 160.0 |
| 2020-01-01T00:02:00Z | 150.0 |
| 2020-01-01T00:03:00Z | 220.0 |
| 2020-01-01T00:04:00Z | 200.0 |
| 2020-01-01T00:05:00Z | 290.0 |
| 2020-01-01T01:00:00Z | 340.0 |
output: |
| le | _value |
|:-- | ------:|
| 100.0 | 0.0 |
| 200.0 | 3.0 |
| 300.0 | 6.0 |
| 400.0 | 7.0 |
increase:
-
code: |
```js
data
|> increase()
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1 |
| 2020-01-01T00:02:00Z | 2 |
| 2020-01-01T00:03:00Z | 8 |
| 2020-01-01T00:04:00Z | 10 |
| 2020-01-01T00:05:00Z | 0 |
| 2020-01-01T00:06:00Z | 4 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:02:00Z | 1 |
| 2020-01-01T00:03:00Z | 7 |
| 2020-01-01T00:04:00Z | 9 |
| 2020-01-01T00:05:00Z | 9 |
| 2020-01-01T00:06:00Z | 13 |
join:
-
code: |
```js
t1 = from(bucket: "example-bucket")
|> range(start: 2020-01-01T00:00:00Z)
|> filter(fn: (r) => r.m == "foo")
t2 = from(bucket: "example-bucket")
|> range(start: 2020-01-01T00:00:00Z)
|> filter(fn: (r) => r.m == "bar")
join(tables: {t1: t1, t2: t2}, on: ["_time"])
```
input: |
###### t1
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1 |
| 2020-01-01T00:02:00Z | 2 |
| 2020-01-01T00:03:00Z | 1 |
| 2020-01-01T00:04:00Z | 3 |
###### t2
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 5 |
| 2020-01-01T00:02:00Z | 2 |
| 2020-01-01T00:03:00Z | 3 |
| 2020-01-01T00:04:00Z | 4 |
output: |
| _time | _value_t1 | _value_t2 |
|:----- | ---------:| ---------:|
| 2020-01-01T00:01:00Z | 1 | 5 |
| 2020-01-01T00:02:00Z | 2 | 2 |
| 2020-01-01T00:03:00Z | 1 | 3 |
| 2020-01-01T00:04:00Z | 3 | 4 |
map_math:
-
code: |
```js
data
|> map(fn: (r) => ({ r with _value: r._value * r._value }))
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 2 |
| 2020-01-01T00:02:00Z | 4 |
| 2020-01-01T00:03:00Z | 3 |
| 2020-01-01T00:04:00Z | 5 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 4 |
| 2020-01-01T00:02:00Z | 16 |
| 2020-01-01T00:03:00Z | 9 |
| 2020-01-01T00:04:00Z | 25 |
median:
-
code: |
```js
data
|> median()
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
output: |
| _value |
|:------:|
| 1.5 |
moving_average:
-
code: |
```js
data
|> movingAverage(n: 5)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.2 |
| 2020-01-01T00:03:00Z | 1.8 |
| 2020-01-01T00:04:00Z | 0.9 |
| 2020-01-01T00:05:00Z | 1.4 |
| 2020-01-01T00:06:00Z | 2.0 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:03:00Z | 1.33 |
| 2020-01-01T00:04:00Z | 1.30 |
| 2020-01-01T00:05:00Z | 1.36 |
| 2020-01-01T00:06:00Z | 1.43 |
-
code: |
```js
data
|> timedMovingAverage(every: 5m, period: 10m)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.2 |
| 2020-01-01T00:03:00Z | 1.8 |
| 2020-01-01T00:04:00Z | 0.9 |
| 2020-01-01T00:05:00Z | 1.4 |
| 2020-01-01T00:06:00Z | 2.0 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:02:00Z | 1.000 |
| 2020-01-01T00:04:00Z | 1.333 |
| 2020-01-01T00:06:00Z | 1.325 |
| 2020-01-01T00:06:00Z | 1.150 |
quantile:
-
code: |
```js
data
|> quantile(q: 0.99, method: "estimate_tdigest")
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:01:00Z | 1.0 |
| 2020-01-01T00:02:00Z | 1.0 |
| 2020-01-01T00:03:00Z | 2.0 |
| 2020-01-01T00:04:00Z | 3.0 |
output: |
| _value |
|:------:|
| 3.0 |
rate_of_change:
-
code: |
```js
data
|> derivative(unit: 1m, nonNegative: true)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:00:00Z | 250 |
| 2020-01-01T00:04:00Z | 160 |
| 2020-01-01T00:12:00Z | 150 |
| 2020-01-01T00:19:00Z | 220 |
| 2020-01-01T00:32:00Z | 200 |
| 2020-01-01T00:51:00Z | 290 |
| 2020-01-01T01:00:00Z | 340 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:04:00Z | |
| 2020-01-01T00:12:00Z | |
| 2020-01-01T00:19:00Z | 10.0 |
| 2020-01-01T00:32:00Z | |
| 2020-01-01T00:51:00Z | 4.74 |
| 2020-01-01T01:00:00Z | 5.56 |
-
code: |
```js
import "experimental/aggregate"
data
|> aggregate.rate(every: 20m, unit: 1m)
```
input: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:00:00Z | 250 |
| 2020-01-01T00:04:00Z | 160 |
| 2020-01-01T00:12:00Z | 150 |
| 2020-01-01T00:19:00Z | 220 |
| 2020-01-01T00:32:00Z | 200 |
| 2020-01-01T00:51:00Z | 290 |
| 2020-01-01T01:00:00Z | 340 |
output: |
| _time | _value |
|:----- | ------:|
| 2020-01-01T00:20:00Z | |
| 2020-01-01T00:40:00Z | 10.0 |
| 2020-01-01T01:00:00Z | 4.74 |
| 2020-01-01T01:20:00Z | 5.56 |
regular_expressions:
-
code: |
```js
data
|> filter(fn: (r) => r.tag =~ /^foo[1-3]/)
```
input: |
| _time | tag | _value |
|:----- |:----:| ------:|
| 2020-01-01T00:01:00Z | foo1 | 1.0 |
| 2020-01-01T00:02:00Z | foo5 | 1.2 |
| 2020-01-01T00:03:00Z | bar3 | 1.8 |
| 2020-01-01T00:04:00Z | foo3 | 0.9 |
| 2020-01-01T00:05:00Z | foo2 | 1.4 |
| 2020-01-01T00:06:00Z | bar1 | 2.0 |
output: |
| _time | tag | _value |
|:----- |:----:| ------:|
| 2020-01-01T00:01:00Z | foo1 | 1.0 |
| 2020-01-01T00:04:00Z | foo3 | 0.9 |
| 2020-01-01T00:05:00Z | foo2 | 1.4 |
sort_limit:
-
code: |
```js
data
|> sort(columns: ["host", "_value"])
|> limit(n: 4)
```
input: |
| _time | host | _value |
|:----- |:----:| ------:|
| 2020-01-01T00:01:00Z | A | 1.0 |
| 2020-01-01T00:02:00Z | B | 1.2 |
| 2020-01-01T00:03:00Z | A | 1.8 |
| 2020-01-01T00:04:00Z | B | 0.9 |
| 2020-01-01T00:05:00Z | B | 1.4 |
| 2020-01-01T00:06:00Z | B | 2.0 |
output: |
| _time | host | _value |
|:----- |:----:| ------:|
| 2020-01-01T00:03:00Z | A | 1.8 |
| 2020-01-01T00:01:00Z | A | 1.0 |
| 2020-01-01T00:06:00Z | B | 2.0 |
| 2020-01-01T00:05:00Z | B | 1.4 |

View File

@ -1,5 +1,7 @@
{{ $type := .Get "type" | default "articles" }}
{{ $show := .Get "show" | default "all" }}
{{ $readMore := .Get "readmore" | default false }}
{{ $hr := .Get "hr" | default false }}
{{ if eq $show "all" }}
{{ .Scratch.Set "pages" (union .Page.Pages .Page.Sections) }}
@ -11,56 +13,90 @@
{{ $pages := .Scratch.Get "pages" }}
<div class="children-links">
{{ if eq $type "articles" }}
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
<h3 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h3>
<p>
{{- if .Description }}{{- .Description | markdownify -}}
{{ else }}{{- .Summary | markdownify -}}
{{ end -}}
</p>
{{ if .Params.list_image }}
{{ $img := .Params.list_image }}
{{ if (fileExists ( print "/static" $img )) }}
{{ with (imageConfig ( print "/static" $img )) }}
{{ $imageWidth := div .Width 3 }}
<img src='{{ $img }}' width='{{ $imageWidth }}' />
<div class="children-links">
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
<h3 id="{{ anchorize $title }}"><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a></h3>
<p>
{{- if .Description }}{{- .Description | markdownify -}}
{{ else }}{{- .Summary | markdownify -}}
{{ end -}}
</p>
{{ if .Params.list_image }}
{{ $img := .Params.list_image }}
{{ if (fileExists ( print "/static" $img )) }}
{{ with (imageConfig ( print "/static" $img )) }}
{{ $imageWidth := div .Width 3 }}
<img src='{{ $img }}' width='{{ $imageWidth }}' />
{{ end }}
{{ else }}
<img src='{{ $img }}'/>
{{ end }}
{{ else }}
<img src='{{ $img }}'/>
{{ end }}
{{ end }}
{{ if .Params.list_code_example }}
{{ .Params.list_code_example | markdownify }}
{{ end }}
{{ if .Params.list_code_example }}
{{ .Params.list_code_example | markdownify }}
{{ end }}
{{ if .Params.list_query_example }}
{{ range (index .Site.Data.query_examples .Params.list_query_example) }}
{{ .code | markdownify }}
<div class="flex-wrapper">
<div class="flex-container half">
<h6>Input:</h6>
{{ .input | markdownify }}
</div>
<div class="flex-container half">
<h6>Output:</h6>
{{ .output | markdownify }}
</div>
</div>
{{ end }}
{{ end }}
{{ if and (eq $readMore true) ( or (isset .Params "list_query_example") (isset .Params "list_code_example") ) }}
<p style="text-align: right"><em><a href="{{ $url }}" target="{{ $target }}">Read more <span class="icon-chevron-right"></span></a></em></p>
{{ end }}
{{ if eq $hr true }}
<hr />
{{ end }}
{{ end }}
</div>
{{ else if (eq $type "functions") }}
<ul>
{{ range $pages.ByWeight }}
{{ $title := replaceRE `\ function` "" .Title }}
<li><a href="{{ .RelPermalink }}">{{ if .Params.list_title }}{{ .Params.list_title }}{{ else }}{{ $title }}{{ end }}</a></li>
{{ end }}
<ul>
<div class="children-links">
<ul>
{{ range $pages.ByWeight }}
{{ $title := replaceRE `\ function` "" .Title }}
<li><a href="{{ .RelPermalink }}">{{ if .Params.list_title }}{{ .Params.list_title }}{{ else }}{{ $title }}{{ end }}</a></li>
{{ end }}
</ul>
</div>
{{ else if (eq $type "list") }}
<div class="children-links">
<ul>
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
{{ end }}
</ul>
</div>
{{ else if (eq $type "anchored-list") }}
<ul>
{{ range $pages.ByWeight }}
{{ $title := cond ( isset .Params "list_title" ) .Params.list_title .Title }}
{{ $url := cond ( isset .Params "external_url" ) .Params.external_url .RelPermalink }}
{{ $target := cond ( isset .Params "external_url" ) "_blank" "" }}
{{ $note := cond ( isset .Params "list_note" ) (print "<span class='list-note'>" .Params.list_note "</span>") "" }}
<li><a href="{{ $url }}" target="{{ $target }}">{{ $title }}</a> {{ $note | markdownify }}</li>
<li><a href="#{{ anchorize $title }}">{{ $title }}</a></li>
{{ end }}
<ul>
</ul>
{{ end }}
</div>