@@ -136,6 +136,28 @@ func formatArrayLiteral(val interface{}) string {
136136 return fmt .Sprintf ("Array_[%s]" , strings .Join (parts , ", " ))
137137}
138138
139+ // formatNumericExpr formats a numeric expression (literal or unary minus of literal)
140+ func formatNumericExpr (e ast.Expression ) (string , bool ) {
141+ if lit , ok := e .(* ast.Literal ); ok {
142+ if lit .Type == ast .LiteralInteger || lit .Type == ast .LiteralFloat {
143+ return FormatLiteral (lit ), true
144+ }
145+ }
146+ if unary , ok := e .(* ast.UnaryExpr ); ok && unary .Op == "-" {
147+ if lit , ok := unary .Operand .(* ast.Literal ); ok {
148+ switch val := lit .Value .(type ) {
149+ case int64 :
150+ return fmt .Sprintf ("Int64_%d" , - val ), true
151+ case uint64 :
152+ return fmt .Sprintf ("Int64_%d" , - int64 (val )), true
153+ case float64 :
154+ return fmt .Sprintf ("Float64_%s" , FormatFloat (- val )), true
155+ }
156+ }
157+ }
158+ return "" , false
159+ }
160+
139161// formatTupleLiteral formats a tuple literal for EXPLAIN AST output
140162func formatTupleLiteral (val interface {}) string {
141163 exprs , ok := val .([]ast.Expression )
@@ -144,7 +166,9 @@ func formatTupleLiteral(val interface{}) string {
144166 }
145167 var parts []string
146168 for _ , e := range exprs {
147- if lit , ok := e .(* ast.Literal ); ok {
169+ if formatted , ok := formatNumericExpr (e ); ok {
170+ parts = append (parts , formatted )
171+ } else if lit , ok := e .(* ast.Literal ); ok {
148172 parts = append (parts , FormatLiteral (lit ))
149173 } else if ident , ok := e .(* ast.Identifier ); ok {
150174 parts = append (parts , ident .Name ())
@@ -159,7 +183,9 @@ func formatTupleLiteral(val interface{}) string {
159183func formatInListAsTuple (list []ast.Expression ) string {
160184 var parts []string
161185 for _ , e := range list {
162- if lit , ok := e .(* ast.Literal ); ok {
186+ if formatted , ok := formatNumericExpr (e ); ok {
187+ parts = append (parts , formatted )
188+ } else if lit , ok := e .(* ast.Literal ); ok {
163189 parts = append (parts , FormatLiteral (lit ))
164190 } else if ident , ok := e .(* ast.Identifier ); ok {
165191 parts = append (parts , ident .Name ())
0 commit comments