Skip to content

Commit

Permalink
support for 32 bits value in evalengine toSQLValue function
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Jan 23, 2021
1 parent 9e2c673 commit 34ffa84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions go/vt/vtgate/evalengine/evalengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,34 @@ func (v EvalResult) toSQLValue(resultType querypb.Type) sqltypes.Value {
switch {
case sqltypes.IsSigned(resultType):
switch v.typ {
case sqltypes.Int64:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, v.ival, 10))
case sqltypes.Uint64:
case sqltypes.Int64, sqltypes.Int32:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.ival), 10))
case sqltypes.Uint64, sqltypes.Uint32:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.uval), 10))
case sqltypes.Float64:
case sqltypes.Float64, sqltypes.Float32:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.fval), 10))
}
case sqltypes.IsUnsigned(resultType):
switch v.typ {
case sqltypes.Uint64:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, v.uval, 10))
case sqltypes.Int64:
case sqltypes.Uint64, sqltypes.Uint32:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.uval), 10))
case sqltypes.Int64, sqltypes.Int32:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.ival), 10))
case sqltypes.Float64:
case sqltypes.Float64, sqltypes.Float32:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.fval), 10))
}
case sqltypes.IsFloat(resultType) || resultType == sqltypes.Decimal:
switch v.typ {
case sqltypes.Int64:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, v.ival, 10))
case sqltypes.Uint64:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, v.uval, 10))
case sqltypes.Float64:
case sqltypes.Int64, sqltypes.Int32:
return sqltypes.MakeTrusted(resultType, strconv.AppendInt(nil, int64(v.ival), 10))
case sqltypes.Uint64, sqltypes.Uint32:
return sqltypes.MakeTrusted(resultType, strconv.AppendUint(nil, uint64(v.uval), 10))
case sqltypes.Float64, sqltypes.Float32:
format := byte('g')
if resultType == sqltypes.Decimal {
format = 'f'
}
return sqltypes.MakeTrusted(resultType, strconv.AppendFloat(nil, v.fval, format, -1, 64))
return sqltypes.MakeTrusted(resultType, strconv.AppendFloat(nil, float64(v.fval), format, -1, 64))
}
default:
return sqltypes.MakeTrusted(resultType, v.bytes)
Expand Down
10 changes: 5 additions & 5 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ func TestSelectSystemVariables(t *testing.T) {
RowsAffected: 1,
Rows: [][]sqltypes.Value{{
// the following are the uninitialised session values
sqltypes.NULL,
sqltypes.NULL,
sqltypes.NULL,
sqltypes.NULL,
sqltypes.NewInt32(0),
sqltypes.NewInt32(0),
sqltypes.NewInt32(0),
sqltypes.NewInt32(0),
sqltypes.NewInt64(0),
sqltypes.NewVarBinary("UNSPECIFIED"),
sqltypes.NewVarBinary(""),
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestSelectSingleVitessAwareVariable(t *testing.T) {
},
RowsAffected: 1,
Rows: [][]sqltypes.Value{{
sqltypes.NewInt32(1),
sqltypes.NewInt32(0), // autocommit is by default false in the masterSession, thus 0
}},
}
require.NoError(t, err)
Expand Down

0 comments on commit 34ffa84

Please sign in to comment.