Skip to content

Commit

Permalink
[release-20.0] evalengine: normalize types during compilation (vitess…
Browse files Browse the repository at this point in the history
…io#17887) (vitessio#17895)

Signed-off-by: Vicent Marti <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Vicent Marti <[email protected]>
  • Loading branch information
vitess-bot[bot] and vmg authored Mar 4, 2025
1 parent 254b0fe commit 7ea4bb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/vt/vtgate/evalengine/expr_bvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ func (bvar *BindVariable) compile(c *compiler) (ctype, error) {

switch tt := typ.Type; {
case sqltypes.IsSigned(tt):
typ.Type = sqltypes.Int64
c.asm.PushBVar_i(bvar.Key)
case sqltypes.IsUnsigned(tt):
typ.Type = sqltypes.Uint64
c.asm.PushBVar_u(bvar.Key)
case sqltypes.IsFloat(tt):
typ.Type = sqltypes.Float64
c.asm.PushBVar_f(bvar.Key)
case sqltypes.IsDecimal(tt):
c.asm.PushBVar_d(bvar.Key)
Expand All @@ -149,9 +152,11 @@ func (bvar *BindVariable) compile(c *compiler) (ctype, error) {
typ.Type = sqltypes.VarBinary
typ.Flag |= flagBit
} else {
typ.Type = sqltypes.VarChar
c.asm.PushBVar_text(bvar.Key, typ.Col)
}
case sqltypes.IsBinary(tt):
typ.Type = sqltypes.VarBinary
c.asm.PushBVar_bin(bvar.Key)
case sqltypes.IsNull(tt):
c.asm.PushNull()
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtgate/evalengine/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,19 @@ func TestCardinalityWithBindVariables(t *testing.T) {
})
}
}

func TestBindVarType(t *testing.T) {
lhs := sqlparser.NewTypedArgument("lhs", sqltypes.Int32)
rhs := sqlparser.NewTypedArgument("rhs", sqltypes.Int64)
venv := vtenv.NewTestEnv()
cmp := &sqlparser.ComparisonExpr{
Operator: sqlparser.EqualOp,
Left: lhs,
Right: rhs,
}
_, err := Translate(cmp, &Config{
Collation: venv.CollationEnv().DefaultConnectionCharset(),
Environment: venv,
})
require.NoError(t, err)
}

0 comments on commit 7ea4bb9

Please sign in to comment.