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
  • Loading branch information
systay authored Jan 9, 2024
1 parent 6f23f60 commit ff48e73
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import (
"fmt"
"testing"

"vitess.io/vitess/go/test/endtoend/utils"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/utils"
)

func start(t *testing.T) (utils.MySQLCompare, func()) {
Expand Down Expand Up @@ -232,7 +230,7 @@ func TestTypeORMQuery(t *testing.T) {
mcmp, closer := start(t)
defer closer()

query := `SELECT kcu.TABLE_NAME, kcu.COLUMN_NAME, cols.DATA_TYPE
utils.AssertMatchesAny(t, mcmp.VtConn, `SELECT kcu.TABLE_NAME, kcu.COLUMN_NAME, cols.DATA_TYPE
FROM (SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu
WHERE kcu.TABLE_SCHEMA = 'ks'
Expand All @@ -252,11 +250,23 @@ FROM (SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME
WHERE cols.TABLE_SCHEMA = 'ks'
AND cols.TABLE_NAME = 't7_xxhash') cols
ON kcu.TABLE_SCHEMA = cols.TABLE_SCHEMA AND kcu.TABLE_NAME = cols.TABLE_NAME AND
kcu.COLUMN_NAME = cols.COLUMN_NAME`
utils.AssertMatchesAny(t, mcmp.VtConn, query,
kcu.COLUMN_NAME = cols.COLUMN_NAME`,
`[[VARBINARY("t1") VARCHAR("id1") BLOB("bigint")] [VARBINARY("t7_xxhash") VARCHAR("uid") BLOB("varchar")]]`,
`[[VARCHAR("t1") VARCHAR("id1") BLOB("bigint")] [VARCHAR("t7_xxhash") VARCHAR("uid") BLOB("varchar")]]`,
)

utils.AssertMatchesAny(t, mcmp.VtConn, `
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'ks' AND TABLE_NAME = 't1'
UNION
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'ks' AND TABLE_NAME = 't2';
`,
`[[VARBINARY("def") VARBINARY("vt_ks") VARBINARY("t1") VARCHAR("id1") UINT32(1) NULL VARCHAR("NO") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("PRI") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARBINARY("def") VARBINARY("vt_ks") VARBINARY("t1") VARCHAR("id2") UINT32(2) NULL VARCHAR("YES") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARBINARY("def") VARBINARY("vt_ks") VARBINARY("t2") VARCHAR("id") UINT32(1) NULL VARCHAR("NO") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("PRI") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARBINARY("def") VARBINARY("vt_ks") VARBINARY("t2") VARCHAR("value") UINT32(2) NULL VARCHAR("YES") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL]]`,
`[[VARCHAR("def") VARCHAR("vt_ks") VARCHAR("t1") VARCHAR("id1") UINT32(1) NULL VARCHAR("NO") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("PRI") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARCHAR("def") VARCHAR("vt_ks") VARCHAR("t1") VARCHAR("id2") UINT32(2) NULL VARCHAR("YES") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARCHAR("def") VARCHAR("vt_ks") VARCHAR("t2") VARCHAR("id") UINT32(1) NULL VARCHAR("NO") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("PRI") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL] [VARCHAR("def") VARCHAR("vt_ks") VARCHAR("t2") VARCHAR("value") UINT32(2) NULL VARCHAR("YES") BLOB("bigint") NULL NULL UINT64(19) UINT64(0) NULL NULL NULL BLOB("bigint") VARBINARY("") VARCHAR("") VARCHAR("select,insert,update,references") BLOB("") BLOB("") NULL]]`,
)
}

func TestJoinWithSingleShardQueryOnRHS(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions go/test/endtoend/vtgate/queries/informationschema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ create table t1
primary key (id1)
) Engine = InnoDB;

create table t2
(
id bigint,
value bigint,
primary key (id)
) Engine = InnoDB;

create table t1_id2_idx
(
id2 bigint,
Expand Down
10 changes: 9 additions & 1 deletion go/test/endtoend/vtgate/queries/informationschema/vschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"hash": {
"type": "hash"
},
"unicode_loose_xxhash" : {
"unicode_loose_xxhash": {
"type": "unicode_loose_xxhash"
},
"t1_id2_idx": {
Expand Down Expand Up @@ -40,6 +40,14 @@
}
]
},
"t2": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
},
"t3_id7_idx": {
"column_vindexes": [
{
Expand Down
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 @@ -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 ff48e73

Please sign in to comment.