Skip to content

Commit 9785146

Browse files
committed
Add JSON subcolumn type accessor syntax support
ClickHouse supports a special syntax for JSON path type casting: - json.field.:`TypeName` (backtick-quoted type) - json.field.:TypeName (unquoted type) These are parsed as part of identifier paths and represented as parts like ":`String`" or ":`Array(Nullable(Int64))`". This fixes ~100 failing statements across multiple JSON-related test files.
1 parent ea9dbc0 commit 9785146

12 files changed

Lines changed: 20 additions & 134 deletions

File tree

parser/expression.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ func (p *Parser) parseIdentifierOrFunction() ast.Expression {
475475
} else {
476476
break
477477
}
478+
} else if p.currentIs(token.COLON) {
479+
// JSON subcolumn type accessor: json.field.:`TypeName` or json.field.:TypeName
480+
p.nextToken() // skip :
481+
typePart := ":"
482+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() || p.currentIs(token.STRING) {
483+
typePart += "`" + p.current.Value + "`"
484+
p.nextToken()
485+
}
486+
parts = append(parts, typePart)
478487
} else if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
479488
// Keywords can be used as column/field names (e.g., l_t.key, t.index)
480489
parts = append(parts, p.current.Value)
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true,
4-
"stmt8": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,6 @@
11
{
22
"explain_todo": {
33
"stmt14": true,
4-
"stmt17": true,
5-
"stmt18": true,
6-
"stmt20": true,
7-
"stmt21": true,
8-
"stmt23": true,
9-
"stmt24": true,
10-
"stmt28": true,
11-
"stmt29": true,
12-
"stmt31": true,
13-
"stmt32": true,
14-
"stmt34": true,
15-
"stmt35": true,
16-
"stmt37": true,
17-
"stmt38": true,
18-
"stmt40": true,
19-
"stmt41": true,
20-
"stmt43": true,
21-
"stmt44": true,
22-
"stmt46": true,
23-
"stmt47": true,
24-
"stmt49": true,
25-
"stmt50": true,
26-
"stmt52": true,
27-
"stmt53": true,
28-
"stmt55": true,
29-
"stmt56": true,
30-
"stmt58": true,
31-
"stmt59": true,
32-
"stmt6": true,
33-
"stmt61": true,
34-
"stmt62": true,
35-
"stmt66": true,
36-
"stmt67": true,
37-
"stmt69": true,
38-
"stmt70": true
4+
"stmt6": true
395
}
406
}
Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt100": true,
4-
"stmt101": true,
5-
"stmt103": true,
6-
"stmt104": true,
7-
"stmt105": true,
83
"stmt14": true,
9-
"stmt17": true,
10-
"stmt18": true,
11-
"stmt19": true,
12-
"stmt20": true,
13-
"stmt22": true,
14-
"stmt24": true,
15-
"stmt25": true,
16-
"stmt27": true,
17-
"stmt28": true,
18-
"stmt29": true,
19-
"stmt36": true,
20-
"stmt39": true,
21-
"stmt40": true,
22-
"stmt41": true,
23-
"stmt42": true,
24-
"stmt45": true,
25-
"stmt46": true,
26-
"stmt47": true,
27-
"stmt48": true,
28-
"stmt50": true,
29-
"stmt52": true,
30-
"stmt53": true,
31-
"stmt55": true,
32-
"stmt56": true,
33-
"stmt57": true,
34-
"stmt59": true,
35-
"stmt6": true,
36-
"stmt61": true,
37-
"stmt62": true,
38-
"stmt64": true,
39-
"stmt65": true,
40-
"stmt66": true,
41-
"stmt68": true,
42-
"stmt70": true,
43-
"stmt71": true,
44-
"stmt73": true,
45-
"stmt74": true,
46-
"stmt75": true,
47-
"stmt77": true,
48-
"stmt79": true,
49-
"stmt80": true,
50-
"stmt82": true,
51-
"stmt83": true,
52-
"stmt84": true,
53-
"stmt86": true,
54-
"stmt88": true,
55-
"stmt89": true,
56-
"stmt91": true,
57-
"stmt92": true,
58-
"stmt93": true
4+
"stmt6": true
595
}
606
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": 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-
"stmt7": 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-
"stmt7": 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-
"stmt11": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true,
4-
"stmt9": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt3": true,
4-
"stmt5": true
3+
"stmt3": true
54
}
65
}

0 commit comments

Comments
 (0)