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

morrysnow 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 2aa1fa281ea branch-3.0: [fix](Nereids) fold const return type does not 
matched with type coercion #44022 (#44139)
2aa1fa281ea is described below

commit 2aa1fa281ea66c0d7b2c8cebfa54653aab04581e
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Nov 18 15:42:57 2024 +0800

    branch-3.0: [fix](Nereids) fold const return type does not matched with 
type coercion #44022 (#44139)
    
    Cherry-picked from #44022
    
    Co-authored-by: LiBinfeng <[email protected]>
---
 .../functions/executable/NumericArithmetic.java     | 21 +++++++++++++--------
 .../fold_constant_numeric_arithmatic.groovy         |  9 +++++++++
 2 files changed, 22 insertions(+), 8 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 a9acfeb2d60..d739c830df2 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
@@ -704,7 +704,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "round")
     public static Expression round(DecimalV3Literal first) {
-        return castDecimalV3Literal(first.round(0), 
first.getValue().precision());
+        return castDecimalV3Literal(first.round(0), ((DecimalV3Type) 
first.getDataType()).getPrecision());
     }
 
     /**
@@ -712,7 +712,8 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "round")
     public static Expression round(DecimalV3Literal first, IntegerLiteral 
second) {
-        return castDecimalV3Literal(first.round(second.getValue()), 
first.getValue().precision());
+        return castDecimalV3Literal(first.round(second.getValue()),
+                ((DecimalV3Type) first.getDataType()).getPrecision());
     }
 
     /**
@@ -738,7 +739,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "ceil")
     public static Expression ceil(DecimalV3Literal first) {
-        return castDecimalV3Literal(first.roundCeiling(0), 
first.getValue().precision());
+        return castDecimalV3Literal(first.roundCeiling(0), ((DecimalV3Type) 
first.getDataType()).getPrecision());
     }
 
     /**
@@ -746,7 +747,8 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "ceil")
     public static Expression ceil(DecimalV3Literal first, IntegerLiteral 
second) {
-        return castDecimalV3Literal(first.roundCeiling(second.getValue()), 
first.getValue().precision());
+        return castDecimalV3Literal(first.roundCeiling(second.getValue()),
+                ((DecimalV3Type) first.getDataType()).getPrecision());
     }
 
     /**
@@ -772,7 +774,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "floor")
     public static Expression floor(DecimalV3Literal first) {
-        return castDecimalV3Literal(first.roundFloor(0), 
first.getValue().precision());
+        return castDecimalV3Literal(first.roundFloor(0), ((DecimalV3Type) 
first.getDataType()).getPrecision());
     }
 
     /**
@@ -780,7 +782,8 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "floor")
     public static Expression floor(DecimalV3Literal first, IntegerLiteral 
second) {
-        return castDecimalV3Literal(first.roundFloor(second.getValue()), 
first.getValue().precision());
+        return castDecimalV3Literal(first.roundFloor(second.getValue()),
+                ((DecimalV3Type) first.getDataType()).getPrecision());
     }
 
     /**
@@ -1142,9 +1145,11 @@ public class NumericArithmetic {
         if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
             return first;
         } else if (first.getValue().compareTo(BigDecimal.ZERO) < 0) {
-            return castDecimalV3Literal(first.roundCeiling(second.getValue()), 
first.getValue().precision());
+            return castDecimalV3Literal(first.roundCeiling(second.getValue()),
+                    ((DecimalV3Type) first.getDataType()).getPrecision());
         } else {
-            return castDecimalV3Literal(first.roundFloor(second.getValue()), 
first.getValue().precision());
+            return castDecimalV3Literal(first.roundFloor(second.getValue()),
+                    ((DecimalV3Type) first.getDataType()).getPrecision());
         }
     }
 
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 dbfd3fad7bf..14fecc91b35 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
@@ -434,4 +434,13 @@ test {
     testFoldConst("with cte as (select round(300.343, -4) order by 1 limit 1) 
select * from cte")
     testFoldConst("with cte as (select ceil(300.343, -4) order by 1 limit 1) 
select * from cte")
     testFoldConst("with cte as (select truncate(300.343, -4) order by 1 limit 
1) select * from cte")
+
+    testFoldConst("with cte as (select floor(3) order by 1 limit 1) select * 
from cte")
+    testFoldConst("with cte as (select round(3) order by 1 limit 1) select * 
from cte")
+    testFoldConst("with cte as (select ceil(3) order by 1 limit 1) select * 
from cte")
+
+    testFoldConst("with cte as (select floor(3, 2) order by 1 limit 1) select 
* from cte")
+    testFoldConst("with cte as (select round(3, 2) order by 1 limit 1) select 
* from cte")
+    testFoldConst("with cte as (select ceil(3, 2) order by 1 limit 1) select * 
from cte")
+    testFoldConst("with cte as (select truncate(3, 2) order by 1 limit 1) 
select * from cte")
 }


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

Reply via email to