Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package vtgate
import (
"context"
"fmt"
"github.com/google/go-cmp/cmp"
"testing"

"github.com/google/go-cmp/cmp"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -549,6 +550,14 @@ func TestShowColumns(t *testing.T) {
assertMatches(t, conn, "SHOW columns FROM `t5_null_vindex` in `ks`", expected)
}

func TestCastConvert(t *testing.T) {
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()

assertMatches(t, conn, `SELECT CAST("test" AS CHAR(60))`, `[[VARCHAR("test")]]`)
}

func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) {
t.Helper()
qr := exec(t, conn, query)
Expand Down
5 changes: 5 additions & 0 deletions go/vt/sqlparser/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (nz *normalizer) WalkStatement(node SQLNode) (bool, error) {
// Common node types that never contain SQLVals or ListArgs but create a lot of object
// allocations.
return false, nil
case *ConvertType: // we should not rewrite the type description
return false, nil
}
return true, nil
}
Expand All @@ -91,6 +93,9 @@ func (nz *normalizer) WalkSelect(node SQLNode) (bool, error) {
case OrderBy, GroupBy:
// do not make a bind var for order by column_position
return false, nil
case *ConvertType:
// we should not rewrite the type description
return false, nil
}
return true, nil
}
Expand Down
7 changes: 7 additions & 0 deletions go/vt/sqlparser/normalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func TestNormalize(t *testing.T) {
outbv: map[string]*querypb.BindVariable{
"bv1": sqltypes.TestBindVariable([]interface{}{1, []byte("2")}),
},
}, {
// Do not normalize cast/convert types
in: `select CAST("test" AS CHAR(60))`,
outstmt: `select convert(:bv1, CHAR(60)) from dual`,
outbv: map[string]*querypb.BindVariable{
"bv1": sqltypes.StringBindVariable("test"),
},
}}
for _, tc := range testcases {
stmt, err := Parse(tc.in)
Expand Down