Skip to content

Commit 3aa61af

Browse files
committed
Fix empty GROUPING SETS output formatting
Output empty grouping set () as 'ExpressionList' without children count, matching ClickHouse's expected EXPLAIN format. Fixed tests (10 statements): - 02293_grouping_function (stmt7) - 01883_with_grouping_sets (stmt9) - 02315_grouping_constant_folding (stmt4, stmt6) - 02416_grouping_function_compatibility (stmt4) - 03611_uniqExact_bug (stmt10) - 03708_analyzer_convert_any_outer_to_inner_2 (stmt12) - 03654_grouping_sets_any_min_max (stmt2, stmt12, stmt14)
1 parent 548d700 commit 3aa61af

File tree

8 files changed

+14
-37
lines changed

8 files changed

+14
-37
lines changed

internal/explain/select.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,14 @@ func explainSelectQuery(sb *strings.Builder, n *ast.SelectQuery, indent string,
360360
// but we need to unwrap tuples and output elements directly
361361
if lit, ok := g.(*ast.Literal); ok && lit.Type == ast.LiteralTuple {
362362
if elements, ok := lit.Value.([]ast.Expression); ok {
363-
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(elements))
364-
for _, elem := range elements {
365-
Node(sb, elem, depth+3)
363+
if len(elements) == 0 {
364+
// Empty grouping set () outputs ExpressionList without children count
365+
fmt.Fprintf(sb, "%s ExpressionList\n", indent)
366+
} else {
367+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(elements))
368+
for _, elem := range elements {
369+
Node(sb, elem, depth+3)
370+
}
366371
}
367372
} else {
368373
// Fallback for unexpected tuple value type
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt9": 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt6": 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-
"stmt4": true
4-
}
5-
}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
43
"stmt2": true
54
}
65
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true,
4-
"stmt14": true,
5-
"stmt2": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)