Skip to content

Commit 56cb4de

Browse files
authored
Fix negated integer literals with aliases in EXPLAIN output (#91)
1 parent 5d2f760 commit 56cb4de

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

internal/explain/expressions.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,19 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
418418
}
419419
case *ast.UnaryExpr:
420420
// Handle negated numeric literals - output as Literal instead of Function negate
421-
// For integers, only do this in subquery context (ClickHouse behavior)
422-
// For floats (especially inf/nan), always do this
421+
// When an aliased expression is a negated literal, output as negative Literal
423422
if e.Op == "-" {
424423
if lit, ok := e.Operand.(*ast.Literal); ok {
425424
switch lit.Type {
426425
case ast.LiteralInteger:
427-
// Only convert to literal in subquery context
428-
if inSubqueryContext {
429-
switch val := lit.Value.(type) {
430-
case int64:
431-
fmt.Fprintf(sb, "%sLiteral Int64_%d (alias %s)\n", indent, -val, escapeAlias(n.Alias))
432-
return
433-
case uint64:
434-
fmt.Fprintf(sb, "%sLiteral Int64_-%d (alias %s)\n", indent, val, escapeAlias(n.Alias))
435-
return
436-
}
426+
// Convert negated integer to negative literal
427+
switch val := lit.Value.(type) {
428+
case int64:
429+
fmt.Fprintf(sb, "%sLiteral Int64_%d (alias %s)\n", indent, -val, escapeAlias(n.Alias))
430+
return
431+
case uint64:
432+
fmt.Fprintf(sb, "%sLiteral Int64_-%d (alias %s)\n", indent, val, escapeAlias(n.Alias))
433+
return
437434
}
438435
case ast.LiteralFloat:
439436
// Always convert negated floats to literals (especially for -inf, -nan)

0 commit comments

Comments
 (0)