Skip to content

Commit

Permalink
[release-17.0] evalengine bugfix: handle nil evals correctly when coe…
Browse files Browse the repository at this point in the history
…rcing values (#14906) (#14913)

Signed-off-by: Andres Taylor <[email protected]>
Co-authored-by: Andrés Taylor <[email protected]>
  • Loading branch information
vitess-bot[bot] and systay authored Jan 9, 2024
1 parent 7fb9164 commit 0bcd0bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions go/vt/vtgate/evalengine/api_arithmetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/evalengine/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bcd0bc

Please sign in to comment.