Skip to content

Commit 37c13c5

Browse files
kyleconroyclaude
andauthored
Fix CAST alias and large float formatting in EXPLAIN output (#95)
* Fix CAST alias and large float formatting in EXPLAIN output - Always show alias for CAST expressions when wrapped in AliasedExpr, regardless of whether CAST uses AS syntax (CAST(x AS Type)) or comma syntax (CAST(x, 'Type')) - Use scientific notation for very large floats (>= 1e21) in EXPLAIN output to match ClickHouse's behavior - Update next-test command to show test with most pending statements instead of fewest These changes fix 69 test files with numerous explain_todo statements. * Add total pending statements count to next-test output --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 18d833e commit 37c13c5

File tree

69 files changed

+83
-340
lines changed

Some content is hidden

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

69 files changed

+83
-340
lines changed

cmd/next-test/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ func main() {
7979
return
8080
}
8181

82-
// Sort by explain_todo count (fewest first), then by query size
82+
// Sort by explain_todo count (most first), then by query size
8383
sort.Slice(todoTests, func(i, j int) bool {
8484
if todoTests[i].explainTodoLen != todoTests[j].explainTodoLen {
85-
return todoTests[i].explainTodoLen < todoTests[j].explainTodoLen
85+
return todoTests[i].explainTodoLen > todoTests[j].explainTodoLen
8686
}
8787
return todoTests[i].querySize < todoTests[j].querySize
8888
})
@@ -116,5 +116,12 @@ func main() {
116116
}
117117
}
118118

119+
// Calculate total pending statements across all tests
120+
totalStatements := 0
121+
for _, t := range todoTests {
122+
totalStatements += t.explainTodoLen
123+
}
124+
119125
fmt.Printf("\nRemaining explain_todo tests: %d\n", len(todoTests))
126+
fmt.Printf("Total pending statements: %d\n", totalStatements)
120127
}

internal/explain/expressions.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,8 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
503503
Node(sb, e.Then, depth+2)
504504
Node(sb, e.Else, depth+2)
505505
case *ast.CastExpr:
506-
// CAST expressions - show alias only for CAST(x AS Type) syntax, not CAST(x, 'Type')
507-
if e.UsedASSyntax {
508-
explainCastExprWithAlias(sb, e, n.Alias, indent, depth)
509-
} else {
510-
explainCastExpr(sb, e, indent, depth)
511-
}
506+
// CAST expressions always show the alias from the AliasedExpr wrapper
507+
explainCastExprWithAlias(sb, e, n.Alias, indent, depth)
512508
case *ast.ArrayAccess:
513509
// Array access - show alias only when array is not a literal
514510
// ClickHouse hides alias when array access is on a literal

internal/explain/format.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ func FormatFloat(val float64) string {
2121
if math.IsNaN(val) {
2222
return "nan"
2323
}
24-
// Use scientific notation for very small numbers (< 1e-6)
25-
// This matches ClickHouse's behavior where numbers like 0.0000001 (-1e-7)
26-
// are displayed in scientific notation
24+
// Use scientific notation for very small numbers (< 1e-6) or very large numbers (>= 1e21)
25+
// This matches ClickHouse's behavior
2726
absVal := math.Abs(val)
28-
if absVal > 0 && absVal < 1e-6 {
27+
if (absVal > 0 && absVal < 1e-6) || absVal >= 1e21 {
2928
s := strconv.FormatFloat(val, 'e', -1, 64)
30-
// Remove leading zeros from exponent (e-07 -> e-7)
29+
// Remove leading zeros from exponent (e-07 -> e-7, e+07 -> e+7)
3130
s = strings.Replace(s, "e-0", "e-", 1)
3231
s = strings.Replace(s, "e+0", "e+", 1)
32+
// Remove the + from positive exponents (e+21 -> e21)
33+
s = strings.Replace(s, "e+", "e", 1)
3334
return s
3435
}
3536
// Use decimal notation for normal-sized numbers
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true,
4-
"stmt4": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt121": true,
4-
"stmt122": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt86": true,
4-
"stmt89": true,
5-
"stmt92": true,
6-
"stmt95": true
7-
}
8-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt17": true,
4-
"stmt27": true,
5-
"stmt7": 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-
"stmt5": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": true,
4-
"stmt6": true,
5-
"stmt9": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt11":true,"stmt12":true,"stmt7":true,"stmt8":true}}
1+
{}

0 commit comments

Comments
 (0)