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 5c1e37783e4 branch-3.0: [fix](Nereids) fix log and power #46077 
(#46636)
5c1e37783e4 is described below

commit 5c1e37783e422645548e269440b3f9b536a16843
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Jan 13 16:58:11 2025 +0800

    branch-3.0: [fix](Nereids) fix log and power #46077 (#46636)
    
    Cherry-picked from #46077
    
    Co-authored-by: LiBinfeng <[email protected]>
---
 .../expressions/functions/executable/NumericArithmetic.java    |  6 ++++++
 .../doris/nereids/rules/expression/FoldConstantTest.java       | 10 ++++++++++
 2 files changed, 16 insertions(+)

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 d739c830df2..6ab41167dc1 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
@@ -827,6 +827,9 @@ public class NumericArithmetic {
     @ExecFunction(name = "log")
     public static Expression log(DoubleLiteral first, DoubleLiteral second) {
         checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true);
+        if (first.getValue().equals(1.0d)) {
+            throw new NotSupportedException("the first input of function log 
can not be 1.0");
+        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.log(first.getValue()) / Math.log(second.getValue())));
     }
 
@@ -863,6 +866,9 @@ public class NumericArithmetic {
     @ExecFunction(name = "power")
     public static Expression power(DoubleLiteral first, DoubleLiteral second) {
         checkInputBoundary(second, Double.NEGATIVE_INFINITY, 
Double.POSITIVE_INFINITY, false, false);
+        if (first.getValue() < 0 && second.getValue() % 1 != 0) {
+            throw new NotSupportedException("input pair of function power can 
not be negative number and non-integer");
+        }
         return checkOutputBoundary(new 
DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
     }
 
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 0601b3b558d..255a5295001 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
@@ -51,6 +51,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.Floor;
 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.Ln;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.Log;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Power;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.Round;
@@ -395,6 +396,11 @@ class FoldConstantTest extends ExpressionRewriteTestHelper 
{
             executor.rewrite(exExp, context);
         }, "input -1 is out of boundary");
 
+        Assertions.assertThrows(NotSupportedException.class, () -> {
+            Log exExp = new Log(new DoubleLiteral(1.0d), new 
DoubleLiteral(1.0d));
+            executor.rewrite(exExp, context);
+        }, "the first input of function log can not be 1.0");
+
         Sqrt sqrt = new Sqrt(new DoubleLiteral(16d));
         rewritten = executor.rewrite(sqrt, context);
         Assertions.assertEquals(new DoubleLiteral(4d), rewritten);
@@ -413,6 +419,10 @@ class FoldConstantTest extends ExpressionRewriteTestHelper 
{
             Power exExp = new Power(new DoubleLiteral(2d), new 
DoubleLiteral(10000d));
             executor.rewrite(exExp, context);
         }, "infinite result is invalid");
+        Assertions.assertThrows(NotSupportedException.class, () -> {
+            Power exExp = new Power(new DoubleLiteral(-1d), new 
DoubleLiteral(1.1d));
+            executor.rewrite(exExp, context);
+        }, "input pair of function power can not be negative number and 
non-integer");
 
         Sin sin = new Sin(new DoubleLiteral(Math.PI / 2));
         rewritten = executor.rewrite(sin, context);


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

Reply via email to