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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,506 @@ 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;
+    }
+
+    private static Expression filterNanResult(Literal input) {
+        if (input instanceof DoubleLiteral) {
+            if (((DoubleLiteral) input).getValue().isNaN()) {
+                return new NullLiteral(input.getDataType());
+            }
+        }
+        return input;
+    }
+
+    /**
+     * 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 filterNanResult(new 
DoubleLiteral(middleResult.round(0).getDouble()));

Review Comment:
   why round need filterNanResult?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,506 @@ 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;
+    }
+
+    private static Expression filterNanResult(Literal input) {
+        if (input instanceof DoubleLiteral) {
+            if (((DoubleLiteral) input).getValue().isNaN()) {
+                return new NullLiteral(input.getDataType());
+            }
+        }
+        return input;
+    }
+
+    /**
+     * 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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(new 
DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble()));
+    }
+
+    /**
+     * exp
+     */
+    @ExecFunction(name = "exp")
+    public static Expression exp(DoubleLiteral first) {
+        return filterNanResult(new DoubleLiteral(Math.exp(first.getValue())));

Review Comment:
   only nan input will lead to nan result? so why filter nan here?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -596,4 +650,506 @@ 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;
+    }
+
+    private static Expression filterNanResult(Literal input) {
+        if (input instanceof DoubleLiteral) {
+            if (((DoubleLiteral) input).getValue().isNaN()) {
+                return new NullLiteral(input.getDataType());
+            }
+        }
+        return input;
+    }
+
+    /**
+     * 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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(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 filterNanResult(new 
DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble()));
+    }
+
+    /**
+     * exp
+     */
+    @ExecFunction(name = "exp")
+    public static Expression exp(DoubleLiteral first) {
+        return filterNanResult(new DoubleLiteral(Math.exp(first.getValue())));
+    }
+
+    /**
+     * ln
+     */
+    @ExecFunction(name = "ln")
+    public static Expression ln(DoubleLiteral first) {
+        if (first.getValue() <= 0) {
+            return new NullLiteral(first.getDataType());
+        }
+        return filterNanResult(new DoubleLiteral(Math.log(first.getValue())));

Review Comment:
   same as exp



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -194,7 +248,7 @@ public static Expression 
addLargeIntLargeInt(LargeIntLiteral first, LargeIntLite
     @ExecFunction(name = "add")
     public static Expression addDoubleDouble(DoubleLiteral first, 
DoubleLiteral second) {
         double result = first.getValue() + second.getValue();
-        return new DoubleLiteral(result);
+        return filterNanResult(new DoubleLiteral(result));

Review Comment:
   why add need filterNanResult?



-- 
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