Skip to content

Commit 16bd8a1

Browse files
authored
Fix parser tests after ClickHouse 25.8 explain file updates (#79)
1 parent 82c3066 commit 16bd8a1

File tree

264 files changed

+1321
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+1321
-187
lines changed

internal/explain/expressions.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,18 @@ func explainWithElement(sb *strings.Builder, n *ast.WithElement, indent string,
586586
Node(sb, e.Right, depth+2)
587587
}
588588
case *ast.Subquery:
589-
if n.Name != "" {
590-
fmt.Fprintf(sb, "%sSubquery (alias %s) (children %d)\n", indent, n.Name, 1)
589+
// Check if this is "(subquery) AS alias" syntax vs "name AS (subquery)" syntax
590+
if e.Alias != "" {
591+
// "(subquery) AS alias" syntax: output Subquery with alias directly
592+
fmt.Fprintf(sb, "%sSubquery (alias %s) (children 1)\n", indent, e.Alias)
593+
Node(sb, e.Query, depth+1)
591594
} else {
592-
fmt.Fprintf(sb, "%sSubquery (children %d)\n", indent, 1)
595+
// "name AS (subquery)" syntax: output WithElement wrapping the Subquery
596+
// The alias/name is not shown in the EXPLAIN AST output
597+
fmt.Fprintf(sb, "%sWithElement (children 1)\n", indent)
598+
fmt.Fprintf(sb, "%s Subquery (children 1)\n", indent)
599+
Node(sb, e.Query, depth+2)
593600
}
594-
Node(sb, e.Query, depth+1)
595601
case *ast.CastExpr:
596602
explainCastExprWithAlias(sb, e, n.Name, indent, depth)
597603
default:

parser/parser.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,22 +654,25 @@ func (p *Parser) parseWithClause() []ast.Expression {
654654
}
655655
} else if p.currentIs(token.LPAREN) {
656656
// Subquery: (SELECT ...) AS name
657+
// In this syntax, the alias goes on the Subquery, not on WithElement
657658
p.nextToken()
658659
subquery := p.parseSelectWithUnion()
659660
if !p.expect(token.RPAREN) {
660661
return nil
661662
}
662-
elem.Query = &ast.Subquery{Query: subquery}
663+
sq := &ast.Subquery{Query: subquery}
663664

664665
if !p.expect(token.AS) {
665666
return nil
666667
}
667668

668669
// Alias can be IDENT or certain keywords (VALUES, KEY, etc.)
670+
// Set alias on the Subquery for "(subquery) AS name" syntax
669671
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
670-
elem.Name = p.current.Value
672+
sq.Alias = p.current.Value
671673
p.nextToken()
672674
}
675+
elem.Query = sq
673676
} else {
674677
// Scalar WITH: expr AS name (ClickHouse style)
675678
// Examples: WITH 1 AS x, WITH 'hello' AS s, WITH func() AS f
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt1": true
4+
}
5+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt7": true
4+
}
5+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt5": true
4+
}
5+
}

parser/testdata/00392_enum_nested_alter/metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
"stmt13": true,
55
"stmt15": true,
66
"stmt17": true,
7+
"stmt21": true,
78
"stmt23": true,
9+
"stmt24": true,
10+
"stmt29": true,
811
"stmt31": true,
12+
"stmt4": true,
913
"stmt6": true,
14+
"stmt7": true,
1015
"stmt9": true
1116
}
1217
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt4": true,
4+
"stmt5": true,
5+
"stmt6": true
6+
}
7+
}

parser/testdata/00577_replacing_merge_tree_vertical_merge/metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"explain_todo": {
3+
"stmt12": true,
4+
"stmt13": true,
5+
"stmt14": true,
36
"stmt15": true,
47
"stmt16": true,
58
"stmt7": true
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt1": true
4+
}
5+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt3": true
4+
}
5+
}

0 commit comments

Comments
 (0)