fix: support BigQuery UNNEST WITH OFFSET without AS alias (#6547)#6596
Open
Zjianru wants to merge 1 commit intoalibaba:masterfrom
Open
fix: support BigQuery UNNEST WITH OFFSET without AS alias (#6547)#6596Zjianru wants to merge 1 commit intoalibaba:masterfrom
Zjianru wants to merge 1 commit intoalibaba:masterfrom
Conversation
The parser required an expression after WITH OFFSET even when no AS alias was specified, causing a ParserException on valid BigQuery SQL like: SELECT * FROM UNNEST([10,20,30]) as numbers WITH OFFSET; Changes: - SQLSelectParser: make the offset alias optional after WITH OFFSET - SQLUnnestTableSource: add withOffset boolean field to distinguish 'WITH OFFSET' (no alias) from no WITH OFFSET at all - SQLASTOutputVisitor: output 'WITH OFFSET' without 'AS' when no alias is present - UnnestTest: add 3 test cases covering no alias, AS alias, and implicit alias Closes alibaba#6547
|
|
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.
Problem / 问题
BigQuery SQL
SELECT * FROM UNNEST([10,20,30]) as numbers WITH OFFSETfails withParserExceptionbecause the parser unconditionally callsexprParser.expr()afterWITH OFFSET, even when noAS aliasis specified.BigQuery SQL
SELECT * FROM UNNEST([10,20,30]) as numbers WITH OFFSET解析失败,抛出ParserException。原因是解析器在WITH OFFSET后无条件调用exprParser.expr(),即使没有AS alias。Root Cause / 根因
In
SQLSelectParser.parseUnnestTableSource(), the code was:When
WITH OFFSEThas noAS alias, the next token is;(or EOF), andexpr()cannot parse it.在
SQLSelectParser.parseUnnestTableSource()中,AS是可选的,但expr()总是被调用。当WITH OFFSET后面没有AS alias时,下一个 token 是;(或 EOF),expr()无法解析。Fix / 修复
SQLSelectParser.java: Make the offset alias truly optional — only parse an alias expression whenASis present or a valid identifier follows.SQLUnnestTableSource.java: Addboolean withOffsetfield to distinguish "hasWITH OFFSETbut no alias" from "noWITH OFFSETat all".SQLASTOutputVisitor.java: OutputWITH OFFSET(withoutAS) whenwithOffsetis true but no alias expression exists.Tests / 测试
Added 3 test cases to
UnnestTest.java:test_unnest_with_offset_no_alias:WITH OFFSETwithout any alias (the reported bug)test_unnest_with_offset_as_alias:WITH OFFSET AS off(existing behavior, regression check)test_unnest_with_offset_implicit_alias:WITH OFFSET off(withoutASkeyword, but with alias)All 4 tests pass (including the original
test_0).Closes #6547