Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix panic in upper() and lower() func. (#32505) #32512

Closed
Closed
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
34 changes: 28 additions & 6 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ func (b *builtinLowerSig) vectorized() bool {
}

func (b *builtinLowerUTF8Sig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalString(b.ctx, input, result); err != nil {
n := input.NumRows()
buf, err := b.bufAllocator.get()
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}
result.ReserveString(n)
enc := charset.FindEncoding(b.args[0].GetType().Charset)
for i := 0; i < input.NumRows(); i++ {
result.SetRaw(i, []byte(enc.ToLower(result.GetString(i))))
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
} else {
result.AppendString(enc.ToLower(buf.GetString(i)))
}
}
return nil
}
Expand Down Expand Up @@ -142,12 +153,23 @@ func (b *builtinStringIsNullSig) vectorized() bool {
}

func (b *builtinUpperUTF8Sig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalString(b.ctx, input, result); err != nil {
n := input.NumRows()
buf, err := b.bufAllocator.get()
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}
result.ReserveString(n)
enc := charset.FindEncoding(b.args[0].GetType().Charset)
for i := 0; i < input.NumRows(); i++ {
result.SetRaw(i, []byte(enc.ToUpper(result.GetString(i))))
for i := 0; i < n; i++ {
if buf.IsNull(i) {
result.AppendNull()
} else {
result.AppendString(enc.ToUpper(buf.GetString(i)))
}
}
return nil
}
Expand Down
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6996,6 +6996,22 @@ func TestIssue30264(t *testing.T) {
tk.MustQuery("select greatest(cast(a as JSON), cast('3' as JSON)) from t1;").Check(testkit.Rows("3"))
}

func TestIssue32488(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a varchar(32)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;")
tk.MustExec("insert into t values('ʞ'), ('İ');")
tk.MustExec("set @@tidb_enable_vectorized_expression = false;")
tk.MustQuery("select binary upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}})
tk.MustQuery("select distinct upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}})
tk.MustExec("set @@tidb_enable_vectorized_expression = true;")
tk.MustQuery("select binary upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}})
tk.MustQuery("select distinct upper(a), lower(a) from t order by upper(a);").Check([][]interface{}{{"İ i"}, {"Ʞ ʞ"}})
}

func TestIssue33397(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand Down