diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp index 50712d5e1dc0ed..53ac852a8ba140 100644 --- a/be/src/exprs/math_functions.cpp +++ b/be/src/exprs/math_functions.cpp @@ -325,6 +325,9 @@ StringVal MathFunctions::hex_int(FunctionContext* ctx, const BigIntVal& v) { } uint64_t num = v.val; + if (num == 0) { + return AnyValUtil::from_string_temp(ctx, "0"); + } char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; // uint64_t max value 0xFFFFFFFFFFFFFFFF , 16 'F' // need 1 more space for '\0' diff --git a/be/test/exprs/math_functions_test.cpp b/be/test/exprs/math_functions_test.cpp index 8c397c8ffb9a8d..64d1f96722cdf2 100644 --- a/be/test/exprs/math_functions_test.cpp +++ b/be/test/exprs/math_functions_test.cpp @@ -181,7 +181,7 @@ TEST_F(MathFunctionsTest, hex_int) { ASSERT_EQ(StringVal("FFE5853AB393E6C0"), MathFunctions::hex_int(context, BigIntVal(-7453337203775808))); - ASSERT_EQ(StringVal(""), + ASSERT_EQ(StringVal("0"), MathFunctions::hex_int(context, BigIntVal(0))); ASSERT_EQ(StringVal("C"),