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 826a6e41f95 branch-3.0: [fix](constant fold)Remove double boundary 
check. (#54939) (#55077)
826a6e41f95 is described below

commit 826a6e41f95d8a2bf7e9428c9b1f63d21637b82a
Author: James <[email protected]>
AuthorDate: Mon Aug 25 15:53:28 2025 +0800

    branch-3.0: [fix](constant fold)Remove double boundary check. (#54939) 
(#55077)
    
    backport: https://github.com/apache/doris/pull/54939
---
 .../org/apache/doris/analysis/FloatLiteral.java    |   7 +-
 .../functions/executable/NumericArithmetic.java    |  45 +---
 .../nereids/trees/expressions/literal/Literal.java |   8 +
 .../apache/doris/analysis/ArrayLiteralTest.java    |  16 +-
 .../org/apache/doris/analysis/MapLiteralTest.java  |   8 +-
 .../apache/doris/analysis/StructLiteralTest.java   |   8 +-
 .../nereids/rules/expression/FoldConstantTest.java | 278 ++++++++++++++++++---
 .../cast_function/test_cast_struct.out             | Bin 496 -> 494 bytes
 .../org/apache/doris/regression/suite/Suite.groovy |   3 +-
 .../fold_constant_numeric_arithmatic.groovy        |  10 +
 10 files changed, 302 insertions(+), 81 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
index 074b0eea5ec..eb402c22e76 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
@@ -170,10 +170,11 @@ public class FloatLiteral extends NumericLiteralExpr {
             String timeStr = getStringValue();
             return timeStr.substring(1, timeStr.length() - 1);
         } else {
-            if (Double.isInfinite(getValue())) {
-                return Double.toString(getValue());
+            double value = getValue();
+            if (Double.isInfinite(value)) {
+                return value > 0 ? "inf" : "-inf";
             }
-            return BigDecimal.valueOf(getValue()).toPlainString();
+            return 
BigDecimal.valueOf(getValue()).stripTrailingZeros().toPlainString();
         }
     }
 
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 abf6363c035..741eb03fb40 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
@@ -689,8 +689,8 @@ public class NumericArithmetic {
 
     private static Expression checkOutputBoundary(Literal input) {
         if (input instanceof DoubleLiteral) {
-            if (((DoubleLiteral) input).getValue().isNaN() || ((DoubleLiteral) 
input).getValue().isInfinite()) {
-                return new NullLiteral(DoubleType.INSTANCE);
+            if (((DoubleLiteral) input).getValue().isNaN()) {
+                throw new IllegalArgumentException();
             }
         }
         return input;
@@ -819,7 +819,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "ln")
     public static Expression ln(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, false, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log(first.getValue())));
@@ -831,7 +831,8 @@ public class NumericArithmetic {
     @ExecFunction(name = "log")
     public static Expression log(DoubleLiteral first, DoubleLiteral second) {
         if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)
-                || first.getValue().equals(1.0d)) {
+                || first.getValue().equals(1.0d)
+                || inputOutOfBound(second, 0.0d, Double.POSITIVE_INFINITY, 
false, true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log(second.getValue()) / Math.log(first.getValue())));
@@ -842,7 +843,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "log2")
     public static Expression log2(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, false, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log(first.getValue()) / Math.log(2.0)));
@@ -853,7 +854,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "log10")
     public static Expression log10(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, false, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log10(first.getValue())));
@@ -864,7 +865,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "sqrt")
     public static Expression sqrt(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, true, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, true, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.sqrt(first.getValue())));
@@ -875,10 +876,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "power")
     public static Expression power(DoubleLiteral first, DoubleLiteral second) {
-        if (inputOutOfBound(second, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)
-                || (first.getValue() < 0 && second.getValue() % 1 != 0)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
     }
 
@@ -887,9 +884,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "sin")
     public static Expression sin(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.sin(first.getValue())));
     }
 
@@ -898,9 +892,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "cos")
     public static Expression cos(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.cos(first.getValue())));
     }
 
@@ -909,9 +900,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "tan")
     public static Expression tan(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.tan(first.getValue())));
     }
 
@@ -920,9 +908,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "cot")
     public static Expression cot(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new DoubleLiteral(1.0 / 
Math.tan(first.getValue())));
     }
 
@@ -931,9 +916,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "sec")
     public static Expression sec(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new DoubleLiteral(1.0 / 
Math.cos(first.getValue())));
     }
 
@@ -942,9 +924,6 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "cosec")
     public static Expression cosec(DoubleLiteral first) {
-        if (inputOutOfBound(first, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false)) {
-            return new NullLiteral(DoubleType.INSTANCE);
-        }
         return checkOutputBoundary(new DoubleLiteral(1.0 / 
Math.sin(first.getValue())));
     }
 
