fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
123 stars 17 forks source link

Feature Request: Filtering with variables holding multiple values should not be so hard #90

Closed teodesian closed 1 year ago

teodesian commented 2 years ago

Describe the bug Currently to filter via variable with multiple values we need to do some string processing, as the var generally interpolates as:

// Multivariate
{ a, b, c }
// single
a

The most straightforward where clause which should work here would be: field IN $variable

This would require the variable to be interpolated as:

// Multivariate
( 'a', 'b', 'c')
// single
('a')

The way to process things under the status quo requires replace() of the braces and splitting the string via recursive CTE to quote the vars.

To Reproduce Steps to reproduce the behavior:

I've put the entire environment I used to observe the problem up on github: https://github.com/teodesian/memmon

Follow the installation instructions therein.

Versions (please complete the following information):

fr-ser commented 2 years ago

Maybe I misunderstand the issue but I am under the impression that this (through Grafana features) should already be possible. I have an example dashboard with this query

with data(time, temperature, city) AS (VALUES
(724125600, 10, 'London'), (724161600, 11, 'London'),
(724161600, 20, 'New York'), (724197600, 21, 'New York'),
(724125600, 25, 'Washington'), (724197600, 26, 'Washington')
) SELECT * from data
WHERE city in (${cities:singlequote})
order by time

And this as a query variable

SELECT * FROM (VALUES ('London'), ('New York'), ('Washington'))

This works as expected, or is there something else you mean?

teodesian commented 1 year ago

This works great! Thank you.

I think this should be added to the examples. I'll create a PR along these lines shortly.

teodesian commented 1 year ago

https://github.com/fr-ser/grafana-sqlite-datasource/pull/93