diff --git a/go/vt/vtgate/evalengine/api_arithmetic_test.go b/go/vt/vtgate/evalengine/api_arithmetic_test.go index 0a0abc84a30..57f59a4d9cd 100644 --- a/go/vt/vtgate/evalengine/api_arithmetic_test.go +++ b/go/vt/vtgate/evalengine/api_arithmetic_test.go @@ -24,17 +24,15 @@ import ( "strconv" "testing" - "vitess.io/vitess/go/mysql/collations" - "vitess.io/vitess/go/test/utils" - "vitess.io/vitess/go/vt/vthash" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/sqltypes" - + "vitess.io/vitess/go/test/utils" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/vterrors" + "vitess.io/vitess/go/vt/vthash" ) var ( @@ -1048,6 +1046,23 @@ func TestToSqlValue(t *testing.T) { typ: sqltypes.Decimal, v: newEvalFloat(1.2e-16), out: TestValue(sqltypes.Decimal, "0.00000000000000012"), + }, { + // null in should return null out no matter what type + typ: sqltypes.Int64, + v: nil, + out: sqltypes.NULL, + }, { + typ: sqltypes.Uint64, + v: nil, + out: sqltypes.NULL, + }, { + typ: sqltypes.Float64, + v: nil, + out: sqltypes.NULL, + }, { + typ: sqltypes.VarChar, + v: nil, + out: sqltypes.NULL, }} for _, tcase := range tcases { got := evalToSQLValueWithType(tcase.v, tcase.typ) diff --git a/go/vt/vtgate/evalengine/eval.go b/go/vt/vtgate/evalengine/eval.go index d11bba24dde..9a6dd178866 100644 --- a/go/vt/vtgate/evalengine/eval.go +++ b/go/vt/vtgate/evalengine/eval.go @@ -129,7 +129,7 @@ func evalToSQLValueWithType(e eval, resultType sqltypes.Type) sqltypes.Value { case *evalDecimal: return sqltypes.MakeTrusted(resultType, e.dec.FormatMySQL(e.length)) } - default: + case e != nil: return sqltypes.MakeTrusted(resultType, e.ToRawBytes()) } return sqltypes.NULL