From 7924bd7e7225b2ac1e16bd5f5121de3fa1c6e672 Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Thu, 26 Dec 2024 17:58:42 +0800 Subject: [PATCH 1/2] fix log and power --- .../functions/executable/NumericArithmetic.java | 6 ++++++ .../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 d739c830df2a17..6ab41167dc11be 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 static Expression ln(DoubleLiteral first) { @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 static Expression sqrt(DoubleLiteral first) { @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 0601b3b558d882..844353895bd584 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 @@ -50,6 +50,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.Log; import org.apache.doris.nereids.trees.expressions.functions.scalar.Ln; import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd; import org.apache.doris.nereids.trees.expressions.functions.scalar.Power; @@ -395,6 +396,11 @@ void testleFoldNumeric() { 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 @@ void testleFoldNumeric() { 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); From 34f33b1b1e1ab51b26b76618a791400012365e66 Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Fri, 27 Dec 2024 13:55:46 +0800 Subject: [PATCH 2/2] fix compile --- .../apache/doris/nereids/rules/expression/FoldConstantTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 844353895bd584..255a529500190c 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 @@ -50,8 +50,8 @@ 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.Log; 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;