Skip to content

Commit a933153

Browse files
committed
Fix negated integer literals with aliases in EXPLAIN output
Remove the subquery context restriction when outputting negated integer literals with aliases. Previously, `-5 as offset` was incorrectly rendered as `Function negate (alias offset)` in regular SELECT statements, but should be rendered as `Literal Int64_-5 (alias offset)`. This fixes several failing tests in the 02154_bit_slice_for_string and 02154_bit_slice_for_fixedstring test suites.
1 parent 5d2f760 commit a933153

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

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)