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: support GBK charset for builtin function octet_length() #29039

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions cmd/explaintest/r/new_character_set_builtin.result
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ length(a) length(b) length(c)
select ascii(a), ascii(b), ascii(c) from t;
ascii(a) ascii(b) ascii(c)
228 210 228
select octet_length(a), octet_length(b), octet_length(c) from t;
octet_length(a) octet_length(b) octet_length(c)
9 6 20
set @@tidb_enable_vectorized_expression = true;
select hex(a), hex(b), hex(c) from t;
hex(a) hex(b) hex(c)
Expand All @@ -20,6 +23,9 @@ length(a) length(b) length(c)
select ascii(a), ascii(b), ascii(c) from t;
ascii(a) ascii(b) ascii(c)
228 210 228
select octet_length(a), octet_length(b), octet_length(c) from t;
octet_length(a) octet_length(b) octet_length(c)
9 6 20
set @@tidb_enable_vectorized_expression = false;
drop table if exists t;
create table t (a char(100) charset utf8mb4, b char(100) charset gbk);
Expand Down
4 changes: 3 additions & 1 deletion cmd/explaintest/t/new_character_set_builtin.test
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
-- test for builtin function hex(), length() and ascii()
-- test for builtin function hex(), length(), ascii(), octet_length()
drop table if exists t;
create table t (a char(20) charset utf8mb4, b char(20) charset gbk, c binary(20));
insert into t values ('一二三', '一二三', '一二三');
select hex(a), hex(b), hex(c) from t;
select length(a), length(b), length(c) from t;
select ascii(a), ascii(b), ascii(c) from t;
select octet_length(a), octet_length(b), octet_length(c) from t;
set @@tidb_enable_vectorized_expression = true;
select hex(a), hex(b), hex(c) from t;
select length(a), length(b), length(c) from t;
select ascii(a), ascii(b), ascii(c) from t;
select octet_length(a), octet_length(b), octet_length(c) from t;
set @@tidb_enable_vectorized_expression = false;

-- test for builtin function upper() and lower()
Expand Down
18 changes: 10 additions & 8 deletions expression/builtin_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ func TestLengthAndOctetLength(t *testing.T) {
{"一二三!", "gbk", 7},
{"一二三!", "", 10},
}
for _, c := range tbl {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, c.chs)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, ast.Length, primitiveValsToConstants(ctx, []interface{}{c.input})...)
require.NoError(t, err)
d, err := f.Eval(chunk.Row{})
require.NoError(t, err)
require.Equal(t, c.result, d.GetInt64())
for _, lengthMethod := range lengthMethods {
for _, c := range tbl {
err := ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, c.chs)
require.NoError(t, err)
f, err := newFunctionForTest(ctx, lengthMethod, primitiveValsToConstants(ctx, []interface{}{c.input})...)
require.NoError(t, err)
d, err := f.Eval(chunk.Row{})
require.NoError(t, err)
require.Equal(t, c.result, d.GetInt64())
}
}
}

Expand Down