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

'opt.value.match is not a function' error when using array variable. #169

Closed
ryanmickler opened this issue Jan 23, 2020 · 1 comment · Fixed by #213
Closed

'opt.value.match is not a function' error when using array variable. #169

ryanmickler opened this issue Jan 23, 2020 · 1 comment · Fixed by #213
Assignees

Comments

@ryanmickler
Copy link

ryanmickler commented Jan 23, 2020

https://github.com/Vertamedia/clickhouse-grafana/blob/50d46ef5138f5b5d8098c1cbacc7f0d3f56e16a9/src/sql_query.ts#L548

I'm getting an error when trying to use an array variable.

My variable is called modcha and is a query variable, set up as follows.
SELECT DISTINCT [Module, Channel] FROM mydb.my_table
This works fine, and see the variables getting correctly populated [0,1], [1,1], [2,0],...

However, in the visualization, im trying to use:
... WHERE [Module, Channel] == [ $modcha ] ...
And I get the error
opt.value.match is not a function

Using grafana v6.2.5, and installing clickhouse plugin from the cli
grafana-cli plugins install vertamedia-clickhouse-datasource

UPDATE:

there's even more crazy stuff going on. if I write
... WHERE [Module, Channel] == ${modcha:json} ...
i no longer get the opt.value.match error, however the generated SQL is
WHERE [Module, Channel] == [[1,0],[1,1],[2,0],[2,1],[3,0],[3,1],[4,0],[4,1],[5,0],[5,1],[6,0],[6,1],[7,0],[7,1],[8,0],[8,1]]
i.e. its not using an element, but the whole list of modcha values.

UPDATE UPDATE:
found a problem. I had enabled the All option for my variable, hence i was seeing the whole list. Disabling the All option fixed that.
I got this to work as i wanted:
... WHERE [Module, Channel] == [${modcha:csv}] ...

@Slach Slach self-assigned this Jun 26, 2020
Slach added a commit that referenced this issue Jun 28, 2020
fix #199
also partial solution for #169, 
array variables need investigation on Grafana Core
@Slach Slach closed this as completed in #213 Jul 2, 2020
@Slach
Copy link
Collaborator

Slach commented Jul 2, 2020

@ryanmickler unfortunately, grafana 7.x broke template variables for cases when the data source plugin return each variable value as ["string", "string"], but for grafana 6.7.x latest version of master works fine

as a workaround, we can use
using SELECT arrayStringConcat(array_field,",") ... for template variable and WHERE arrayStringConcat([field1, field2], ",") IN (${variable_name})
https://clickhouse.tech/docs/en/sql-reference/functions/splitting-merging-functions/#arraystringconcatarr-separator

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Jul 7, 2020
# 2.0.2 (2020-07-07)

## Enhancements:
* add alerts support for Windows and MacOSX
* improve ad-hoc filters for query field values as `SELECT DISTINCT field AS value FROM db.table LIMIT 300`, Altinity/clickhouse-grafana#222
* add the ability to multiple JOIN parsing Altinity/clickhouse-grafana#206
* multiple improvements for docker-compose environments, add automatic dashboards and data source provisions which help to reproduce most of the corner cases which happens in Grafana + ClickHouse

## Fixes:
* apply a workaround for UTC timezone for Date and DateTime columns in grafana dashboards Altinity/clickhouse-grafana#117
* clear documentation about timestamp term for $from and $to Altinity/clickhouse-grafana#115
* fix AST parsing corner case in `WHERE [test, 'test']` "," was skipped, fix ah-doc AST FROM recursive parsing Altinity/clickhouse-grafana#99
* fix corner cases for table functions parsing when Adhoc filter applied Altinity/clickhouse-grafana#130
* fix multiple grammar issues in README.md
* fix convert rules for Float, Decimal columns from Clickhouse to Grafana Table plugin Altinity/clickhouse-grafana#199
* fix corner cases when Grafana Template variable value represented as an array of strings Altinity/clickhouse-grafana#169
* fix AST parsing corner cases for $macroFunctions correct position for FROM statement Altinity/clickhouse-grafana#187

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