Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template variable expansion default type changed in 2.0.2? #252

Closed
banburybill opened this issue Jul 24, 2020 · 6 comments · Fixed by #253
Closed

Template variable expansion default type changed in 2.0.2? #252

banburybill opened this issue Jul 24, 2020 · 6 comments · Fixed by #253
Assignees

Comments

@banburybill
Copy link

I have multi-value template variables. With Grafana 7.1.0 and plugin 2.0.1, plain $var expands as a sqlstring, so as 'one', 'two', 'three'. With 2.0.2 this becomes ['one', 'two', 'three']. I'm using this in SELECT field WHERE field IN ($var), so ClickHouse becomes unhappy.

With 2.0.2, I can explicitly request sqlstring and replace $var with ${var:sqlstring} to restore previous behaviour. Unfortunately I need to work with Grafana 6.7.4 as well, and using 6.7.4 with 2.0.2 ${var:sqlstring} produces {one,two,three}.

(I just noticed 2.0.3 appeared while I was composing this - I haven't tested on that yet).

@Slach
Copy link
Collaborator

Slach commented Jul 24, 2020

@banburybill
which version of ClickHouse Server do you use?
could you share the plugin generated SQL query (query inspector -> raw query) ?

before change
I tried

 SELECT 'one' IN (['one','two','three']);

and it was successful

┌─in('one', ['one', 'two', 'three'])─┐
│                                  1 │
└────────────────────────────────────┘

if you need multiple variable values as field names
so just try to use quick workaround ${var:csv}

@banburybill
Copy link
Author

Sorry, I should have included that. Yes, it's a ClickHouse version issue. We're on a carefully selected 19.16 version, 19.16.4.12.

FWIW, here's logs of the actual queries. With 2.0.1:
executeQuery: (from xxx) SELECT region_name FROM wombat.node_text WHERE NOT bitTest(flags, 0) AND server_name IN ('IMRS','Sinodun') GROUP BY region_name FORMAT JSON

With 2.0.2:
executeQuery: Code: 53, e.displayText() = DB::Exception: Type mismatch in IN or VALUES section. Expected: String. Got: Array (version 19.16.4.12 (official build)) (from xxx) (in query: SELECT region_name FROM wombat.node_text WHERE NOT bitTest(flags, 0) AND server_name IN (['IMRS','Sinodun']) GROUP BY region_name FORMAT JSON

Trying your example on the latest 20.3LTS works. With our 19.16:

`:) select 'one' in (['one', 'two', 'three']);

SELECT 'one' IN (['one', 'two', 'three'])

Received exception from server (version 19.16.4):
Code: 53. DB::Exception: Received from localhost:9000. DB::Exception: Type mismatch in IN or VALUES section. Expected: String. Got: Array.`

I suspect 19.14LTS will do the same.

@banburybill
Copy link
Author

Altinity's latest recommended stable ClickHouse is 20.3.12.112, a recommendation made less than a month ago. Previous Altinity recommended stable versions were both 19.16 releases. We'll think about updating, but there is a case for retaining ClickHouse v19 support.

@Slach
Copy link
Collaborator

Slach commented Jul 24, 2020

oops ;(
look like we need to apply fix which continues to solve #169, but stay works for old ClickHouse versions

@banburybill thanks for open the issue

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Jul 25, 2020
## Fixes:
  * fix multi-value variables behavior - Altinity/clickhouse-grafana#252

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
@Slach
Copy link
Collaborator

Slach commented Jul 25, 2020

Hi @banburybill, could you check the latest master branch?

also please subscribe to grafana/grafana-plugin-repository#690 for notifying when this fix will available https://grafana.com/grafana/plugins/vertamedia-clickhouse-datasource

@Slach Slach self-assigned this Jul 25, 2020
@banburybill
Copy link
Author

Yes, latest master fixes my problem. Thanks!

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Aug 13, 2020
# 2.1.0 (2020-08-13)

## Enhancement:
* add "Skip comments" checkbox to query editor to pass SQL comments to server, fix Altinity/clickhouse-grafana#265
* add setup notes for Grafana 7.x to README
* add SQL preprocessing logic on browser side with <% js code subset %>, Altinity/clickhouse-grafana#186, thanks @fgbogdan
* improve alerts query processing for use case when `query(query_name, from, to)` time range is less than visible dashboard time range, see Altinity/clickhouse-grafana#237
* improve alerts json parsing in golang part for case when we have string fields in response which interprets as series name, see Altinity/clickhouse-grafana#230
* properly parsing POST queries in golang part of plugin, Altinity/clickhouse-grafana#228, thanks @it1804

## Fixes:
* fix corner cases for $macro + subquery, see Altinity/clickhouse-grafana#276 and Altinity/clickhouse-grafana#277
* fix parallel query execution, see Altinity/clickhouse-grafana#273
* fix identifiers quotes, see Altinity/clickhouse-grafana#276, Altinity/clickhouse-grafana#277
* fix plugin.json for pass `grafana-plugin-repository` plugin validator
* fix multi-value variables behavior - Altinity/clickhouse-grafana#252
* add Vagrantfile for statefull environment and allow to upgrade scenario like  grafana 7.1.0 + grafana-cli upgrade-all
  * fix Altinity/clickhouse-grafana#244
  * fix Altinity/clickhouse-grafana#243
* add multiple dashboard examples for github issues:
  * fix Altinity/clickhouse-grafana#240
  * fix Altinity/clickhouse-grafana#135
  * fix Altinity/clickhouse-grafana#245
  * fix Altinity/clickhouse-grafana#238
  * fix Altinity/clickhouse-grafana#232
  * fix Altinity/clickhouse-grafana#127
  * fix Altinity/clickhouse-grafana#141

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants