Transformations : Add partition by values to transformation docs (#57697)

* add partition by values to tranformation docs

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>

* include leon's suggestions

* include leon's suggestions

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

* Update docs/sources/panels-visualizations/query-transform-data/transform-data/index.md

Co-authored-by: Kim Nylander <104772500+knylander-grafana@users.noreply.github.com>
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Brendan O'Handley 2022-10-26 19:01:45 -04:00 committed by GitHub
parent 7346280316
commit 59ffd9571e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -501,6 +501,38 @@ In the example below, I hid the value field and renamed Max and Min.
{{< figure src="/static/img/docs/transformations/organize-fields-stat-example-7-0.png" class="docs-image--no-shadow" max-width= "1100px" >}}
### Partition by values
This transformation can help eliminate the need for multiple queries to the same datasource with different `WHERE` clauses when graphing multiple series. Consider a metrics SQL table with the following data:
| Time | Region | Value |
| ------------------- | ------ | ----- |
| 2022-10-20 12:00:00 | US | 1520 |
| 2022-10-20 12:00:00 | EU | 2936 |
| 2022-10-20 01:00:00 | US | 1327 |
| 2022-10-20 01:00:00 | EU | 912 |
Prior to v9.3, if you wanted to plot a red trendline for US and a blue one for EU in the same TimeSeries panel, you would likely have to split this into two queries:
`SELECT Time, Value FROM metrics WHERE Time > '2022-10-20' AND Region='US'`<br>
`SELECT Time, Value FROM metrics WHERE Time > '2022-10-20' AND Region='EU'`
This also requires you to know ahead of time which regions actually exist in the metrics table.
With the _Partition by values_ transformer, you can now issue a single query and split the results by unique values in one or more columns (`fields`) of your choosing. The following example uses `Region`.
`SELECT Time, Region, Value FROM metrics WHERE Time > '2022-10-20'`
| Time | Region | Value |
| ------------------- | ------ | ----- |
| 2022-10-20 12:00:00 | US | 1520 |
| 2022-10-20 01:00:00 | US | 1327 |
| Time | Region | Value |
| ------------------- | ------ | ----- |
| 2022-10-20 12:00:00 | EU | 2936 |
| 2022-10-20 01:00:00 | EU | 912 |
### Reduce
The _Reduce_ transformation applies a calculation to each field in the frame and return a single value. Time fields are removed when applying this transformation.