fr-ser / grafana-sqlite-datasource

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

Fail to get type of "Expressions" when result is empty. #63

Closed n-arakawa closed 2 years ago

n-arakawa commented 2 years ago

Describe the bug I'm not sure this is a bug of this plugin or SQLite itself, I got 'number' type for "Expression" column even though its "Affinity" is "TEXT"

https://www.sqlite.org/datatype3.html#affinity_of_expressions

To Reproduce

With grafana explorer, type in query.

SELECT "a" WHERE 1=0
or SELECT CAST("a" as TEXT) WHERE 1=0

The type of the column is 'number'. number

Without WHERE 1=0 , I got "string" type SELECT CAST("a" as TEXT)
text

Versions (please complete the following information):

fr-ser commented 2 years ago

The problem might be that the plugin needs to determine the data type from the data itself. When there is no data this is not easily done and string is probably just the default.

Can you explain the issue this is causing?

n-arakawa commented 2 years ago

The problem might be that the plugin needs to determine the data type from the data itself.

Types of database column is correct even with empty result. Therefor I guess SQLite has a API to get type information of columns. I'm not sure whether there is corresponding API for "Expression" column.

Can you explain the issue this is causing?

My use case is quite a edge one,

I found work around for this. I use "UNION ALL" in SQL and remove "Merge" Transformation. Everything is fine now.

fr-ser commented 2 years ago

Yeah. I would also suggest to do this in SQL if possible. UNION ALL seems like the best way to go here.

If this is causing more issues, let's revisit 👌🏻