grafana / sqlds

A package that assists writing SQL-driven datasources
Apache License 2.0
17 stars 12 forks source link

- fix parsing macros in queries #74

Closed sasklacz closed 1 year ago

sasklacz commented 1 year ago

This was originally reported as a bug in clickhouse plugin https://github.com/grafana/clickhouse-datasource/issues/195 . Whenever there are are multiple parentheses in the query, parser is having a hard time finding the end of the macro command.

This solution is maybe not the prettiest, but I think it's pretty solid. It first cleans up the input query from any empty spaces before the parentheses. Then it parses the query looking for macros with parentheses and adds an empty space at the last parenthesis, so that we can still use our original regex for finding the macro AND arguments (which is now bulletproof, as before it could grab a bracket belonging to a select, or other outer command).

Added new test cases and tested in clickhouse datasource plugin.

Do we update the version anywhere ?

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

sasklacz commented 1 year ago

Got rid of the regex for parsing macros as suggested by @andresmgot