From 4324be7c005792c503a65cc9528d16982f74cab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Tue, 9 Jan 2024 08:31:00 +0100 Subject: [PATCH] evalengine bugfix: handle nil evals correctly when coercing values (#14906) Signed-off-by: Andres Taylor --- .../vtgate/evalengine/api_arithmetic_test.go | 23 +++++++++++++++---- go/vt/vtgate/evalengine/eval.go | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/go/vt/vtgate/evalengine/api_arithmetic_test.go b/go/vt/vtgate/evalengine/api_arithmetic_test.go index 40373423aa5..2d601c256c9 100644 --- a/go/vt/vtgate/evalengine/api_arithmetic_test.go +++ b/go/vt/vtgate/evalengine/api_arithmetic_test.go @@ -24,16 +24,14 @@ import ( "strconv" "testing" - "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/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 ( @@ -740,6 +738,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 fbc3cbca57d..e4405a4c0b2 100644 --- a/go/vt/vtgate/evalengine/eval.go +++ b/go/vt/vtgate/evalengine/eval.go @@ -128,7 +128,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