Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro matching is too lax #82

Closed
fionera opened this issue Jan 5, 2023 · 0 comments · Fixed by #83
Closed

Macro matching is too lax #82

fionera opened this issue Jan 5, 2023 · 0 comments · Fixed by #83

Comments

@fionera
Copy link
Contributor

fionera commented Jan 5, 2023

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 #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

When evaluating fromTime first, the match is correct:
image

Additional Info:

Working:

image

Broken:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant