From faeeccfc0ed0aa947493c6116238b65ed35442da Mon Sep 17 00:00:00 2001 From: Scott Lepper Date: Fri, 14 Jan 2022 17:00:56 -0500 Subject: [PATCH] change time macros names (#39) * change name * update read me --- CHANGELOG.md | 4 ++++ README.md | 14 +++++++------- package.json | 2 +- pkg/macros/macros_test.go | 3 ++- pkg/plugin/driver.go | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03541060..6778ef8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.6 + +Bug - Change time template variable names. + ## 0.9.5 Bug - Fix global template variables. diff --git a/README.md b/README.md index a79a720a..d62e520d 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,13 @@ FROM test_data WHERE $__timeFilter(date_time) ``` -| Macro example | Description | -| ------------------------ | ---------------------------------------------------------------------------------- | -| *$__timeFilter(dataRow)* | Will be replaced by a time range filter using the specified name. | -| *$__from* | Will be replaced by the start of the currently active time range filter selection. | -| *$__to* | Will be replaced by the end of the currently active time range filter selection. | -| *$__table* | Will be replaced by the table in use. | -| *$__column* | Will be replaced by the column in use. | +| Macro example | Description | +| -- | --| +| *$__timeFilter(dataRow)* | Will be replaced by a time range filter using the specified name. | +| *$__fromTime* | Replaced by the start of time range in ms wrapped by toDateTime function. Example: toDateTime(intDiv(1415792726371,1000)) | +| *$__toTime* | Replaced by the end of time range in ms wrapped by toDateTime function. Example: toDateTime(intDiv(1415792726371,1000)) | +| *$__table* | Will be replaced by the table in use. | +| *$__column* | Will be replaced by the column in use. | The plugin also supports notation using braces {}. Use this notation when queries are needed inside parameters. diff --git a/package.json b/package.json index dcd47f44..d5046838 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clickhouse-datasource", - "version": "0.9.5", + "version": "0.9.6", "description": "Clickhouse Datasource", "scripts": { "build": "grafana-toolkit plugin:build", diff --git a/pkg/macros/macros_test.go b/pkg/macros/macros_test.go index 1fe1be12..87fc8b4f 100644 --- a/pkg/macros/macros_test.go +++ b/pkg/macros/macros_test.go @@ -18,7 +18,7 @@ func TestMacroFromTimeFilter(t *testing.T) { From: from, To: to, }, - RawSQL: "select foo from foo where bar > $__from", + RawSQL: "select foo from foo where bar > $__fromTime", } tests := []struct { want string @@ -50,6 +50,7 @@ func TestMacroToTimeFilter(t *testing.T) { From: from, To: to, }, + RawSQL: "select foo from foo where bar > $__toTime", } tests := []struct { want string diff --git a/pkg/plugin/driver.go b/pkg/plugin/driver.go index 43d6d08b..03c0c62a 100644 --- a/pkg/plugin/driver.go +++ b/pkg/plugin/driver.go @@ -116,8 +116,8 @@ func (h *Clickhouse) Converters() []sqlutil.Converter { // Macros returns list of macro functions convert the macros of raw query func (h *Clickhouse) Macros() sqlds.Macros { return map[string]sqlds.MacroFunc{ - "from": macros.FromTimeFilter, - "to": macros.ToTimeFilter, + "fromTime": macros.FromTimeFilter, + "toTime": macros.ToTimeFilter, "timeFilter": macros.TimeFilter, "table": macros.Table, "column": macros.Column,