@@ -412,21 +412,26 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
412412 Node (sb , e .Right , depth + 2 )
413413 }
414414 case * ast.UnaryExpr :
415- // When inside a Subquery context, negated numeric literals should be output as Literal Int64_-N
416- // Otherwise, output as Function negate
417- if inSubqueryContext && e .Op == "-" {
415+ // Handle negated numeric literals - output as Literal instead of Function negate
416+ // For integers, only do this in subquery context (ClickHouse behavior)
417+ // For floats (especially inf/nan), always do this
418+ if e .Op == "-" {
418419 if lit , ok := e .Operand .(* ast.Literal ); ok {
419420 switch lit .Type {
420421 case ast .LiteralInteger :
421- switch val := lit .Value .(type ) {
422- case int64 :
423- fmt .Fprintf (sb , "%sLiteral Int64_%d (alias %s)\n " , indent , - val , n .Alias )
424- return
425- case uint64 :
426- fmt .Fprintf (sb , "%sLiteral Int64_-%d (alias %s)\n " , indent , val , n .Alias )
427- return
422+ // Only convert to literal in subquery context
423+ if inSubqueryContext {
424+ switch val := lit .Value .(type ) {
425+ case int64 :
426+ fmt .Fprintf (sb , "%sLiteral Int64_%d (alias %s)\n " , indent , - val , n .Alias )
427+ return
428+ case uint64 :
429+ fmt .Fprintf (sb , "%sLiteral Int64_-%d (alias %s)\n " , indent , val , n .Alias )
430+ return
431+ }
428432 }
429433 case ast .LiteralFloat :
434+ // Always convert negated floats to literals (especially for -inf, -nan)
430435 val := lit .Value .(float64 )
431436 s := FormatFloat (- val )
432437 fmt .Fprintf (sb , "%sLiteral Float64_%s (alias %s)\n " , indent , s , n .Alias )
0 commit comments