From 698d88f9a86d3bf6a42c41df36a0c2d411f3343d 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 1/2] evalengine bugfix: handle nil evals correctly when coercing values (#14906) Signed-off-by: Andres Taylor --- .../vtgate/evalengine/api_arithmetic_test.go | 25 +++++++++++++++---- go/vt/vtgate/evalengine/eval.go | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) 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 From 27d0b025c7417eb4f0e9d42842d5a971dfb898d4 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 9 Jan 2024 10:10:25 +0100 Subject: [PATCH 2/2] force CI Signed-off-by: Andres Taylor