From f6ed370302e6e69d688eea1fd19d33e62dfc2202 Mon Sep 17 00:00:00 2001 From: zhangstar333 <2561612514@qq.com> Date: Tue, 25 Jun 2024 11:41:49 +0800 Subject: [PATCH 1/2] [Bug](cast) fix cast string to int return wrong result --- be/src/util/string_parser.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/be/src/util/string_parser.hpp b/be/src/util/string_parser.hpp index 34bd678c947f9e..8bc6ecae9141fb 100644 --- a/be/src/util/string_parser.hpp +++ b/be/src/util/string_parser.hpp @@ -279,6 +279,11 @@ T StringParser::string_to_int_internal(const char* __restrict s, int len, ParseR [[fallthrough]]; case '+': ++i; + // only one '+'/'-' char, so could return failure directly + if (UNLIKELY(len == 1)) { + *result = PARSE_FAILURE; + return 0; + } } // This is the fast path where the string cannot overflow. From 1b12955cc8a0ec49e467d5e8735295d82fd9adb6 Mon Sep 17 00:00:00 2001 From: zhangstar333 <2561612514@qq.com> Date: Wed, 26 Jun 2024 16:08:11 +0800 Subject: [PATCH 2/2] add test case --- regression-test/data/datatype_p0/json/json_cast.out | 12 ++++++++++++ .../suites/datatype_p0/json/json_cast.groovy | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/regression-test/data/datatype_p0/json/json_cast.out b/regression-test/data/datatype_p0/json/json_cast.out index 73809a890243a8..8f58f45ce7405d 100644 --- a/regression-test/data/datatype_p0/json/json_cast.out +++ b/regression-test/data/datatype_p0/json/json_cast.out @@ -41,3 +41,15 @@ true -- !sql14 -- 1.1111 +-- !sql15 -- +\N + +-- !sql16 -- +\N + +-- !sql17 -- +\N + +-- !sql18 -- +\N + diff --git a/regression-test/suites/datatype_p0/json/json_cast.groovy b/regression-test/suites/datatype_p0/json/json_cast.groovy index dcb42effdf3487..458c60992d905f 100644 --- a/regression-test/suites/datatype_p0/json/json_cast.groovy +++ b/regression-test/suites/datatype_p0/json/json_cast.groovy @@ -16,7 +16,6 @@ // under the License. suite("test_json_type_cast", "p0") { - sql """ set enable_fold_constant_by_be = false;""" qt_sql1 "SELECT CAST(CAST(10 AS JSON) as INT)" qt_sql2 "SELECT CAST(CAST(102423 AS JSON) as TINYINT)" qt_sql3 "SELECT CAST(CAST(102423 AS JSON) as SMALLINT)" @@ -32,4 +31,9 @@ suite("test_json_type_cast", "p0") { qt_sql12 """select cast("111111" as json)""" qt_sql13 """select cast(111111 as json)""" qt_sql14 """select cast(1.1111 as json)""" + + qt_sql15 """select cast("+" as int);""" + qt_sql16 """select cast("-" as int);""" + qt_sql17 """select cast("a" as int);""" + qt_sql18 """select cast("/" as int);""" } \ No newline at end of file