morrySnow commented on code in PR #40744:
URL: https://github.com/apache/doris/pull/40744#discussion_r1764466197


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########


Review Comment:
   add fe ut test for all functions



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,472 @@ public static Expression divideDecimalV3(DecimalV3Literal 
first, DecimalV3Litera
         return new 
DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(
                 t1.getPrecision(), t1.getScale() - t2.getScale()), result);
     }
+
+    /**
+     * coalesce
+     */
+    @ExecFunction(name = "coalesce")
+    public static Expression coalesce(Literal first, Literal... second) {
+        if (!(first instanceof NullLiteral)) {
+            return first;
+        }
+        for (Literal secondLiteral : second) {
+            if (!(secondLiteral instanceof NullLiteral)) {
+                return secondLiteral;
+            }
+        }
+        return first;
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first) {
+        return first.round(0);
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.round(second.getValue());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.round(0).getDouble());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first, IntegerLiteral second) 
{
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.round(second.getValue()).getDouble());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first) {
+        return first.roundCeiling(0);
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.roundCeiling(second.getValue());

Review Comment:
   same as round, if second > old scale, the result is wrong



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,472 @@ public static Expression divideDecimalV3(DecimalV3Literal 
first, DecimalV3Litera
         return new 
DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(
                 t1.getPrecision(), t1.getScale() - t2.getScale()), result);
     }
+
+    /**
+     * coalesce
+     */
+    @ExecFunction(name = "coalesce")
+    public static Expression coalesce(Literal first, Literal... second) {
+        if (!(first instanceof NullLiteral)) {
+            return first;
+        }
+        for (Literal secondLiteral : second) {
+            if (!(secondLiteral instanceof NullLiteral)) {
+                return secondLiteral;
+            }
+        }
+        return first;
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first) {
+        return first.round(0);
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.round(second.getValue());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.round(0).getDouble());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first, IntegerLiteral second) 
{
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.round(second.getValue()).getDouble());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first) {
+        return first.roundCeiling(0);
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.roundCeiling(second.getValue());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.roundCeiling(0).getDouble());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DoubleLiteral first, IntegerLiteral second) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.roundCeiling(second.getValue()).getDouble());
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DecimalV3Literal first) {
+        return first.roundFloor(0);
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.roundFloor(second.getValue());

Review Comment:
   same as ceil



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java:
##########
@@ -84,6 +84,12 @@ public DecimalV3Literal roundFloor(int newScale) {
                 value.setScale(newScale, RoundingMode.FLOOR));
     }
 
+    public DecimalV3Literal round(int newScale) {
+        return new DecimalV3Literal(DecimalV3Type
+            .createDecimalV3Type(((DecimalV3Type) dataType).getPrecision(), 
newScale),

Review Comment:
   what scale should be set if newScale bigger than old scale?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,472 @@ public static Expression divideDecimalV3(DecimalV3Literal 
first, DecimalV3Litera
         return new 
DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(
                 t1.getPrecision(), t1.getScale() - t2.getScale()), result);
     }
+
+    /**
+     * coalesce
+     */
+    @ExecFunction(name = "coalesce")
+    public static Expression coalesce(Literal first, Literal... second) {
+        if (!(first instanceof NullLiteral)) {
+            return first;
+        }
+        for (Literal secondLiteral : second) {
+            if (!(secondLiteral instanceof NullLiteral)) {
+                return secondLiteral;
+            }
+        }
+        return first;
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first) {
+        return first.round(0);
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.round(second.getValue());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.round(0).getDouble());
+    }
+
+    /**
+     * round
+     */
+    @ExecFunction(name = "round")
+    public static Expression round(DoubleLiteral first, IntegerLiteral second) 
{
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.round(second.getValue()).getDouble());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first) {
+        return first.roundCeiling(0);
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.roundCeiling(second.getValue());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.roundCeiling(0).getDouble());
+    }
+
+    /**
+     * ceil
+     */
+    @ExecFunction(name = "ceil")
+    public static Expression ceil(DoubleLiteral first, IntegerLiteral second) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.roundCeiling(second.getValue()).getDouble());
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DecimalV3Literal first) {
+        return first.roundFloor(0);
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DecimalV3Literal first, IntegerLiteral 
second) {
+        return first.roundFloor(second.getValue());
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DoubleLiteral first) {
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new DoubleLiteral(middleResult.roundFloor(0).getDouble());
+    }
+
+    /**
+     * floor
+     */
+    @ExecFunction(name = "floor")
+    public static Expression floor(DoubleLiteral first, IntegerLiteral second) 
{
+        DecimalV3Literal middleResult = new DecimalV3Literal(new 
BigDecimal(Double.toString(first.getValue())));
+        return new 
DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble());
+    }
+
+    /**
+     * exp
+     */
+    @ExecFunction(name = "exp")
+    public static Expression exp(DoubleLiteral first) {
+        return new DoubleLiteral(Math.exp(first.getValue()));

Review Comment:
   what will happen if result of Math.exp is infinity?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to