LiBinfeng-01 commented on code in PR #40744:
URL: https://github.com/apache/doris/pull/40744#discussion_r1764531179
##########
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:
It should return null literal, in java it would return infinite value when
it is infinity, would return NaN when the input is Invalid like acos(-2) which
input should between [-1, 1]. In sql behavior, it should return NULL, when it
is NaN or infinity(positive, negative is same logic). Let me add some boundary
check in some functions
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
Review Comment:
get
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]