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 8de09cb  [Bug-fix] Decimal Divide, Mod Zero Result Should be NULL. 
(#6051)
8de09cb is described below

commit 8de09cbd2125764a44d6513ebabb2c6fcf8d899a
Author: HappenLee <[email protected]>
AuthorDate: Fri Jul 16 21:43:06 2021 -0500

    [Bug-fix] Decimal Divide, Mod Zero Result Should be NULL. (#6051)
---
 be/src/exprs/decimalv2_operators.cpp | 24 ++++++++++++++++++------
 be/src/runtime/decimalv2_value.cpp   |  4 ++--
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/be/src/exprs/decimalv2_operators.cpp 
b/be/src/exprs/decimalv2_operators.cpp
index 32f54d9..ccc41b9 100644
--- a/be/src/exprs/decimalv2_operators.cpp
+++ b/be/src/exprs/decimalv2_operators.cpp
@@ -176,12 +176,24 @@ DateTimeVal 
DecimalV2Operators::cast_to_date_val(FunctionContext* context,
         return result;                                                         
         \
     }
 
-#define DECIMAL_ARITHMETIC_OPS()        \
-    DECIMAL_ARITHMETIC_OP(add, +);      \
-    DECIMAL_ARITHMETIC_OP(subtract, -); \
-    DECIMAL_ARITHMETIC_OP(multiply, *); \
-    DECIMAL_ARITHMETIC_OP(divide, /);   \
-    DECIMAL_ARITHMETIC_OP(mod, %);
+#define DECIMAL_ARITHMETIC_OP_DIVIDE(FN_NAME, OP)                              
     \
+DecimalV2Val DecimalV2Operators::FN_NAME##_decimalv2_val_decimalv2_val(        
     \
+        FunctionContext* context, const DecimalV2Val& v1, const DecimalV2Val& 
v2) { \
+    if (v1.is_null || v2.is_null || v2.value() == 0) return 
DecimalV2Val::null();   \
+    DecimalV2Value iv1 = DecimalV2Value::from_decimal_val(v1);                 
     \
+    DecimalV2Value iv2 = DecimalV2Value::from_decimal_val(v2);                 
     \
+    DecimalV2Value ir = iv1 OP iv2;                                            
     \
+    DecimalV2Val result;                                                       
     \
+    ir.to_decimal_val(&result);                                                
     \
+    return result;                                                             
     \
+}
+
+#define DECIMAL_ARITHMETIC_OPS()                \
+    DECIMAL_ARITHMETIC_OP(add, +);              \
+    DECIMAL_ARITHMETIC_OP(subtract, -);         \
+    DECIMAL_ARITHMETIC_OP(multiply, *);         \
+    DECIMAL_ARITHMETIC_OP_DIVIDE(divide, /);    \
+    DECIMAL_ARITHMETIC_OP_DIVIDE(mod, %);
 
 DECIMAL_ARITHMETIC_OPS();
 
diff --git a/be/src/runtime/decimalv2_value.cpp 
b/be/src/runtime/decimalv2_value.cpp
index 437dd8f..4a12398 100644
--- a/be/src/runtime/decimalv2_value.cpp
+++ b/be/src/runtime/decimalv2_value.cpp
@@ -192,7 +192,7 @@ DecimalV2Value operator/(const DecimalV2Value& v1, const 
DecimalV2Value& v2) {
     int128_t x = v1.value();
     int128_t y = v2.value();
 
-    //todo: return 0 for divide zero
+    DCHECK(y != 0);
     if (x == 0 || y == 0) return DecimalV2Value(0);
     bool is_positive = (x > 0 && y > 0) || (x < 0 && y < 0);
     do_div(abs(x), abs(y), &result);
@@ -207,7 +207,7 @@ DecimalV2Value operator%(const DecimalV2Value& v1, const 
DecimalV2Value& v2) {
     int128_t x = v1.value();
     int128_t y = v2.value();
 
-    //todo: return 0 for divide zero
+    DCHECK(y != 0);
     if (x == 0 || y == 0) return DecimalV2Value(0);
 
     do_mod(x, y, &result);

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

Reply via email to