Hey,

I'm working on a product that executes arbitrary SQL on a "data source".
A data source implements a SQL language, for instance, it can be MySQL,
Pinot, BigQuery, etc...
I'd like to introduce a macro language on top of the SQL.
Very similar to what is done in grafana:
https://grafana.com/docs/grafana/latest/datasources/mysql/#macros
These macros would be resolved before the SQL is executed on the data
source.

A macro looks like a function but is a string replacement, for instance:
 __timeFilter(timeColumn, start, end) -->  timeColumn>=start and
timeColumn<end

Grafana uses regex replacements, but I'm considering parsing the SQL with
Calcite to apply the macros safely and manage nested macros/functions.

--> Is this a good use case for Calcite? What seemed interesting to me is
that Calcite has all those SqlDialect implementations.

I had this flow in mind:
1. get the SqlDialect of my datasource
*2.* add to this dialect my custom macros (add to an SqlFunction list? )
3. parse
4. replace
5. rebuild

I'm wondering if 2. is possible? I'm not sure to understand how I could add
a list of SqlFunction to a dialect, or build a new dialect from an existing
one dynamically.

If you've taken the time to read this message, thanks a lot!
Have a nice day.

-- 
[image: Startree] <https://www.startree.ai/>

Cyril de Catheu

Software Engineer, StarTree

[email protected] | +33 684-829-908

[image: Linkedin] <https://www.linkedin.com/in/cyril-de-catheu/>[image:
Twitter] <https://twitter.com/deCatheu>

Reply via email to