This is an automated email from the ASF dual-hosted git repository.

englefly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 7cce1a4ad5c [fix](Nereids) fix log and power (#46077)
7cce1a4ad5c is described below

commit 7cce1a4ad5c7beb360b49794341f5d14c3d0156b
Author: LiBinfeng <libinf...@selectdb.com>
AuthorDate: Mon Dec 30 15:14:52 2024 +0800

    [fix](Nereids) fix log and power (#46077)
    
    ### What problem does this PR solve?
    Problem Summary:
    log should not have 1 as the first value, power should not have negative
    number and non-integer as input at the same time, or it
    would result in non-real number
---
 .../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 75888f08c32..624a47f11bd 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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to