dreverri opened a new pull request, #27333:
URL: https://github.com/apache/datafusion/pull/27333
## Which issue does this PR close?
- Closes #27332.
## Rationale for this change
Unparsing the optimized plan of `select count(*) from t where id > 10`
produces `SELECT count(1) AS "count(*)" FROM (SELECT FROM t WHERE (t.id >
10))`, even for dialects whose `supports_empty_select_list()` is `false`.
Engines that don't accept an empty select list, such as BigQuery ("SELECT list
must not be empty"), reject the generated SQL.
`optimize_projections` prunes the filter column above the `Filter`, which
leaves a `Projection` with no expressions. #19221 added the `SELECT 1` fallback
for empty projections, but only the `TableScan` path uses it.
## What changes are included in this PR?
- `reconstruct_select_statement` now uses `empty_projection_fallback()` when
the `Projection` has no expressions, the same as the `TableScan` path. Dialects
without empty select list support get `SELECT 1 FROM ...`. PostgreSQL output is
unchanged (`SELECT FROM ...`).
## Are these changes tested?
Yes.
- `datafusion/core/tests/sql/unparser.rs`:
`optimized_count_over_filter_empty_projection` runs the real query through the
optimizer and unparser. It fails without the fix.
- `datafusion/sql/tests/cases/plan_to_sql.rs`: snapshot tests for an empty
`Projection` node with the default, PostgreSQL and BigQuery dialects.
## Are there any user-facing changes?
Yes, generated SQL changes for dialects that don't support an empty select
list: an empty `Projection` now unparses as `SELECT 1 FROM ...` instead of
`SELECT FROM ...`. There are no public API changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]