Skip to content

Commit 4fda7c3

Browse files
committed
Fix Identifier handling in FormatDataType and escape strings in CAST explain
- Add Identifier handling in FormatDataType to properly format AggregateFunction types that contain function name identifiers - Escape string literals in CAST explain output to properly handle null bytes and other control characters Tests fixed: - 02688_aggregate_states (all statements) - 02477_single_value_data_string_regression - 02689_meaningless_data_types - 02731_nothing_deserialization - 02885_arg_min_max_combinator - 03011_definitive_guide_to_cast - 03210_variant_with_aggregate_function_type - 03254_normalize_aggregate_states_with_named_tuple_args - 03411_iceberg_bucket
1 parent db2e211 commit 4fda7c3

11 files changed

Lines changed: 16 additions & 54 deletions

File tree

internal/explain/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ func FormatDataType(dt *ast.DataType) string {
286286
} else {
287287
params = append(params, fmt.Sprintf("%v", p))
288288
}
289+
} else if ident, ok := p.(*ast.Identifier); ok {
290+
// Identifier (e.g., function name in AggregateFunction types)
291+
params = append(params, ident.Name())
289292
} else {
290293
params = append(params, fmt.Sprintf("%v", p))
291294
}

internal/explain/functions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,11 @@ func explainCastExprWithAlias(sb *strings.Builder, n *ast.CastExpr, alias string
489489
// NULL stays as Literal NULL, not formatted as a string
490490
fmt.Fprintf(sb, "%s Literal NULL\n", indent)
491491
} else {
492-
// Simple literal - format as string
492+
// Simple literal - format as string (escape special chars for string literals)
493493
exprStr := formatExprAsString(lit)
494+
if lit.Type == ast.LiteralString {
495+
exprStr = escapeStringLiteral(exprStr)
496+
}
494497
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, exprStr)
495498
}
496499
} else if negatedLit := extractNegatedLiteral(n.Expr); negatedLit != "" {
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-
"stmt4": true,
5-
"stmt8": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true,
4-
"stmt2": true,
5-
"stmt3": true,
6-
"stmt4": true,
7-
"stmt5": true,
8-
"stmt6": true,
9-
"stmt7": true
10-
}
11-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true,
4-
"stmt2": 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-
"stmt1": 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-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"explain_todo": {
33
"stmt36": true,
4-
"stmt53": true,
5-
"stmt84": true
4+
"stmt53": true
65
}
76
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt4": true,
4-
"stmt7": true
3+
"stmt4": true
54
}
65
}
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+
{}

0 commit comments

Comments
 (0)