Skip to content

Commit

Permalink
evalengine: normalize types during compilation (#17887)
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Vicent Marti <vmg@strn.cat>
  • Loading branch information
systay and vmg authored Mar 3, 2025
1 parent ea9ea39 commit 1141d84
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 @@ -125,10 +125,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 @@ -146,9 +149,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 1141d84

Please sign in to comment.