Skip to content

Commit

Permalink
evalengine bugfix: handle nil evals correctly when coercing values (#…
Browse files Browse the repository at this point in the history
…14906)

Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jan 9, 2024
1 parent ec4b9ba commit 4324be7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions go/vt/vtgate/evalengine/api_arithmetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
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 @@ -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
Expand Down

0 comments on commit 4324be7

Please sign in to comment.