Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/explain/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
case *ast.TupleAccess:
// Tuple access - ClickHouse doesn't show aliases on tupleElement in EXPLAIN AST
explainTupleAccess(sb, e, indent, depth)
case *ast.InExpr:
// IN expressions with alias
explainInExprWithAlias(sb, e, n.Alias, indent, depth)
default:
// For other types, recursively explain and add alias info
Node(sb, n.Expr, depth)
Expand Down
30 changes: 28 additions & 2 deletions internal/explain/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ func formatArrayLiteral(val interface{}) string {
return fmt.Sprintf("Array_[%s]", strings.Join(parts, ", "))
}

// formatNumericExpr formats a numeric expression (literal or unary minus of literal)
func formatNumericExpr(e ast.Expression) (string, bool) {
if lit, ok := e.(*ast.Literal); ok {
if lit.Type == ast.LiteralInteger || lit.Type == ast.LiteralFloat {
return FormatLiteral(lit), true
}
}
if unary, ok := e.(*ast.UnaryExpr); ok && unary.Op == "-" {
if lit, ok := unary.Operand.(*ast.Literal); ok {
switch val := lit.Value.(type) {
case int64:
return fmt.Sprintf("Int64_%d", -val), true
case uint64:
return fmt.Sprintf("Int64_%d", -int64(val)), true
case float64:
return fmt.Sprintf("Float64_%s", FormatFloat(-val)), true
}
}
}
return "", false
}

// formatTupleLiteral formats a tuple literal for EXPLAIN AST output
func formatTupleLiteral(val interface{}) string {
exprs, ok := val.([]ast.Expression)
Expand All @@ -144,7 +166,9 @@ func formatTupleLiteral(val interface{}) string {
}
var parts []string
for _, e := range exprs {
if lit, ok := e.(*ast.Literal); ok {
if formatted, ok := formatNumericExpr(e); ok {
parts = append(parts, formatted)
} else if lit, ok := e.(*ast.Literal); ok {
parts = append(parts, FormatLiteral(lit))
} else if ident, ok := e.(*ast.Identifier); ok {
parts = append(parts, ident.Name())
Expand All @@ -159,7 +183,9 @@ func formatTupleLiteral(val interface{}) string {
func formatInListAsTuple(list []ast.Expression) string {
var parts []string
for _, e := range list {
if lit, ok := e.(*ast.Literal); ok {
if formatted, ok := formatNumericExpr(e); ok {
parts = append(parts, formatted)
} else if lit, ok := e.(*ast.Literal); ok {
parts = append(parts, FormatLiteral(lit))
} else if ident, ok := e.(*ast.Identifier); ok {
parts = append(parts, ident.Name())
Expand Down
Loading