From 59ffd9571e239db0b48db7a86d7233f53f2db9e9 Mon Sep 17 00:00:00 2001 From: Brendan O'Handley Date: Wed, 26 Oct 2022 19:01:45 -0400 Subject: [PATCH] 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 --- .../transform-data/index.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/sources/panels-visualizations/query-transform-data/transform-data/index.md b/docs/sources/panels-visualizations/query-transform-data/transform-data/index.md index 21fa3919b15..c38203a71d2 100644 --- a/docs/sources/panels-visualizations/query-transform-data/transform-data/index.md +++ b/docs/sources/panels-visualizations/query-transform-data/transform-data/index.md @@ -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'`
+`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.