Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}

Expand Down Expand Up @@ -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())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading