Skip to content
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

Fix unable to recursive parsing the UNION clause #96

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parser/parser_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func (p *Parser) parseSelectQuery(_ Pos) (*SelectQuery, error) {
case p.tryConsumeKeyword(KeywordUnion) != nil:
switch {
case p.tryConsumeKeyword(KeywordAll) != nil:
unionAllExpr, err := p.parseSelectStmt(p.Pos())
unionAllExpr, err := p.parseSelectQuery(p.Pos())
if err != nil {
return nil, err
}
Expand Down
14 changes: 14 additions & 0 deletions parser/testdata/query/format/select_with_multi_union.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Origin SQL:
SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3


-- Format SQL:

SELECT
1 AS v1
UNION ALL
SELECT
2 AS v2
UNION ALL
SELECT
3 AS v3;
132 changes: 132 additions & 0 deletions parser/testdata/query/output/select_with_multi_union.sql.golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[
{
"SelectPos": 0,
"StatementEnd": 14,
"With": null,
"Top": null,
"SelectColumns": {
"ListPos": 7,
"ListEnd": 14,
"HasDistinct": false,
"Items": [
{
"Expr": {
"NumPos": 7,
"NumEnd": 8,
"Literal": "1",
"Base": 10
},
"AliasPos": 12,
"Alias": {
"Name": "v1",
"QuoteType": 1,
"NamePos": 12,
"NameEnd": 14
}
}
]
},
"From": null,
"ArrayJoin": null,
"Window": null,
"Prewhere": null,
"Where": null,
"GroupBy": null,
"WithTotal": false,
"Having": null,
"OrderBy": null,
"LimitBy": null,
"Limit": null,
"Settings": null,
"Format": null,
"UnionAll": {
"SelectPos": 25,
"StatementEnd": 39,
"With": null,
"Top": null,
"SelectColumns": {
"ListPos": 32,
"ListEnd": 39,
"HasDistinct": false,
"Items": [
{
"Expr": {
"NumPos": 32,
"NumEnd": 33,
"Literal": "2",
"Base": 10
},
"AliasPos": 37,
"Alias": {
"Name": "v2",
"QuoteType": 1,
"NamePos": 37,
"NameEnd": 39
}
}
]
},
"From": null,
"ArrayJoin": null,
"Window": null,
"Prewhere": null,
"Where": null,
"GroupBy": null,
"WithTotal": false,
"Having": null,
"OrderBy": null,
"LimitBy": null,
"Limit": null,
"Settings": null,
"Format": null,
"UnionAll": {
"SelectPos": 50,
"StatementEnd": 64,
"With": null,
"Top": null,
"SelectColumns": {
"ListPos": 57,
"ListEnd": 64,
"HasDistinct": false,
"Items": [
{
"Expr": {
"NumPos": 57,
"NumEnd": 58,
"Literal": "3",
"Base": 10
},
"AliasPos": 62,
"Alias": {
"Name": "v3",
"QuoteType": 1,
"NamePos": 62,
"NameEnd": 64
}
}
]
},
"From": null,
"ArrayJoin": null,
"Window": null,
"Prewhere": null,
"Where": null,
"GroupBy": null,
"WithTotal": false,
"Having": null,
"OrderBy": null,
"LimitBy": null,
"Limit": null,
"Settings": null,
"Format": null,
"UnionAll": null,
"UnionDistinct": null,
"Except": null
},
"UnionDistinct": null,
"Except": null
},
"UnionDistinct": null,
"Except": null
}
]
1 change: 1 addition & 0 deletions parser/testdata/query/select_with_multi_union.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3
Loading