Repository navigation
Allow a SessionState to carry a custom sqlparser dialect - #26437
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26437 +/- ##
==========================================
- Coverage 82.89% 82.89% -0.01%
==========================================
Files 1154 1154
Lines 457620 457698 +78
Branches 457620 457698 +78
==========================================
+ Hits 379352 379415 +63
- Misses 55262 55265 +3
- Partials 23006 23018 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
89c8cc7 to
05b4aa3
Compare
05b4aa3 to
06f67b1
Compare
|
|
||
| /// Set the [`sqlparser`] dialect object used to parse SQL. | ||
| /// | ||
| /// Use this method for a dialect that `datafusion.sql_parser.dialect` |
There was a problem hiding this comment.
I think this could be shorter "Use this method for custom dialects that are not supported by ..."
| /// [`sqlparser::dialect::Dialect`]. | ||
| /// | ||
| /// The dialect object takes precedence over the dialect name in the | ||
| /// session config. If it is set, [`SessionContext::sql`], |
There was a problem hiding this comment.
do we really need to list all the (current) users of this setting?
|
Shall we merge it? |
|
I think so! Let me address your feedback next week or feel free to push and merge before that |
|
Pinging this PR (trying to clean up the review / merge queue). Do we still want to merge this? |
|
Yes, sorry for the delay. I'll handle this today. |
Address review: drop the list of current call sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
06f67b1 to
441bacd
Compare
|
Thanks @alamb, I applied your wording suggestiosn from review, sending to merge now! |
|
woohoo! |
Which issue does this PR close?
This picks up the approach of #23235, which the stale bot closed without a review decision. This PR adds the clone-path,
SETand expression-path coverage, and documents the precedence rule.Rationale for this change
datafusion.sql_parser.dialectaccepts only a closed list of names.SessionState::sql_to_statementandSessionState::sql_to_expr_with_aliasresolve that name withdialect_from_stron every parse. Thus an application with its ownsqlparser::dialect::Dialect, for example one built withderive_dialect!on top ofPostgreSqlDialect(apache/datafusion-sqlparser-rs#2174), cannot plug it in. It must wrap every parse entry point itself. A call to a stock method such asSessionContext::sqlthen parses with the wrong dialect, and the query fails with a parse error.What changes are included in this PR?
SessionStateBuilder::with_sql_dialect(Arc<dyn Dialect + Send + Sync>), plus the gettersSessionState::sql_dialect()andSessionStateBuilder::sql_dialect().sql_to_statementandsql_to_expr_with_aliasuse the dialect object when it is set. All other parse paths go through these two methods:SessionContext::sql,sql_with_options,create_logical_plan,create_logical_exprandsql_to_expr.dialectargument tosql_to_statementorsql_to_expr, and a laterSET datafusion.sql_parser.dialect = ....SETstill changes the config value, but not the parser.SessionStateBuilder::new_from_existingandFrom<SessionState>keep the dialect object.datafusion-cliresolves the dialect name itself and does not expose a way to set a dialect object, so this PR does not change it.Are these changes tested?
Yes.
test_custom_sql_dialectuses a small hand-written dialect: PostgreSQL plusSELECT * EXCEPT (...). Thederive-dialectfeature of sqlparser is not enabled in this workspace. The test checks that:ctx.sql(...),create_logical_plan,sql_to_statement,sql_to_exprandcreate_logical_exprparse with the dialect object,SET datafusion.sql_parser.dialectstatement does not replace it,new_from_existingandFrom<SessionState>keep it.The rustdoc example on
with_sql_dialectruns as a doctest.Are there any user-facing changes?
Yes. This PR adds a new public builder method and two getters. There are no breaking changes.