fix: keep all clauses when deparsing SELECT without FROM (#2483) - #2484
Merged
manticore-projects merged 1 commit intoAug 18, 2026
Merged
Conversation
…2483) PlainSelect.appendSelectBodyTo printed the post-FROM clause chain (oracle hierarchical, PREFERRING, GROUP BY, HAVING, QUALIFY, WINDOW, EMIT CHANGES) only when a FROM item was present; the "without from" branch rendered WHERE and PREWHERE alone. Move the shared clause chain out of the fromItem branch, mirroring SelectDeParser, so a FROM-less SELECT renders every clause stored on the AST. Output for SELECTs with FROM is unchanged (same checks in the same order). Signed-off-by: 付典 <fudianchn@gmail.com>
fudianchn
force-pushed
the
fix/select-without-from-clauses
branch
from
August 18, 2026 02:08
c05bd1d to
cc450a9
Compare
Contributor
|
Thank you, all of this came from a time where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PlainSelect.toString()silently dropped every clause exceptWHERE/PREWHEREfor aSELECTwithoutFROM:GROUP BY,HAVING,WINDOW,QUALIFY,START WITH/CONNECT BYandPREFERRINGparsed fine and were stored on the AST, but disappeared from the rendered SQL.Why
FROM-less SELECT is supported Standard SQL (#1514). A parse -> toString -> reparse round trip silently rewrites the statement, the worst failure mode for audit / rewriting tools. The
StatementDeParserpath already renders all these clauses unconditionally, so the two render paths disagreed.How
PlainSelect.appendSelectBodyTo: keep only the FROM-adjacent parts (FROM, lateral views, joins,FINAL, ksqlWINDOW) inside thefromItem != nullbranch, move the shared clause chain out, and delete the truncatedelse // without frombranch. This mirrorsSelectDeParser, which already prints the whole chain outside its FROM block. Output for SELECTs with FROM is byte-identical (same checks in the same order).Root cause
The
else // without frombranch ofPlainSelect.appendSelectBodyTorenderedpreWhere/whereonly, while the whole clause chain sat inside thefromItem != nullbranch.Testing
SelectTest#testSelectWithoutFromRetainsWhereGroupByHaving,#testSelectWithoutFromRetainsWindowAndQualify,#testSelectWithoutFromRetainsHierarchicalAndPreferring: on master the round-trip assertions fail (toString()returnsSELECT 1), with the fix all pass../gradlew spotlessApply check: 4858 tests, 0 failures, 0 errors.Verification of the original issue
On master
ad69ecc(jshell,CCJSqlParserUtil.parse(...).toString()):With the fix, all statements from the issue round-trip through both
toString()andStatementDeParser(both are asserted by the new tests).Fixes #2483