@@ -1102,7 +1081,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "dlog10")
     public static Expression dlog10(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, false, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log10(first.getValue())));
@@ -1113,7 +1092,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "dsqrt")
     public static Expression dsqrt(DoubleLiteral first) {
-        if (inputOutOfBound(first, 0.0d, Double.MAX_VALUE, false, true)) {
+        if (inputOutOfBound(first, 0.0d, Double.POSITIVE_INFINITY, true, 
true)) {
             return new NullLiteral(DoubleType.INSTANCE);
         }
         return checkOutputBoundary(new 
DoubleLiteral(Math.sqrt(first.getValue())));
@@ -1124,7 +1103,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "dpow")
     public static Expression dpow(DoubleLiteral first, DoubleLiteral second) {
-        return checkOutputBoundary(new 
DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
+        return power(first, second);
     }
 
     /**
@@ -1148,7 +1127,7 @@ public class NumericArithmetic {
      */
     @ExecFunction(name = "fpow")
     public static Expression fpow(DoubleLiteral first, DoubleLiteral second) {
-        return checkOutputBoundary(new 
DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
+        return power(first, second);
     }
 
     /**
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
index 932bf6ba83d..0eba30a70f8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Literal.java
@@ -259,8 +259,16 @@ public abstract class Literal extends Expression 
implements LeafExpression, Comp
         } else if (targetType.isLargeIntType()) {
             return Literal.of(new BigDecimal(desc).toBigInteger());
         } else if (targetType.isFloatType()) {
+            float f = Double.valueOf(desc).floatValue();
+            if (Float.isNaN(f)) {
+                return new NullLiteral(targetType);
+            }
             return Literal.of(Double.valueOf(desc).floatValue());
         } else if (targetType.isDoubleType()) {
+            double d = Double.parseDouble(desc);
+            if (Double.isNaN(d)) {
+                return new NullLiteral(targetType);
+            }
             return Literal.of(Double.parseDouble(desc));
         } else if (targetType.isCharType()) {
             if (((CharType) targetType).getLen() >= desc.length()) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java
index 2085a407388..b880905ef70 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ArrayLiteralTest.java
@@ -40,7 +40,7 @@ public class ArrayLiteralTest  {
         DateLiteral dateLiteral = new DateLiteral("2022-10-10", Type.DATE);
         DateLiteral datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", 
Type.DATETIME);
         ArrayLiteral arrayLiteral1 = new ArrayLiteral(intLiteral1, 
floatLiteral);
-        Assert.assertEquals("[1.0, 2.15]", 
arrayLiteral1.getStringValueForQuery(options));
+        Assert.assertEquals("[1, 2.15]", 
arrayLiteral1.getStringValueForQuery(options));
         ArrayLiteral arrayLiteralWithTime = new ArrayLiteral(floatLiteral1);
         Assert.assertEquals("[\"11:22:33\"]", 
arrayLiteralWithTime.getStringValueForQuery(options));
 
@@ -88,7 +88,7 @@ public class ArrayLiteralTest  {
         MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral);
         StructLiteral structLiteral = new StructLiteral(intLiteral1, 
floatLiteral, dateLiteral);
         ArrayLiteral arrayLiteral13 = new ArrayLiteral(arrayLiteral, 
arrayLiteral);
-        Assert.assertEquals("[[1.0, 2.15], [1.0, 2.15]]",
+        Assert.assertEquals("[[1, 2.15], [1, 2.15]]",
                 arrayLiteral13.getStringValueForQuery(options));
         ArrayLiteral arrayLiteral14 = new ArrayLiteral(mapLiteral);
         Assert.assertEquals("[{1:2.15}]", 
arrayLiteral14.getStringValueForQuery(options));
@@ -112,7 +112,7 @@ public class ArrayLiteralTest  {
         DateLiteral dateLiteral = new DateLiteral("2022-10-10", Type.DATE);
         DateLiteral datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", 
Type.DATETIME);
         ArrayLiteral arrayLiteral1 = new ArrayLiteral(intLiteral1, 
floatLiteral);
-        Assert.assertEquals("[1.0, 2.15]", 
arrayLiteral1.getStringValueForQuery(options));
+        Assert.assertEquals("[1, 2.15]", 
arrayLiteral1.getStringValueForQuery(options));
         ArrayLiteral arrayLiteralWithTime = new ArrayLiteral(floatLiteral1);
         Assert.assertEquals("[11:22:33]", 
arrayLiteralWithTime.getStringValueForQuery(options));
 
@@ -160,7 +160,7 @@ public class ArrayLiteralTest  {
         MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral);
         StructLiteral structLiteral = new StructLiteral(intLiteral1, 
floatLiteral, dateLiteral);
         ArrayLiteral arrayLiteral13 = new ArrayLiteral(arrayLiteral, 
arrayLiteral);
-        Assert.assertEquals("[[1.0, 2.15], [1.0, 2.15]]", 
arrayLiteral13.getStringValueForQuery(options));
+        Assert.assertEquals("[[1, 2.15], [1, 2.15]]", 
arrayLiteral13.getStringValueForQuery(options));
         ArrayLiteral arrayLiteral14 = new ArrayLiteral(mapLiteral);
         Assert.assertEquals("[{1=2.15}]", 
arrayLiteral14.getStringValueForQuery(options));
         ArrayLiteral arrayLiteral15 = new ArrayLiteral(structLiteral);
@@ -182,7 +182,7 @@ public class ArrayLiteralTest  {
         DateLiteral dateLiteral = new DateLiteral("2022-10-10", Type.DATE);
         DateLiteral datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", 
Type.DATETIME);
         ArrayLiteral arrayLiteral1 = new ArrayLiteral(intLiteral1, 
floatLiteral);
-        Assert.assertEquals("[1.0,2.15]", 
arrayLiteral1.getStringValueForQuery(options));
+        Assert.assertEquals("[1,2.15]", 
arrayLiteral1.getStringValueForQuery(options));
         ArrayLiteral arrayLiteralWithTime = new ArrayLiteral(floatLiteral1);
         Assert.assertEquals("[\"11:22:33\"]", 
arrayLiteralWithTime.getStringValueForQuery(options));
 
@@ -231,7 +231,7 @@ public class ArrayLiteralTest  {
         MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral);
         StructLiteral structLiteral = new StructLiteral(intLiteral1, 
floatLiteral, dateLiteral);
         ArrayLiteral arrayLiteral13 = new ArrayLiteral(arrayLiteral, 
arrayLiteral);
-        Assert.assertEquals("[[1.0,2.15],[1.0,2.15]]", 
arrayLiteral13.getStringValueForQuery(options));
+        Assert.assertEquals("[[1,2.15],[1,2.15]]", 
arrayLiteral13.getStringValueForQuery(options));
         ArrayLiteral arrayLiteral14 = new ArrayLiteral(mapLiteral);
         Assert.assertEquals("[{1:2.15}]", 
arrayLiteral14.getStringValueForQuery(options));
         ArrayLiteral arrayLiteral15 = new ArrayLiteral(structLiteral);
@@ -254,7 +254,7 @@ public class ArrayLiteralTest  {
         DateLiteral dateLiteral = new DateLiteral("2022-10-10", Type.DATE);
         DateLiteral datetimeLiteral = new DateLiteral("2022-10-10 12:10:10", 
Type.DATETIME);
         ArrayLiteral arrayLiteral1 = new ArrayLiteral(intLiteral1, 
floatLiteral);
-        Assert.assertEquals("[1.0, 2.15]", 
arrayLiteral1.getStringValueForStreamLoad(options));
+        Assert.assertEquals("[1, 2.15]", 
arrayLiteral1.getStringValueForStreamLoad(options));
         ArrayLiteral arrayLiteralWithTime = new ArrayLiteral(floatLiteral1);
         Assert.assertEquals("[\"11:22:33\"]", 
arrayLiteralWithTime.getStringValueForStreamLoad(options));
 
@@ -303,7 +303,7 @@ public class ArrayLiteralTest  {
         MapLiteral mapLiteral = new MapLiteral(intLiteral1, floatLiteral);
         StructLiteral structLiteral = new StructLiteral(intLiteral1, 
floatLiteral, dateLiteral);
         ArrayLiteral arrayLiteral13 = new ArrayLiteral(arrayLiteral, 
arrayLiteral);
-        Assert.assertEquals("[[1.0, 2.15], [1.0, 2.15]]",
+        Assert.assertEquals("[[1, 2.15], [1, 2.15]]",
                 arrayLiteral13.getStringValueForStreamLoad(options));
         ArrayLiteral arrayLiteral14 = new ArrayLiteral(mapLiteral);
         Assert.assertEquals("[{1:2.15}]", 
arrayLiteral14.getStringValueForStreamLoad(options));
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java
index 9e483e51771..782f0d1ed3c 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/MapLiteralTest.java
@@ -87,7 +87,7 @@ public class MapLiteralTest {
         Assertions.assertEquals("{1:null}", 
mapLiteral9.getStringValueForQuery(options));
 
         MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral);
-        Assertions.assertEquals("{1:[1.0, 2.15]}", 
mapLiteral10.getStringValueForQuery(options));
+        Assertions.assertEquals("{1:[1, 2.15]}", 
mapLiteral10.getStringValueForQuery(options));
         try {
             new MapLiteral(arrayLiteral, floatLiteral);
         } catch (Exception e) {
@@ -142,7 +142,7 @@ public class MapLiteralTest {
         Assertions.assertEquals("{1=NULL}", 
mapLiteral9.getStringValueForQuery(options));
 
         MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral);
-        Assertions.assertEquals("{1=[1.0, 2.15]}", 
mapLiteral10.getStringValueForQuery(options));
+        Assertions.assertEquals("{1=[1, 2.15]}", 
mapLiteral10.getStringValueForQuery(options));
         try {
             new MapLiteral(arrayLiteral, floatLiteral);
         } catch (Exception e) {
@@ -198,7 +198,7 @@ public class MapLiteralTest {
         Assertions.assertEquals("{1:null}", 
mapLiteral9.getStringValueForQuery(options));
 
         MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral);
-        Assertions.assertEquals("{1:[1.0,2.15]}", 
mapLiteral10.getStringValueForQuery(options));
+        Assertions.assertEquals("{1:[1,2.15]}", 
mapLiteral10.getStringValueForQuery(options));
         try {
             new MapLiteral(arrayLiteral, floatLiteral);
         } catch (Exception e) {
@@ -255,7 +255,7 @@ public class MapLiteralTest {
         Assertions.assertEquals("{1:null}", 
mapLiteral9.getStringValueForStreamLoad(options));
 
         MapLiteral mapLiteral10 = new MapLiteral(intLiteral1, arrayLiteral);
-        Assertions.assertEquals("{1:[1.0, 2.15]}", 
mapLiteral10.getStringValueForStreamLoad(options));
+        Assertions.assertEquals("{1:[1, 2.15]}", 
mapLiteral10.getStringValueForStreamLoad(options));
         try {
             new MapLiteral(arrayLiteral, floatLiteral);
         } catch (Exception e) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java
index 5df4dc38e88..4afee613f6a 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/StructLiteralTest.java
@@ -69,7 +69,7 @@ public class StructLiteralTest {
                         + "\"shortstring\", \"col6\":1000000000000000000000, 
\"col7\":1.0, \"col8\":2, \"col9\":\"2022-10-10\", \"col10\":\"2022-10-10 
12:10:10\"}",
                 structLiteral1.getStringValueForQuery(options));
         StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, 
mapLiteral, structLiteral);
-        Assert.assertEquals("{\"col1\":[1.0, 2.15], \"col2\":{1:2.15}, 
\"col3\":"
+        Assert.assertEquals("{\"col1\":[1, 2.15], \"col2\":{1:2.15}, \"col3\":"
                         + "{\"col1\":1, \"col2\":2.15, \"col3\":1.0, 
\"col4\":\"2022-10-10\"}}",
                 structLiteral2.getStringValueForQuery(options));
         StructLiteral structLiteral3 = new StructLiteral();
@@ -91,7 +91,7 @@ public class StructLiteralTest {
                         + "shortstring, col6=1000000000000000000000, col7=1.0, 
col8=2, col9=2022-10-10, col10=2022-10-10 12:10:10}",
                 structLiteral1.getStringValueForQuery(options));
         StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, 
mapLiteral, structLiteral);
-        Assert.assertEquals("{col1=[1.0, 2.15], col2={1=2.15}, col3="
+        Assert.assertEquals("{col1=[1, 2.15], col2={1=2.15}, col3="
                         + "{col1=1, col2=2.15, col3=1.0, col4=2022-10-10}}",
                 structLiteral2.getStringValueForQuery(options));
         StructLiteral structLiteral3 = new StructLiteral();
@@ -114,7 +114,7 @@ public class StructLiteralTest {
                 structLiteral1.getStringValueForQuery(options));
         StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, 
mapLiteral, structLiteral);
         Assert.assertEquals(
-                
"{\"col1\":[1.0,2.15],\"col2\":{1:2.15},\"col3\":{\"col1\":1,\"col2\":2.15,\"col3\":1.0,\"col4\":\"2022-10-10\"}}",
+                
"{\"col1\":[1,2.15],\"col2\":{1:2.15},\"col3\":{\"col1\":1,\"col2\":2.15,\"col3\":1.0,\"col4\":\"2022-10-10\"}}",
                 structLiteral2.getStringValueForQuery(options));
         StructLiteral structLiteral3 = new StructLiteral();
         Assert.assertEquals("{}", 
structLiteral3.getStringValueForQuery(options));
@@ -136,7 +136,7 @@ public class StructLiteralTest {
                 structLiteral1.getStringValueForStreamLoad(options));
         StructLiteral structLiteral2 = new StructLiteral(arrayLiteral, 
mapLiteral, structLiteral);
         Assert.assertEquals(
-                "{[1.0, 2.15], {1:2.15}, {\"col1\":1, \"col2\":2.15, 
\"col3\":1.0, \"col4\":\"2022-10-10\"}}",
+                "{[1, 2.15], {1:2.15}, {\"col1\":1, \"col2\":2.15, 
\"col3\":1.0, \"col4\":\"2022-10-10\"}}",
                 structLiteral2.getStringValueForStreamLoad(options));
         StructLiteral structLiteral3 = new StructLiteral();
         Assert.assertEquals("{}", 
structLiteral3.getStringValueForStreamLoad(options));
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
index 21934a7ed35..9ccc75fc797 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
@@ -26,12 +26,16 @@ import 
org.apache.doris.nereids.rules.analysis.ExpressionAnalyzer;
 import org.apache.doris.nereids.rules.expression.rules.FoldConstantRule;
 import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE;
 import 
org.apache.doris.nereids.rules.expression.rules.SimplifyConditionalFunction;
+import org.apache.doris.nereids.trees.expressions.Add;
 import org.apache.doris.nereids.trees.expressions.CaseWhen;
 import org.apache.doris.nereids.trees.expressions.Cast;
+import org.apache.doris.nereids.trees.expressions.Divide;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.GreaterThan;
+import org.apache.doris.nereids.trees.expressions.Multiply;
 import org.apache.doris.nereids.trees.expressions.Slot;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.Subtract;
 import org.apache.doris.nereids.trees.expressions.TimestampArithmetic;
 import 
org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic;
 import 
org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform;
@@ -39,31 +43,44 @@ import 
org.apache.doris.nereids.trees.expressions.functions.executable.TimeRound
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Acos;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.AppendTrailingCharIfAbsent;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Asin;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Atan;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Bin;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitCount;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Cbrt;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Ceil;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.CharacterLength;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Coalesce;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTz;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Cos;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Cosh;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Cot;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.DateFormat;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Degrees;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Dexp;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Dlog10;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Dsqrt;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Exp;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Floor;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Fmod;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.FromUnixtime;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursAdd;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Left;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Ln;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Locate;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Log;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Log10;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Log2;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsBetween;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.NextDay;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Overlay;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Power;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Radians;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.ReplaceEmpty;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Right;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Round;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Sec;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsAdd;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Sign;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Sin;
@@ -71,6 +88,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.Sqrt;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.StrToDate;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Substring;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Tan;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Tanh;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.ToDays;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.UnixTimestamp;
 import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
@@ -574,20 +592,51 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         Assertions.assertEquals(new DoubleLiteral(1.0), rewritten);
         Expression exExp = new Exp(new DoubleLiteral(1000d));
         rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+
+        Dexp dexp = new Dexp(new DoubleLiteral(0d));
+        rewritten = executor.rewrite(dexp, context);
+        Assertions.assertEquals(new DoubleLiteral(1.0), rewritten);
+        dexp = new Dexp(new DoubleLiteral(1000d));
+        rewritten = executor.rewrite(dexp, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
 
         Ln ln = new Ln(new DoubleLiteral(1d));
         rewritten = executor.rewrite(ln, context);
         Assertions.assertEquals(new DoubleLiteral(0.0), rewritten);
-        exExp = new Ln(new DoubleLiteral(0.0d));
-        rewritten = executor.rewrite(exExp, context);
+        ln = new Ln(new DoubleLiteral(0.0d));
+        rewritten = executor.rewrite(ln, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        ln = new Ln(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(ln, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
 
-        exExp = new Ln(new DoubleLiteral(-1d));
-        rewritten = executor.rewrite(exExp, context);
+        ln = new Ln(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(ln, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
-        exExp = new Log(new DoubleLiteral(1.0d), new DoubleLiteral(1.0d));
-        rewritten = executor.rewrite(exExp, context);
+        Log log = new Log(new DoubleLiteral(1.0d), new DoubleLiteral(1.0d));
+        rewritten = executor.rewrite(log, context);
+        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        log = new Log(new DoubleLiteral(10d), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(log, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        Log2 log2 = new Log2(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(log2, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        log2 = new Log2(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(log2, context);
+        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        Log10 log10 = new Log10(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(log10, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        log10 = new Log10(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(log10, context);
+        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        Dlog10 dlog10 = new Dlog10(new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(dlog10, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        dlog10 = new Dlog10(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(dlog10, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
 
         Sqrt sqrt = new Sqrt(new DoubleLiteral(16d));
@@ -596,19 +645,50 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         sqrt = new Sqrt(new DoubleLiteral(0d));
         rewritten = executor.rewrite(sqrt, context);
         Assertions.assertEquals(new DoubleLiteral(0d), rewritten);
-        exExp = new Sqrt(new DoubleLiteral(-1d));
-        rewritten = executor.rewrite(exExp, context);
+        sqrt = new Sqrt(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(sqrt, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        sqrt = new Sqrt(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(sqrt, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+
+        Dsqrt dsqrt = new Dsqrt(new DoubleLiteral(16d));
+        rewritten = executor.rewrite(dsqrt, context);
+        Assertions.assertEquals(new DoubleLiteral(4d), rewritten);
+        dsqrt = new Dsqrt(new DoubleLiteral(0d));
+        rewritten = executor.rewrite(dsqrt, context);
+        Assertions.assertEquals(new DoubleLiteral(0d), rewritten);
+        dsqrt = new Dsqrt(new DoubleLiteral(-1d));
+        rewritten = executor.rewrite(dsqrt, context);
+        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        dsqrt = new Dsqrt(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(dsqrt, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
 
         Power power = new Power(new DoubleLiteral(2d), new DoubleLiteral(3));
         rewritten = executor.rewrite(power, context);
         Assertions.assertEquals(new DoubleLiteral(8d), rewritten);
-        exExp = new Power(new DoubleLiteral(2d), new DoubleLiteral(10000d));
-        rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
-        exExp = new Power(new DoubleLiteral(-1d), new DoubleLiteral(1.1d));
-        rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        power = new Power(new DoubleLiteral(2d), new DoubleLiteral(10000d));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        power = new Power(new DoubleLiteral(-1d), new DoubleLiteral(1.1d));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(power, rewritten);
+        power = new Power(new DoubleLiteral(1d), new DoubleLiteral(0d));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(new DoubleLiteral(1d), rewritten);
+        power = new Power(new DoubleLiteral(0d), new DoubleLiteral(1d));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(new DoubleLiteral(0d), rewritten);
+        power = new Power(new DoubleLiteral(1.1), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        power = new Power(new DoubleLiteral(-1d), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(power, rewritten);
+        power = new Power(new DoubleLiteral(-1d), new 
DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(power, context);
+        Assertions.assertEquals(power, rewritten);
 
         Sin sin = new Sin(new DoubleLiteral(Math.PI / 2));
         rewritten = executor.rewrite(sin, context);
@@ -616,38 +696,104 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         sin = new Sin(new DoubleLiteral(0d));
         rewritten = executor.rewrite(sin, context);
         Assertions.assertEquals(new DoubleLiteral(0d), rewritten);
-        exExp = new Sin(new DoubleLiteral(Double.POSITIVE_INFINITY));
-        rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        sin = new Sin(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(sin, context);
+        Assertions.assertEquals(sin, rewritten);
+        sin = new Sin(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(sin, context);
+        Assertions.assertEquals(sin, rewritten);
+        sin = new Sin(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(sin, context);
+        Assertions.assertEquals(sin, rewritten);
 
         Cos cos = new Cos(new DoubleLiteral(0d));
         rewritten = executor.rewrite(cos, context);
         Assertions.assertEquals(new DoubleLiteral(1d), rewritten);
-        exExp = new Cos(new DoubleLiteral(Double.POSITIVE_INFINITY));
-        rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        cos = new Cos(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(cos, context);
+        Assertions.assertEquals(cos, rewritten);
+        cos = new Cos(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(cos, context);
+        Assertions.assertEquals(cos, rewritten);
 
         Tan tan = new Tan(new DoubleLiteral(0d));
         rewritten = executor.rewrite(tan, context);
         Assertions.assertEquals(new DoubleLiteral(0d), rewritten);
-        exExp = new Tan(new DoubleLiteral(Double.POSITIVE_INFINITY));
-        rewritten = executor.rewrite(exExp, context);
-        Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
+        tan = new Tan(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(tan, context);
+        Assertions.assertEquals(tan, rewritten);
+        tan = new Tan(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(tan, context);
+        Assertions.assertEquals(tan, rewritten);
+
+        Cot cot = new Cot(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(cot, context);
+        Assertions.assertEquals(cot, rewritten);
+        cot = new Cot(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(cot, context);
+        Assertions.assertEquals(cot, rewritten);
+
+        Sec sec = new Sec(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(sec, context);
+        Assertions.assertEquals(sec, rewritten);
+        sec = new Sec(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(sec, context);
+        Assertions.assertEquals(sec, rewritten);
 
         Asin asin = new Asin(new DoubleLiteral(1d));
         rewritten = executor.rewrite(asin, context);
         Assertions.assertEquals(new DoubleLiteral(Math.PI / 2), rewritten);
-        exExp = new Asin(new DoubleLiteral(2d));
-        rewritten = executor.rewrite(exExp, context);
+        asin = new Asin(new DoubleLiteral(2d));
+        rewritten = executor.rewrite(asin, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
 
         Acos acos = new Acos(new DoubleLiteral(1d));
         rewritten = executor.rewrite(acos, context);
         Assertions.assertEquals(new DoubleLiteral(0), rewritten);
-        exExp = new Acos(new DoubleLiteral(2d));
-        rewritten = executor.rewrite(exExp, context);
+        acos = new Acos(new DoubleLiteral(2d));
+        rewritten = executor.rewrite(acos, context);
         Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE), 
rewritten);
 
+        Atan atan = new Atan(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(atan, context);
+        Assertions.assertEquals(new DoubleLiteral(1.5707963267948966), 
rewritten);
+        atan = new Atan(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(atan, context);
+        Assertions.assertEquals(new DoubleLiteral(-1.5707963267948966), 
rewritten);
+        atan = new Atan(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(atan, context);
+        Assertions.assertEquals(atan, rewritten);
+
+        Cbrt cbrt = new Cbrt(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(cbrt, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        cbrt = new Cbrt(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(cbrt, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        cbrt = new Cbrt(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(cbrt, context);
+        Assertions.assertEquals(cbrt, rewritten);
+
+        Cosh cosh = new Cosh(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(cosh, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        cosh = new Cosh(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(cosh, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        cosh = new Cosh(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(cosh, context);
+        Assertions.assertEquals(cosh, rewritten);
+
+        Tanh tanh = new Tanh(new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(tanh, context);
+        Assertions.assertEquals(new DoubleLiteral(1d), rewritten);
+        tanh = new Tanh(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(tanh, context);
+        Assertions.assertEquals(new DoubleLiteral(-1d), rewritten);
+        tanh = new Tanh(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(tanh, context);
+        Assertions.assertEquals(tanh, rewritten);
+
         Sign sign = new Sign(new DoubleLiteral(1d));
         rewritten = executor.rewrite(sign, context);
         Assertions.assertEquals(new TinyIntLiteral((byte) 1), rewritten);
@@ -668,6 +814,82 @@ class FoldConstantTest extends ExpressionRewriteTestHelper 
{
         bitCount = new BitCount(new BigIntLiteral(-1));
         rewritten = executor.rewrite(bitCount, context);
         Assertions.assertEquals(new TinyIntLiteral((byte) 64), rewritten);
+
+        Add add = new Add(new DoubleLiteral(Double.POSITIVE_INFINITY), new 
DoubleLiteral(100));
+        rewritten = executor.rewrite(add, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        add = new Add(new DoubleLiteral(Double.POSITIVE_INFINITY), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(add, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        add = new Add(new DoubleLiteral(Double.NEGATIVE_INFINITY), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(add, context);
+        Assertions.assertEquals(add, rewritten);
+        add = new Add(new DoubleLiteral(Double.NaN), new DoubleLiteral(1));
+        rewritten = executor.rewrite(add, context);
+        Assertions.assertEquals(add, rewritten);
+
+        Subtract subtract = new Subtract(new 
DoubleLiteral(Double.POSITIVE_INFINITY), new DoubleLiteral(100));
+        rewritten = executor.rewrite(subtract, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        subtract = new Subtract(new DoubleLiteral(1), new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(subtract, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        subtract = new Subtract(new DoubleLiteral(Double.POSITIVE_INFINITY), 
new DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(subtract, context);
+        Assertions.assertEquals(subtract, rewritten);
+
+        Multiply multiply = new Multiply(new DoubleLiteral(1e300), new 
DoubleLiteral(1e100));
+        rewritten = executor.rewrite(multiply, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        multiply = new Multiply(new DoubleLiteral(-1e300), new 
DoubleLiteral(1e100));
+        rewritten = executor.rewrite(multiply, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        multiply = new Multiply(new DoubleLiteral(Double.POSITIVE_INFINITY), 
new DoubleLiteral(100));
+        rewritten = executor.rewrite(multiply, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        multiply = new Multiply(new DoubleLiteral(Double.POSITIVE_INFINITY), 
new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(multiply, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+
+        Divide divide = new Divide(new 
DoubleLiteral(Double.POSITIVE_INFINITY), new DoubleLiteral(1e100));
+        rewritten = executor.rewrite(divide, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        divide = new Divide(new DoubleLiteral(Double.NEGATIVE_INFINITY), new 
DoubleLiteral(1e100));
+        rewritten = executor.rewrite(divide, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        divide = new Divide(new DoubleLiteral(Double.NEGATIVE_INFINITY), new 
DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(divide, context);
+        Assertions.assertEquals(divide, rewritten);
+
+        Fmod fmod = new Fmod(new DoubleLiteral(Double.POSITIVE_INFINITY), new 
DoubleLiteral(1));
+        rewritten = executor.rewrite(fmod, context);
+        Assertions.assertEquals(fmod, rewritten);
+        fmod = new Fmod(new DoubleLiteral(Double.NEGATIVE_INFINITY), new 
DoubleLiteral(1));
+        rewritten = executor.rewrite(fmod, context);
+        Assertions.assertEquals(fmod, rewritten);
+        fmod = new Fmod(new DoubleLiteral(Double.NaN), new DoubleLiteral(1));
+        rewritten = executor.rewrite(fmod, context);
+        Assertions.assertEquals(fmod, rewritten);
+
+        Radians radians = new Radians(new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(radians, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        radians = new Radians(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(radians, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        radians = new Radians(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(radians, context);
+        Assertions.assertEquals(rewritten, rewritten);
+
+        Degrees degrees = new Degrees(new 
DoubleLiteral(Double.POSITIVE_INFINITY));
+        rewritten = executor.rewrite(degrees, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY), 
rewritten);
+        degrees = new Degrees(new DoubleLiteral(Double.NEGATIVE_INFINITY));
+        rewritten = executor.rewrite(degrees, context);
+        Assertions.assertEquals(new DoubleLiteral(Double.NEGATIVE_INFINITY), 
rewritten);
+        degrees = new Degrees(new DoubleLiteral(Double.NaN));
+        rewritten = executor.rewrite(degrees, context);
+        Assertions.assertEquals(degrees, rewritten);
     }
 
     @Test
diff --git 
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_struct.out
 
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_struct.out
index fa63c0da504..5f40301cb15 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_struct.out
 and 
b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_struct.out
 differ
diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index b5a3f78dd9d..c23079331b4 100644
--- 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -1793,7 +1793,8 @@ class Suite implements GroovyInterceptable {
         String closeFoldConstant = "set debug_skip_fold_constant=true";
         sql(closeFoldConstant)
         logger.info(foldSql)
-        List<List<Object>> resultExpected = sql(foldSql)
+        Tuple2<List<List<Object>>, ResultSetMetaData> tupleResult2 = 
JdbcUtils.executeToStringList(context.getConnection(), foldSql)
+        List<List<Object>> resultExpected = tupleResult2.first
         logger.info("result expected: " + resultExpected.toString())
 
         String errorMsg = null
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 97a70ac3c0c..5ded6898d9f 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
@@ -65,6 +65,11 @@ suite("fold_constant_numeric_arithmatic") {
     testFoldConst("SELECT ASIN(1E308)")
     testFoldConst("SELECT ASIN(-1E308)")
 
+    // Add function cases
+    testFoldConst("SELECT ADD(1e1000, 1)");
+    testFoldConst("SELECT ADD(-1e1000, 1)");
+    testFoldConst("SELECT ADD(cast(\"nan\" as double), 1)");
+
 //Atan function cases
     testFoldConst("SELECT ATAN(1) AS atan_case_1") //atan(1) = π/4
     testFoldConst("SELECT ATAN(0) AS atan_case_2") //atan(0) = 0
@@ -251,6 +256,7 @@ suite("fold_constant_numeric_arithmatic") {
     testFoldConst("SELECT EXP(-1E-308)") // Very small negative number
     testFoldConst("SELECT EXP(709.782712893384)") // Near overflow boundary
     testFoldConst("SELECT EXP(-709.782712893384)") // Near underflow boundary
+    testFoldConst("SELECT EXP(1959859681)") // Result overflow become infinity
 
 //Floor function cases
     testFoldConst("SELECT FLOOR(3.7) AS floor_case_1")
@@ -301,6 +307,8 @@ suite("fold_constant_numeric_arithmatic") {
 //    testFoldConst("SELECT POWER(2, 1E308)")
     testFoldConst("SELECT POWER(1E-308, 2)") // Very small base
     testFoldConst("SELECT POWER(2, -1E308)") // Very small negative exponent
+    testFoldConst("SELECT POWER(-1.1, 3.2)") // NaN
+    testFoldConst("SELECT POWER(1, 1e1000)")
 
 //Ln function cases
     testFoldConst("SELECT LN(1) AS ln_case_1") //ln(1) = 0
@@ -459,6 +467,8 @@ suite("fold_constant_numeric_arithmatic") {
     testFoldConst("SELECT SQRT(16) AS sqrt_case_1") //sqrt(16) = 4
     testFoldConst("SELECT SQRT(0) AS sqrt_case_2") //sqrt(0) = 0
     testFoldConst("SELECT SQRT(2) AS sqrt_case_3") //sqrt(2)
+    //testFoldConst("SELECT SQRT(1e1000)") //sqrt(2)
+    testFoldConst("SELECT SQRT(-1e1000)") //sqrt(2)
 
 //Tan function cases
     testFoldConst("SELECT TAN(PI() / 4) AS tan_case_1") //tan(π/4) = 1


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

Reply via email to