-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Revert #17295 (Support from-first SQL syntax) #17520
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
Conversation
When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513
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.
Will fix before merging
|
@simonvandel and @Jefffrey could you review please? |
|
I wasn't aware we allowed > select from t1;
+---+---+
| a | b |
+---+---+
| 1 | 2 |
+---+---+
1 row(s) fetched.
Elapsed 0.007 seconds.
> select from t1 where 1=0;
0 row(s) fetched.
Elapsed 0.006 seconds.
So |
|
Hmm good point. I agree with you. And actually @xudong963 I think your original report may be a non issue? |
alamb
left a comment
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.
Makes sense to me -- thank you @adriangb
Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes apache#17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
findepi
left a comment
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.
please add a "non-negotiable" test
datafusion/sql/src/select.rs
Outdated
| // incorrectly returned all columns instead of empty projection. | ||
| // For now, we don't add wildcard, which fixes the regression but breaks FROM-first. | ||
| // A proper fix would need to distinguish between "FROM table" and "SELECT FROM table" | ||
| // at the parser level, which sqlparser currently doesn't support. |
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.
I am not sure the comment is needed. The test is an automated comment.
This PR is logically a revert + regression test.
|
|
||
| query TT | ||
| explain format indent | ||
| select from t1 where t1.a > 1; |
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.
Plan tests are cool, but plan changes are easy to overlook. They need manual verification.
Query results-based tests are less disputable.
Can we also run this query and assert the result?
sqllogic doesn't support this (maybe we would need to change the rendering or result lines to make them non-empty).
If slt doesn't allow testing this, then we need a test in Rust.
|
Yeah it seems like what this is coming to is:
I'd like to get some input from the authors of #17295 before we proceed down that path. Then I agree @findepi we can add a better regression test that asserts against the relevant bit of the plan in Rust. |
comphead
left a comment
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.
thanks @adriangb some minors
Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Co-authored-by: Oleks V <comphead@users.noreply.github.com>
simonvandel
left a comment
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.
Thanks for fixing the regression I introduced!
|
Need to revert doc changes too: datafusion/docs/source/user-guide/sql/select.md Lines 78 to 90 in 351675d
|
agreed. BTW Trino has the following syntax: -- equivalent of SELECT * FROM my_table
TABLE my_table; |
done! |
|
Thank you @adriangb |
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes apache#17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt Co-authored-by: Oleks V <comphead@users.noreply.github.com> * Update datafusion/core/tests/sql/select.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> * revert docs * fmt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
|
This one looks good thanks everyone! I also made a backport PR to |
|
@simonvandel I'm sorry we had to revert your contribution. I hope you're able to contribute again and now that we have the regression test and clarity about the behavior it should be okay to re-add your feature. |
|
Thank you all! Sorry, I didn't get a chance to review it. |
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR #17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes #17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes #17513 🤖 Generated with [Claude Code](https://claude.ai/code) * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt * Update datafusion/core/tests/sql/select.rs * revert docs * fmt --------- Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes apache#17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt Co-authored-by: Oleks V <comphead@users.noreply.github.com> * Update datafusion/core/tests/sql/select.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> * revert docs * fmt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Summary
SELECT FROM tableincorrectly returned all columns instead of empty projectionProblem
PR #17295 added support for FROM-first syntax (e.g.,
FROM tablewithout SELECT). To enable this, it added logic to insert a wildcard projection when the projection list was empty.However, this caused a regression:
SELECT FROM table(which is valid SQL meaning "select no columns") was also getting the wildcard projection added, causing it to return all columns instead of an empty result set.Solution
This PR removes the automatic wildcard projection addition for empty projections. This fixes the regression where
SELECT FROM tablewas incorrectly returning all columns.Note: This temporarily breaks FROM-first syntax support. A proper fix would require distinguishing between
FROM tableandSELECT FROM tableat the parser level, which sqlparser currently doesn't support. This should be addressed in a follow-up PR.Test Changes
The test in
projection.sltnow correctly shows thatSELECT FROM table WHERE ...produces an empty Projection node in the logical plan, while the optimizer still pushes down column requirements to the TableScan for efficiency.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com