-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: Add AST analyzer middleware to optionally rewrite queries before execution #55
feat: Add AST analyzer middleware to optionally rewrite queries before execution #55
Conversation
* feat: Add AST analyzer middleware * fix: Remove redundant ast_analyzer call * chore: Variable does not need to be mutable
This is used in the SQLite Table Provider to perform a non-trivial rewrite of interval expressions to use the SQLite native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to this would be to implement a FederationProvider
directly for execution engines with partial SQL dialect support. Maybe we could look into making that more trivial at some point.
I'll accept this for now since the above would be more effort and there is a default implementation that should not get in the way.
Apologies for commenting in this old thread, but I'm working on learning about DataFusion's I'm exploring replacing the sql-generation system we have in VegaFusion with |
Hello @jonmmease, |
@jonmmease maybe there are already table providers in datafusion-contrib/datafusion-table-providers that meet your needs? These also implement federation. That are used if you register the federation optimizer. |
Thanks @backkem, yes these table providers look great, and I'm excited to learn more about how federation works! I'm thinking about eventually adding support for some additional dialects (like Clickhouse, Spark, MSSQL, etc) and wondering if this should primarily be contributed upstream in the |
RE where to land things: it's a good question. Right now I think we have roughly:
Things can evolve but this is the balance that emerged so far. I'm happy to host more plan re-writing tools/logic that is federation related in this repo. |
Thanks for that context @backkem, I appreciate it and it's very helpful. As I've thought about it, it does make sense for the semantic customization of dialects to live alongside the table provider implementations for the sake of testing the generated SQL. |
Yeah, I still think its not 100% clear where the responsibility of the Unparser dialect ends and where something like the AST rewriter in the specific implementation begins. Like @backkem, I tend to think that the core Unparser should mostly be focused on syntactical differences between the dialects whereas more complex differences in how, e.g., functions work can be implemented by the AST rewriter (as we did for handling intervals in SQLite: datafusion-contrib/datafusion-table-providers#85) |
Adds an AST analyzer to the
SQLExecutor
trait to allow modifying the query AST before execution.