From 8a1bd2ee223410b09fe0833f9de2749bb74c9776 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Tue, 6 Mar 2018 09:24:36 +0100 Subject: [PATCH] docs: fill for mysql/postgres ref #10138 --- docs/sources/features/datasources/mysql.md | 14 ++++++++++++++ docs/sources/features/datasources/postgres.md | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/docs/sources/features/datasources/mysql.md b/docs/sources/features/datasources/mysql.md index 7fae7441b6d..6c15006949e 100644 --- a/docs/sources/features/datasources/mysql.md +++ b/docs/sources/features/datasources/mysql.md @@ -50,6 +50,7 @@ Macro example | Description *$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *FROM_UNIXTIME(1494410783)* *$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *FROM_UNIXTIME(1494497183)* *$__timeGroup(dateColumn,'5m')* | Will be replaced by an expression usable in GROUP BY clause. For example, *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed) as time_sec,* +*$__timeGroup(dateColumn,'5m',0)* | Same as above but with a fill parameter so all null values will be converted to the fill value (all null values would be set to zero using this example). *$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamp. For example, *dateColumn > 1494410783 AND dateColumn < 1494497183* *$__unixEpochFrom()* | Will be replaced by the start of the currently active time selection as unix timestamp. For example, *1494410783* *$__unixEpochTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183* @@ -119,6 +120,19 @@ GROUP BY 1, metric_name ORDER BY 1 ``` +Example using the fill parameter in the $__timeGroup macro to convert null values to be zero instead: + +```sql +SELECT + $__timeGroup(atimestamp,'24h',0) as time_sec, + avg(afloat) as value, + avarchar as metric +FROM testdata.grafana_metrics +WHERE $__timeFilter(atimestamp) +GROUP BY 1, avarchar +ORDER BY 1 +``` + Currently, there is no support for a dynamic group by time based on time range & panel width. This is something we plan to add. diff --git a/docs/sources/features/datasources/postgres.md b/docs/sources/features/datasources/postgres.md index 7d52df2fd3e..270640a93dc 100644 --- a/docs/sources/features/datasources/postgres.md +++ b/docs/sources/features/datasources/postgres.md @@ -49,6 +49,7 @@ Macro example | Description *$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *to_timestamp(1494410783)* *$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *to_timestamp(1494497183)* *$__timeGroup(dateColumn,'5m')* | Will be replaced by an expression usable in GROUP BY clause. For example, *(extract(epoch from dateColumn)/300)::bigint*300 AS time* +*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so all null values will be converted to the fill value (all null values would be set to zero using this example). *$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamp. For example, *dateColumn > 1494410783 AND dateColumn < 1494497183* *$__unixEpochFrom()* | Will be replaced by the start of the currently active time selection as unix timestamp. For example, *1494410783* *$__unixEpochTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183* @@ -103,6 +104,20 @@ GROUP BY time ORDER BY time ``` +Example using the fill parameter in the $__timeGroup macro to convert null values to be zero instead: + +```sql +SELECT + $__timeGroup("createdAt",'5m',0), + sum(value) as value, + measurement +FROM public.grafana_metric +WHERE + $__timeFilter("createdAt") +GROUP BY time, measurement +ORDER BY time +``` + Example with multiple columns: ```sql