select * from foo where ( date >= $__fromTime and date <= $__toTime ) limit 100
Output:
select * from foo where ( date >= toDateTime(intDiv(-6795364578871,1000)) ) limit 100
Expected Output:
select * from foo where ( date >= toDateTime(intDiv(-6795364578871,1000)) and date <= toDateTime(intDiv(-6795364578871,1000)) )
Reason:
It fails when it is evaluating toTime (the second macro inside the parentheses) and then fromTime. The match will contain the already evaluated macro and call strings.Replace onto it, which will replace it and create the wrong query.
When evaluating fromTime first, the match is correct:
While debugging the Unit-Tests of https://github.com/grafana/clickhouse-datasource I found out that sqlds macro match is too lax. This is basically an extension of https://github.com/grafana/sqlds/issues/53. The biggest issue is that it does not fail always, because it is dependent on the order of the map, which is not stable
Input:
select * from foo where ( date >= $__fromTime and date <= $__toTime ) limit 100
Output:
select * from foo where ( date >= toDateTime(intDiv(-6795364578871,1000)) ) limit 100
Expected Output:
select * from foo where ( date >= toDateTime(intDiv(-6795364578871,1000)) and date <= toDateTime(intDiv(-6795364578871,1000)) )
Reason:
It fails when it is evaluating toTime (the second macro inside the parentheses) and then fromTime. The match will contain the already evaluated macro and call strings.Replace onto it, which will replace it and create the wrong query.![image](https://user-images.githubusercontent.com/5741401/210878276-75f88716-fe48-472d-87b5-525e29b9852f.png)
When evaluating fromTime first, the match is correct:![image](https://user-images.githubusercontent.com/5741401/210878734-e5fb0f2d-eda1-4b9a-9fee-c8ce36f32f0a.png)
Additional Info:
Working:
Broken: