Closed ethack closed 1 year ago
Thank you for the detailed info, I was able to reproduce all of these findings.
I ran the debugger in the plugin and it appears that the macros ARE being interpolated correctly, in fact the string looks the same as when you manually entered the functions from the working query:
-- Debugger value for line https://github.com/grafana/sqlds/blob/main/macros.go#L262
SELECT *
FROM dummy(fromTime=toDateTime(intDiv(1695237644505,1000)), toTime=toDateTime(intDiv(1695410444506,1000)))
This never gets sent back to the query inspector since the query failed, so you wouldn't be able to see this without debugging the plugin backend or checking the query_log
table.
Maybe this is a shortcoming of parameterized views in ClickHouse and deserves a feature request there.
I also tried running this directly in the ClickHouse client, and it gives the same error. It seems like this is something that should be possible to do, but for now it doesn't work. I would recommend opening an issue in the ClickHouse repository (make sure it's not a duplicate)
But in the meantime, any thoughts on a workaround for the Grafana data source?
Given the issue with the parameter values, I don't think there is a workaround currently. Is it possible for you to use the original query used to create the parameterized view?
Given what you've said @SpencerTorres it sounds like this isn't a datasource issue, are we fine to close this?
Related to this issue, would it be possible to have a macro that outputs plain dates which are specified in the alert/dashboard parameters ?
SELECT *
FROM dummy(fromTime=$__fromStartTime, toTime=$__toEndTime)
and the values are replaced as the following:
SELECT *
FROM dummy(fromTime='2024-04-10 01:00:00', toTime='2024-04-10 03:00:00')
What happened:
The
$__fromTime
and$__toTime
macros aren't expanded (properly) in a parameterized view's parameters. I'm not sure if any others work.What you expected to happen:
I'd expect
$__fromTime
and$__toTime
and other macros to work in a view's parameters like they would in a normalWHERE
clause.How to reproduce it (as minimally and precisely as possible):
Create a parameterized view:
Queries go into Explore with the time picker set to sometime in 2023 (I had last 2 days set).
This works when I manually specify the parameters but use the macros in the
WHERE
:Query inspector shows this as the final query:
This doesn't work when I use the macros directly in the view parameters:
I took the expanded values from the earlier query and inserted directly into the parameterized view and this doesn't work either.
It seems that no functions work in this context.
Nor math (though I think this would normally get converted to the
divide
function anyway):But literals do:
Maybe this is a shortcoming of parameterized views in ClickHouse and deserves a feature request there. But in the meantime, any thoughts on a workaround for the Grafana data source?
Anything else we need to know?:
Environment: