fix: allow arbitrary column aliases in LATERAL VIEW - #2452
Merged
manticore-projects merged 2 commits intoAug 7, 2026
Merged
Conversation
Hive/Spark LATERAL VIEW supports an arbitrary number of column aliases (e.g. json_tuple yielding many output columns), but the grammar only absorbed the first two aliases (JSQLParser#2088). Any further aliases were silently parsed as comma-separated tables in the FROM clause (implicit cross joins), and because toString() re-emitted them as the join list the broken AST round-tripped identically and was hard to detect by inspection. Generalise the column-alias production to consume any number of aliases after the first two. Fixes JSQLParser#2433 Signed-off-by: 付典 <fudianchn@gmail.com>
manticore-projects
requested changes
Aug 7, 2026
Signed-off-by: 付典 <fudianchn@gmail.com>
Contributor
|
Thank you for your work and effort, good job! |
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
Allow a Hive/Spark
LATERAL VIEWto declare an arbitrary number of column aliases, not just two.Why
LATERAL VIEW ... x AS c1, c2, c3, ..., cNis valid Hive/Spark SQL —json_tupleand similar UDTFs commonly yield many output columns. The grammar only absorbed the first two aliases (#2088); from the third onward the aliases were silently parsed as comma-separated tables in theFROMclause (implicit cross joins):PlainSelect.joinsincorrectly containedJoin(Table("c3")) ... Join(Table("cN"))LateralView.columnAlias.aliasColumnsstopped at 2Because
toString()re-emits the leaked aliases as the join list, the broken AST round-trips to textually identical SQL, so the bug is invisible to round-trip checks.Reported in #2433.
How
The column-alias production (
LateralView) handled the second alias with an optional[ "," name ]block. This adds a("," name)*loop immediately after it, so the 3rd…Nth aliases are consumed by the lateral view instead of leaking to theFROMclause. The existing single- and two-alias behaviour is unchanged (the loop simply runs zero times).Testing
HiveTest#testLateralViewManyColumnAliasesIssue2433parsesLATERAL VIEW json_tuple(...) x AS c1, c2, c3, c4, c5, c6, c7and asserts at the AST level (a round-trip assertion would be vacuous here):PlainSelect.joinsisnullandLateralView.columnAlias.aliasColumnshas size 7.master(expected: <null> but was: <[c3, c4, c5, c6, c7]>) and passes with this change.mvn clean test: 4648 tests, 0 failures, 0 errors (26 skipped) — the existing two-alias case ([BUG] JSQLParser Version 5.1-SNAPSHOT: Lateral View with two aliases recognizes second alias as table #2088) and all other tests unchanged.mvn spotless:check: clean.Fixes #2433