Skip to content

Commit d89d45d

Browse files
committed
Handle very large BigInt literals with negation in EXPLAIN output
Large integers stored as BigInt are converted to Float64 in scientific notation when negated, matching ClickHouse's EXPLAIN AST behavior.
1 parent 60f4d69 commit d89d45d

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

internal/explain/expressions.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package explain
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67

78
"github.com/sqlc-dev/doubleclick/ast"
@@ -434,6 +435,19 @@ func explainUnaryExpr(sb *strings.Builder, n *ast.UnaryExpr, indent string, dept
434435
s := FormatFloat(-val)
435436
fmt.Fprintf(sb, "%sLiteral Float64_%s\n", indent, s)
436437
return
438+
case ast.LiteralString:
439+
// Handle BigInt - very large numbers stored as strings
440+
// ClickHouse converts these to Float64 in scientific notation
441+
if lit.IsBigInt {
442+
if strVal, ok := lit.Value.(string); ok {
443+
// Parse the string as float64 and negate it
444+
if f, err := strconv.ParseFloat(strVal, 64); err == nil {
445+
s := FormatFloat(-f)
446+
fmt.Fprintf(sb, "%sLiteral Float64_%s\n", indent, s)
447+
return
448+
}
449+
}
450+
}
437451
}
438452
}
439453
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true,
4-
"stmt7": true,
5-
"stmt8": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true,
4-
"stmt7": true,
5-
"stmt8": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt2": true,
4-
"stmt3": true
3+
"stmt2": true
54
}
65
}

0 commit comments

Comments
 (0)