Skip to content

Commit 8ce79cd

Browse files
authored
Fix unable to recursive parsing the UNION clause (#96)
1 parent 4099994 commit 8ce79cd

File tree

4 files changed

+148
-1
lines changed

4 files changed

+148
-1
lines changed

parser/parser_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ func (p *Parser) parseSelectQuery(_ Pos) (*SelectQuery, error) {
759759
case p.tryConsumeKeyword(KeywordUnion) != nil:
760760
switch {
761761
case p.tryConsumeKeyword(KeywordAll) != nil:
762-
unionAllExpr, err := p.parseSelectStmt(p.Pos())
762+
unionAllExpr, err := p.parseSelectQuery(p.Pos())
763763
if err != nil {
764764
return nil, err
765765
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Origin SQL:
2+
SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3
3+
4+
5+
-- Format SQL:
6+
7+
SELECT
8+
1 AS v1
9+
UNION ALL
10+
SELECT
11+
2 AS v2
12+
UNION ALL
13+
SELECT
14+
3 AS v3;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
[
2+
{
3+
"SelectPos": 0,
4+
"StatementEnd": 14,
5+
"With": null,
6+
"Top": null,
7+
"SelectColumns": {
8+
"ListPos": 7,
9+
"ListEnd": 14,
10+
"HasDistinct": false,
11+
"Items": [
12+
{
13+
"Expr": {
14+
"NumPos": 7,
15+
"NumEnd": 8,
16+
"Literal": "1",
17+
"Base": 10
18+
},
19+
"AliasPos": 12,
20+
"Alias": {
21+
"Name": "v1",
22+
"QuoteType": 1,
23+
"NamePos": 12,
24+
"NameEnd": 14
25+
}
26+
}
27+
]
28+
},
29+
"From": null,
30+
"ArrayJoin": null,
31+
"Window": null,
32+
"Prewhere": null,
33+
"Where": null,
34+
"GroupBy": null,
35+
"WithTotal": false,
36+
"Having": null,
37+
"OrderBy": null,
38+
"LimitBy": null,
39+
"Limit": null,
40+
"Settings": null,
41+
"Format": null,
42+
"UnionAll": {
43+
"SelectPos": 25,
44+
"StatementEnd": 39,
45+
"With": null,
46+
"Top": null,
47+
"SelectColumns": {
48+
"ListPos": 32,
49+
"ListEnd": 39,
50+
"HasDistinct": false,
51+
"Items": [
52+
{
53+
"Expr": {
54+
"NumPos": 32,
55+
"NumEnd": 33,
56+
"Literal": "2",
57+
"Base": 10
58+
},
59+
"AliasPos": 37,
60+
"Alias": {
61+
"Name": "v2",
62+
"QuoteType": 1,
63+
"NamePos": 37,
64+
"NameEnd": 39
65+
}
66+
}
67+
]
68+
},
69+
"From": null,
70+
"ArrayJoin": null,
71+
"Window": null,
72+
"Prewhere": null,
73+
"Where": null,
74+
"GroupBy": null,
75+
"WithTotal": false,
76+
"Having": null,
77+
"OrderBy": null,
78+
"LimitBy": null,
79+
"Limit": null,
80+
"Settings": null,
81+
"Format": null,
82+
"UnionAll": {
83+
"SelectPos": 50,
84+
"StatementEnd": 64,
85+
"With": null,
86+
"Top": null,
87+
"SelectColumns": {
88+
"ListPos": 57,
89+
"ListEnd": 64,
90+
"HasDistinct": false,
91+
"Items": [
92+
{
93+
"Expr": {
94+
"NumPos": 57,
95+
"NumEnd": 58,
96+
"Literal": "3",
97+
"Base": 10
98+
},
99+
"AliasPos": 62,
100+
"Alias": {
101+
"Name": "v3",
102+
"QuoteType": 1,
103+
"NamePos": 62,
104+
"NameEnd": 64
105+
}
106+
}
107+
]
108+
},
109+
"From": null,
110+
"ArrayJoin": null,
111+
"Window": null,
112+
"Prewhere": null,
113+
"Where": null,
114+
"GroupBy": null,
115+
"WithTotal": false,
116+
"Having": null,
117+
"OrderBy": null,
118+
"LimitBy": null,
119+
"Limit": null,
120+
"Settings": null,
121+
"Format": null,
122+
"UnionAll": null,
123+
"UnionDistinct": null,
124+
"Except": null
125+
},
126+
"UnionDistinct": null,
127+
"Except": null
128+
},
129+
"UnionDistinct": null,
130+
"Except": null
131+
}
132+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1 AS v1 UNION ALL SELECT 2 AS v2 UNION ALL SELECT 3 AS v3

0 commit comments

Comments
 (0)