From 2f4f559b837c19ffd2c2bb69f74bffe17fb2f2d6 Mon Sep 17 00:00:00 2001 From: yihong Date: Tue, 15 Jul 2025 10:10:51 +0800 Subject: [PATCH] fix: close issue 59446 make oct("") same as mysql (#61767) close pingcap/tidb#59446 --- pkg/expression/builtin_string.go | 5 +++++ pkg/expression/builtin_string_vec.go | 9 ++++++++- tests/integrationtest/r/expression/builtin.result | 15 +++++++++++++++ tests/integrationtest/t/expression/builtin.test | 5 +++++ tests/llmtest/testdata/expression.json | 6 +++--- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pkg/expression/builtin_string.go b/pkg/expression/builtin_string.go index 5a19e49444..154b8c9ec2 100644 --- a/pkg/expression/builtin_string.go +++ b/pkg/expression/builtin_string.go @@ -2993,6 +2993,11 @@ func (b *builtinOctStringSig) evalString(ctx EvalContext, row chunk.Row) (string return "", isNull, err } + // for issue #59446 should return NULL for empty string + if len(val) == 0 { + return "", true, nil + } + negative, overflow := false, false val = getValidPrefix(strings.TrimSpace(val), 10) if len(val) == 0 { diff --git a/pkg/expression/builtin_string_vec.go b/pkg/expression/builtin_string_vec.go index 9a92ed763e..7691c29bbc 100644 --- a/pkg/expression/builtin_string_vec.go +++ b/pkg/expression/builtin_string_vec.go @@ -1774,8 +1774,15 @@ func (b *builtinOctStringSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result.AppendNull() continue } - negative, overflow := false, false + + // for issue #59446 should return NULL for empty string str := buf.GetString(i) + if len(str) == 0 { + result.AppendNull() + continue + } + + negative, overflow := false, false str = getValidPrefix(strings.TrimSpace(str), 10) if len(str) == 0 { result.AppendString("0") diff --git a/tests/integrationtest/r/expression/builtin.result b/tests/integrationtest/r/expression/builtin.result index ee231239e6..38500f943c 100644 --- a/tests/integrationtest/r/expression/builtin.result +++ b/tests/integrationtest/r/expression/builtin.result @@ -2007,6 +2007,21 @@ oct("aaaa") oct("-1.9") oct("-9999999999999999999999999") oct("99999999999999999 select oct(-1.9), oct(1.9), oct(-1), oct(1), oct(-9999999999999999999999999), oct(9999999999999999999999999); oct(-1.9) oct(1.9) oct(-1) oct(1) oct(-9999999999999999999999999) oct(9999999999999999999999999) 1777777777777777777777 1 1777777777777777777777 1 1777777777777777777777 1777777777777777777777 +select oct(""), oct(" "), oct(NULL); +oct("") oct(" ") oct(NULL) +NULL 0 NULL +drop table if exists t_oct; +CREATE TABLE t_oct (a VARCHAR(20)); +INSERT INTO t_oct VALUES (''), (' '), (NULL), ('123'), ('abc'), ('0'), ('255'); +SELECT oct(CONCAT(a, '')) FROM t_oct; +oct(CONCAT(a, '')) +NULL +0 +NULL +173 +0 +0 +377 select find_in_set("", ""), find_in_set("", ","), find_in_set("中文", "字符串,中文"), find_in_set("b,", "a,b,c,d"); find_in_set("", "") find_in_set("", ",") find_in_set("中文", "字符串,中文") find_in_set("b,", "a,b,c,d") 0 1 2 0 diff --git a/tests/integrationtest/t/expression/builtin.test b/tests/integrationtest/t/expression/builtin.test index 4fee9792b3..733cf7940e 100644 --- a/tests/integrationtest/t/expression/builtin.test +++ b/tests/integrationtest/t/expression/builtin.test @@ -899,6 +899,11 @@ insert into t values("中国", cast("国" as binary)), ("中国", ""), ("abc", " select instr(a, b) from t; select oct("aaaa"), oct("-1.9"), oct("-9999999999999999999999999"), oct("9999999999999999999999999"); select oct(-1.9), oct(1.9), oct(-1), oct(1), oct(-9999999999999999999999999), oct(9999999999999999999999999); +select oct(""), oct(" "), oct(NULL); +drop table if exists t_oct; +CREATE TABLE t_oct (a VARCHAR(20)); +INSERT INTO t_oct VALUES (''), (' '), (NULL), ('123'), ('abc'), ('0'), ('255'); +SELECT oct(CONCAT(a, '')) FROM t_oct; select find_in_set("", ""), find_in_set("", ","), find_in_set("中文", "字符串,中文"), find_in_set("b,", "a,b,c,d"); select find_in_set(NULL, ""), find_in_set("", NULL), find_in_set(1, "2,3,1"); select make_set(0, "12"), make_set(3, "aa", "11"), make_set(3, NULL, "中文"), make_set(NULL, "aa"); diff --git a/tests/llmtest/testdata/expression.json b/tests/llmtest/testdata/expression.json index facc2e7811..ec814c01b0 100644 --- a/tests/llmtest/testdata/expression.json +++ b/tests/llmtest/testdata/expression.json @@ -35587,9 +35587,9 @@ { "sql": "SELECT OCT('')", "args": null, - "pass": false, - "known": true, - "comment": "https://github.com/pingcap/tidb/issues/59446" + "pass": true, + "known": false, + "comment": "" }, { "sql": "SELECT OCT(8)",