Skip to content

Commit e71b727

Browse files
committed
mv type infer to Type()
1 parent 893a5e9 commit e71b727

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

enginetest/queries/script_queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var ScriptTests = []ScriptTest{
125125
{
126126
// https://github.com/dolthub/dolt/issues/9927
127127
// https://github.com/dolthub/dolt/issues/9053
128-
Name: "double negation of integer minimum values",
128+
Name: "double negation of integer minimum values",
129129
Dialect: "mysql",
130130
SetUpScript: []string{
131131
"CREATE TABLE t0(c0 BIGINT);",

sql/expression/arithmetic.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -669,26 +669,14 @@ func mult(lval, rval interface{}) (interface{}, error) {
669669
// UnaryMinus is an unary minus operator.
670670
type UnaryMinus struct {
671671
UnaryExpression
672-
typ sql.Type
673672
}
674673

675674
var _ sql.Expression = (*UnaryMinus)(nil)
676675
var _ sql.CollationCoercible = (*UnaryMinus)(nil)
677676

678677
// NewUnaryMinus creates a new UnaryMinus expression node.
679678
func NewUnaryMinus(child sql.Expression) *UnaryMinus {
680-
typ := child.Type()
681-
switch child.Type() {
682-
case types.Int8, types.Int16, types.Int32:
683-
typ = types.Int64
684-
case types.Int64:
685-
if lit, ok := child.(*Literal); ok {
686-
if lit.Value().(int64) == math.MinInt64 {
687-
typ = types.InternalDecimalType
688-
}
689-
}
690-
}
691-
return &UnaryMinus{UnaryExpression{Child: child}, typ}
679+
return &UnaryMinus{UnaryExpression{Child: child}}
692680
}
693681

694682
// Eval implements the sql.Expression interface.
@@ -763,19 +751,31 @@ func (e *UnaryMinus) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
763751

764752
// Type implements the sql.Expression interface.
765753
func (e *UnaryMinus) Type() sql.Type {
766-
if !types.IsNumber(e.typ) {
754+
typ := e.Child.Type()
755+
switch typ {
756+
case types.Int8, types.Int16, types.Int32:
757+
typ = types.Int64
758+
case types.Int64:
759+
if lit, ok := e.Child.(*Literal); ok {
760+
if lit.Value().(int64) == math.MinInt64 {
761+
typ = types.InternalDecimalType
762+
}
763+
}
764+
}
765+
766+
if !types.IsNumber(typ) {
767767
return types.Float64
768768
}
769769

770-
if e.typ == types.Uint32 {
770+
if typ == types.Uint32 {
771771
return types.Int32
772772
}
773773

774-
if e.typ == types.Uint64 {
774+
if typ == types.Uint64 {
775775
return types.Int64
776776
}
777777

778-
return e.typ
778+
return typ
779779
}
780780

781781
// CollationCoercibility implements the interface sql.CollationCoercible.

0 commit comments

Comments
 (0)