Skip to content

Commit 4f3870c

Browse files
committed
Fix JSON path type accessor parsing and projection ORDER BY
- Add handling for `.:TypeName` syntax in parseArrayAccess after `[]` This allows parsing expressions like `json.c[].d.:Int64` - Fix projection ORDER BY to use parseExpression instead of just reading a single identifier, allowing qualified identifiers like `json.a`, `t.a`, and `json.c[].d.:Int64` Fixes 22 statements in 03464_projections_with_subcolumns and additional statements in other tests.
1 parent cb711f7 commit 4f3870c

File tree

10 files changed

+18
-70
lines changed

10 files changed

+18
-70
lines changed

parser/expression.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,15 @@ func (p *Parser) parseArrayAccess(left ast.Expression) ast.Expression {
18571857
} else {
18581858
break
18591859
}
1860+
} else if p.currentIs(token.COLON) {
1861+
// JSON subcolumn type accessor: json.field.:`TypeName`
1862+
p.nextToken() // skip :
1863+
typePart := ":"
1864+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() || p.currentIs(token.STRING) {
1865+
typePart += "`" + p.current.Value + "`"
1866+
p.nextToken()
1867+
}
1868+
ident.Parts = append(ident.Parts, typePart)
18601869
} else if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
18611870
ident.Parts = append(ident.Parts, p.current.Value)
18621871
p.nextToken()

parser/parser.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,14 +5343,11 @@ func (p *Parser) parseProjection() *ast.Projection {
53435343
if p.currentIs(token.BY) {
53445344
p.nextToken() // BY
53455345
}
5346-
// Parse ORDER BY columns (comma-separated identifiers)
5346+
// Parse ORDER BY columns (comma-separated expressions)
53475347
for !p.currentIs(token.EOF) && !p.currentIs(token.RPAREN) {
5348-
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
5349-
proj.Select.OrderBy = append(proj.Select.OrderBy, &ast.Identifier{
5350-
Position: p.current.Pos,
5351-
Parts: []string{p.current.Value},
5352-
})
5353-
p.nextToken()
5348+
expr := p.parseExpression(LOWEST)
5349+
if expr != nil {
5350+
proj.Select.OrderBy = append(proj.Select.OrderBy, expr)
53545351
} else {
53555352
break
53565353
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt44": true,
4-
"stmt49": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true
4-
}
5-
}
1+
{}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt1": true,
43
"stmt2": true,
5-
"stmt3": true,
64
"stmt4": true
75
}
86
}
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt18": true,
4-
"stmt20": true,
5-
"stmt23": true,
6-
"stmt24": true,
7-
"stmt27": true,
8-
"stmt28": true,
9-
"stmt30": true,
10-
"stmt32": true,
11-
"stmt35": true,
12-
"stmt36": true,
13-
"stmt39": true,
14-
"stmt40": true,
153
"stmt5": true
164
}
175
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt14": true,
5-
"stmt15": true,
6-
"stmt24": true,
7-
"stmt25": true,
8-
"stmt26": true,
9-
"stmt31": true,
10-
"stmt33": true,
11-
"stmt35": true,
12-
"stmt37": true,
13-
"stmt38": true,
14-
"stmt39": true,
15-
"stmt40": true,
16-
"stmt41": true,
17-
"stmt42": true,
18-
"stmt43": true,
19-
"stmt44": true,
20-
"stmt45": true,
21-
"stmt5": true,
22-
"stmt52": true,
23-
"stmt53": true,
24-
"stmt54": true
25-
}
26-
}
1+
{}

parser/testdata/03628_subcolumns_of_columns_with_dot_in_name/metadata.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
43
"stmt11": true,
54
"stmt15": true,
65
"stmt20": true,
7-
"stmt23": true,
86
"stmt24": true,
97
"stmt27": true,
108
"stmt31": true

0 commit comments

Comments
 (0)