This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new adb9b0d  [Bug] Return 0 when hex(0) (#6837)
adb9b0d is described below

commit adb9b0d9c635d83ca242ac5e1c66e9d64f824b64
Author: EmmyMiao87 <[email protected]>
AuthorDate: Fri Oct 15 10:18:55 2021 +0800

    [Bug] Return 0 when hex(0) (#6837)
---
 be/src/exprs/math_functions.cpp       | 3 +++
 be/test/exprs/math_functions_test.cpp | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp
index 50712d5..53ac852 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 8c397c8..64d1f96 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"),

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to