Skip to content

Commit 06269a7

Browse files
anshal21Anshal Dwivedi
andauthored
Fix should preserve DISTINCT in ParamExprList by Reusing ColumnExprList.String() (#133)
Co-authored-by: Anshal Dwivedi <[email protected]>
1 parent a0eef0f commit 06269a7

File tree

4 files changed

+103
-6
lines changed

4 files changed

+103
-6
lines changed

parser/ast.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,12 +2928,7 @@ func (f *ParamExprList) End() Pos {
29282928
func (f *ParamExprList) String() string {
29292929
var builder strings.Builder
29302930
builder.WriteString("(")
2931-
for i, item := range f.Items.Items {
2932-
if i > 0 {
2933-
builder.WriteString(", ")
2934-
}
2935-
builder.WriteString(item.String())
2936-
}
2931+
builder.WriteString(f.Items.String())
29372932
builder.WriteString(")")
29382933
return builder.String()
29392934
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Origin SQL:
2+
SELECT count(DISTINCT(RECORD_ID)) FROM RECORD_TABLE
3+
4+
-- Format SQL:
5+
SELECT count(DISTINCT (RECORD_ID)) FROM RECORD_TABLE;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[
2+
{
3+
"SelectPos": 0,
4+
"StatementEnd": 51,
5+
"With": null,
6+
"Top": null,
7+
"SelectItems": [
8+
{
9+
"Expr": {
10+
"Name": {
11+
"Name": "count",
12+
"QuoteType": 1,
13+
"NamePos": 7,
14+
"NameEnd": 12
15+
},
16+
"Params": {
17+
"LeftParenPos": 12,
18+
"RightParenPos": 32,
19+
"Items": {
20+
"ListPos": 13,
21+
"ListEnd": 31,
22+
"HasDistinct": true,
23+
"Items": [
24+
{
25+
"Expr": {
26+
"LeftParenPos": 21,
27+
"RightParenPos": 31,
28+
"Items": {
29+
"ListPos": 22,
30+
"ListEnd": 31,
31+
"HasDistinct": false,
32+
"Items": [
33+
{
34+
"Expr": {
35+
"Name": "RECORD_ID",
36+
"QuoteType": 1,
37+
"NamePos": 22,
38+
"NameEnd": 31
39+
},
40+
"Alias": null
41+
}
42+
]
43+
},
44+
"ColumnArgList": null
45+
},
46+
"Alias": null
47+
}
48+
]
49+
},
50+
"ColumnArgList": null
51+
}
52+
},
53+
"Modifiers": [],
54+
"Alias": null
55+
}
56+
],
57+
"From": {
58+
"FromPos": 34,
59+
"Expr": {
60+
"Table": {
61+
"TablePos": 39,
62+
"TableEnd": 51,
63+
"Alias": null,
64+
"Expr": {
65+
"Database": null,
66+
"Table": {
67+
"Name": "RECORD_TABLE",
68+
"QuoteType": 1,
69+
"NamePos": 39,
70+
"NameEnd": 51
71+
}
72+
},
73+
"HasFinal": false
74+
},
75+
"StatementEnd": 51,
76+
"SampleRatio": null,
77+
"HasFinal": false
78+
}
79+
},
80+
"ArrayJoin": null,
81+
"Window": null,
82+
"Prewhere": null,
83+
"Where": null,
84+
"GroupBy": null,
85+
"WithTotal": false,
86+
"Having": null,
87+
"OrderBy": null,
88+
"LimitBy": null,
89+
"Limit": null,
90+
"Settings": null,
91+
"Format": null,
92+
"UnionAll": null,
93+
"UnionDistinct": null,
94+
"Except": null
95+
}
96+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT count(DISTINCT(RECORD_ID)) FROM RECORD_TABLE

0 commit comments

Comments
 (0)