Skip to content

fix: SELECT * EXCLUDE(...) silently returns empty rows when all columns are excluded#21259

Open
xiedeyantu wants to merge 3 commits intoapache:mainfrom
xiedeyantu:fix-exclude
Open

fix: SELECT * EXCLUDE(...) silently returns empty rows when all columns are excluded#21259
xiedeyantu wants to merge 3 commits intoapache:mainfrom
xiedeyantu:fix-exclude

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

When SELECT * EXCLUDE(...) or SELECT * EXCEPT(...) excludes every column in the schema, DataFusion silently produces rows with zero columns instead of failing at planning time. This is confusing and inconsistent with DuckDB, which raises a clear Binder Error: SELECT list is empty after resolving * expressions! at planning time.

What changes are included in this PR?

  • In project_with_validation (builder.rs), after expanding all Wildcard and QualifiedWildcard expressions, added a check: if any wildcard was present and the resulting projection list is empty, return a plan_err! with the message SELECT list is empty after resolving * expressions, the wildcard expanded to zero columns.
  • Updated select.slt to change all existing "zero-column wildcard" test cases (previously statement ok) to statement error asserting the new error message. Cases updated include bare SELECT * EXCEPT(all_cols), with LIMIT, WHERE, GROUP BY, JOIN, and window functions.

Are these changes tested?

Yes. The existing SQL logic tests in select.slt are updated to assert the new planning error for all zero-column wildcard scenarios (EXCLUDE and EXCEPT, with various clauses). This covers:

  • SELECT * EXCLUDE(a, b) / SELECT * EXCEPT(a, b, c, d) on a plain scan
  • Combined with LIMIT, WHERE, GROUP BY, JOIN, and window functions
  • Qualified wildcards (SELECT t.* EXCLUDE(...))

Are there any user-facing changes?

Yes. Queries that previously silently returned empty-column result sets via SELECT * EXCLUDE(...) or SELECT * EXCEPT(...) when all columns were excluded will now fail at planning time with:

DataFusion error: Error during planning: SELECT list is empty after resolving * expressions, the wildcard expanded to zero columns

@github-actions github-actions bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Mar 30, 2026
@xiedeyantu xiedeyantu marked this pull request as draft March 30, 2026 16:28
@xiedeyantu xiedeyantu marked this pull request as ready for review March 30, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SELECT * EXCLUDE(...) silently returns empty rows when all columns are excluded

1 participant