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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 17c7309d548 branch-3.0: [fix](Nereids) divide const folding for 
decimalv3 return type is not correct #48641 (#48679)
17c7309d548 is described below

commit 17c7309d5483ce9442468a91405b74e4afe134b0
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Mar 10 12:26:11 2025 +0800

    branch-3.0: [fix](Nereids) divide const folding for decimalv3 return type 
is not correct #48641 (#48679)
    
    Cherry-picked from #48641
    
    Co-authored-by: morrySnow <zhangwen...@selectdb.com>
---
 .../trees/expressions/functions/executable/NumericArithmetic.java  | 7 ++++---
 .../fold_constant/fold_constant_numeric_arithmatic.groovy          | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
index 41a0bf2bdba..50faecf694d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java
@@ -642,11 +642,12 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "divide")
     public static Expression divideDecimalV3(DecimalV3Literal first, 
DecimalV3Literal second) {
-        if (second.getValue().compareTo(BigDecimal.ZERO) == 0) {
-            return new NullLiteral(first.getDataType());
-        }
         DecimalV3Type t1 = (DecimalV3Type) first.getDataType();
         DecimalV3Type t2 = (DecimalV3Type) second.getDataType();
+        if (second.getValue().compareTo(BigDecimal.ZERO) == 0) {
+            return new NullLiteral(DecimalV3Type.createDecimalV3TypeLooseCheck(
+                    t1.getPrecision(), t1.getScale() - t2.getScale()));
+        }
         BigDecimal result = first.getValue().divide(second.getValue());
         return new 
DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(
                 t1.getPrecision(), t1.getScale() - t2.getScale()), result);
diff --git 
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy
 
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy
index c725c8f5030..f95e28e049a 100644
--- 
a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy
+++ 
b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy
@@ -467,4 +467,7 @@ suite("fold_constant_numeric_arithmatic") {
     testFoldConst("SELECT 0 ^ 1 AS xor_case_2") //0 XOR 1 = 1
     testFoldConst("SELECT 255 ^ 128 AS xor_case_3") //255 XOR 128
 
+    // ensure divide for decimal v3 could return correct type when divider is 0
+    sql """ select if(random() > 0.5, cast(random() as decimal(38,10)), cast(0 
as decimal(30, 10)) / cast(0 as decimal(30,10)))"""
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to