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.
When evaluating fromTime first, the match is correct:
Additional Info:
Working:
Broken: