diff --git a/be/src/vec/functions/function_conv.cpp b/be/src/vec/functions/function_conv.cpp index c168c899006360..78abad9f342ecf 100644 --- a/be/src/vec/functions/function_conv.cpp +++ b/be/src/vec/functions/function_conv.cpp @@ -206,8 +206,12 @@ struct ConvStringImpl { size_t index) { StringRef str = data_column->get_data_at(index); StringParser::ParseResult parse_res; + // select conv('ffffffffffffff', 24, 2); + // if 'ffffffffffffff' parse as int64_t will be overflow, will be get max value: std::numeric_limits::max() + // so change it parse as uint64_t, and return value could still use int64_t, in function decimal_to_base could handle it. + // But if the value is still overflow in uint64_t, will get max value of uint64_t int64_t decimal_num = - StringParser::string_to_int(str.data, str.size, src_base, &parse_res); + StringParser::string_to_int(str.data, str.size, src_base, &parse_res); if (src_base < 0 && decimal_num >= 0) { result_null_map[index] = true; result_column->insert_default(); diff --git a/regression-test/data/nereids_p0/sql_functions/math_functions/test_conv.out b/regression-test/data/nereids_p0/sql_functions/math_functions/test_conv.out index cb2f1e9d4a620e..e05c1a3437ae86 100644 --- a/regression-test/data/nereids_p0/sql_functions/math_functions/test_conv.out +++ b/regression-test/data/nereids_p0/sql_functions/math_functions/test_conv.out @@ -2,3 +2,12 @@ -- !select -- 1111 +-- !select2 -- +1011111001100011011111100110111101001101111010011011110100110111 + +-- !select3 -- +1111111111111111111111111111111111111111111111111111111010001001 + +-- !select4 -- +18446744073709551615 + diff --git a/regression-test/suites/nereids_p0/sql_functions/math_functions/test_conv.groovy b/regression-test/suites/nereids_p0/sql_functions/math_functions/test_conv.groovy index 545bc8d6e75461..214e65ff4bdb16 100644 --- a/regression-test/suites/nereids_p0/sql_functions/math_functions/test_conv.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/math_functions/test_conv.groovy @@ -19,5 +19,9 @@ suite("test_conv") { sql "SET enable_nereids_planner=true" sql "SET enable_fallback_to_original_planner=false" qt_select "SELECT CONV(15,10,2)" + qt_select2 "select conv('ffffffffffffff', 24, 2);" + qt_select3 "select conv('-ff', 24, 2);" + // if beyond the max value of uint64, use max_uint64 as res + qt_select4 "select conv('fffffffffffffffffffffffffffffffff', 24, 10);" }