adriangb opened a new pull request, #27702:
URL: https://github.com/apache/datafusion/pull/27702
## Which issue does this PR close?
- No issue. Follow-up to #27531.
## Rationale for this change
The unparser emits `named_struct(...)` as a `{a: ...}` dictionary literal
for every dialect. sqlparser parses that syntax only for some dialects, such as
DuckDB and Generic. So SQL unparsed with `PostgreSqlDialect`, `MySqlDialect`,
`SqliteDialect` or `BigQueryDialect` does not parse again with the same parser
dialect. The plain `named_struct('a', x)` call plans in every dialect.
The unparser round-trip mode from #27531 could not test a fix like this. It
always unparses with the default dialect, but it plans the result again with
`datafusion.sql_parser.dialect`.
## What changes are included in this PR?
- The round-trip engine unparses with the unparser dialect that matches
`datafusion.sql_parser.dialect`. Parser dialects without their own unparser
dialect use the default one.
- A new `Dialect::supports_dictionary_syntax()` hook, default `true`.
PostgreSQL, MySQL, SQLite and BigQuery return `false` and emit a
`named_struct(...)` call.
`CustomDialectBuilder::with_supports_dictionary_syntax` sets it on a
`CustomDialect`.
- A non-null `ScalarValue::Struct` literal unparses through the same path.
It returned a not-implemented error before. A null struct literal still returns
the error.
## Are these changes tested?
Yes.
- `named_struct_dialects.slt` runs `named_struct` under several parser
dialects. It fails in `--unparser-round-trip` mode before the fix and passes
after it.
- Unit tests in `unparser/expr.rs` cover the output for each built-in
dialect, a `CustomDialect`, and struct literals.
## Are there any user-facing changes?
Yes. SQL unparsed with the PostgreSQL, MySQL, SQLite or BigQuery dialect
contains `named_struct('k', v)` instead of `{k: v}`. The `Dialect` trait has a
new method with a default, so this is not a breaking change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]