This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new d07c8ea5bcf branch-4.1: [Fix](FoldConst) Preserve NaN in numeric
constant folding #63870 (#63909)
d07c8ea5bcf is described below
commit d07c8ea5bcf8c43c766ca1f273e7e926bf4af9e2
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat May 30 21:54:51 2026 +0800
branch-4.1: [Fix](FoldConst) Preserve NaN in numeric constant folding
#63870 (#63909)
Cherry-picked from #63870
Co-authored-by: linrrarity <[email protected]>
---
.../functions/executable/NumericArithmetic.java | 3 +++
.../nereids/rules/expression/FoldConstantTest.java | 20 +++++++++++++++++++-
.../fold_constant_numeric_arithmatic.groovy | 7 +++++++
3 files changed, 29 insertions(+), 1 deletion(-)
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 47d19737690..1fa7c4fe349 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
@@ -324,6 +324,9 @@ public class NumericArithmetic {
boolean isLowerInclusive, boolean isUpperInclusive) {
if (input instanceof DoubleLiteral) {
double inputValue = ((DoubleLiteral) input).getValue();
+ if (Double.isNaN(inputValue)) {
+ return false;
+ }
boolean lowerCheck = isLowerInclusive ? (inputValue >= lowerBound)
: (inputValue > lowerBound);
// Check upper bound
boolean upperCheck = isUpperInclusive ? (inputValue <= upperBound)
: (inputValue < upperBound);
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 424cda4a7c4..fd20c4f5b43 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
@@ -772,30 +772,48 @@ class FoldConstantTest extends
ExpressionRewriteTestHelper {
exExp = new Ln(new DoubleLiteral(-1d));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE),
rewritten);
+ exExp = new Ln(new DoubleLiteral(Double.NaN));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
exExp = new Log(new DoubleLiteral(1.0d), new DoubleLiteral(1.0d));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE),
rewritten);
exExp = new Log(new DoubleLiteral(10d), new
DoubleLiteral(Double.POSITIVE_INFINITY));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY),
rewritten);
+ exExp = new Log(new DoubleLiteral(2d), new DoubleLiteral(Double.NaN));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
+ exExp = new Log(new DoubleLiteral(Double.NaN), new DoubleLiteral(2d));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
exExp = new Log2(new DoubleLiteral(Double.POSITIVE_INFINITY));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY),
rewritten);
exExp = new Log2(new DoubleLiteral(-1d));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE),
rewritten);
+ exExp = new Log2(new DoubleLiteral(Double.NaN));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
exExp = new Log10(new DoubleLiteral(Double.POSITIVE_INFINITY));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY),
rewritten);
exExp = new Log10(new DoubleLiteral(-1d));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE),
rewritten);
+ exExp = new Log10(new DoubleLiteral(Double.NaN));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
exExp = new Dlog10(new DoubleLiteral(Double.POSITIVE_INFINITY));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new DoubleLiteral(Double.POSITIVE_INFINITY),
rewritten);
exExp = new Dlog10(new DoubleLiteral(-1d));
rewritten = executor.rewrite(exExp, context);
Assertions.assertEquals(new NullLiteral(DoubleType.INSTANCE),
rewritten);
+ exExp = new Dlog10(new DoubleLiteral(Double.NaN));
+ rewritten = executor.rewrite(exExp, context);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
Sqrt sqrt = new Sqrt(new DoubleLiteral(16d));
rewritten = executor.rewrite(sqrt, context);
@@ -846,7 +864,7 @@ class FoldConstantTest extends ExpressionRewriteTestHelper {
Assertions.assertEquals(exExp, rewritten);
exExp = new Power(new DoubleLiteral(-1d), new
DoubleLiteral(Double.NaN));
rewritten = executor.rewrite(exExp, context);
- Assertions.assertEquals(exExp, rewritten);
+ Assertions.assertEquals(new DoubleLiteral(Double.NaN), rewritten);
Sin sin = new Sin(new DoubleLiteral(Math.PI / 2));
rewritten = executor.rewrite(sin, context);
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 f17705460a9..0de2486d775 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
@@ -356,6 +356,7 @@ suite("fold_constant_numeric_arithmatic") {
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, cast('nan' as double))")
testFoldConst("SELECT POWER(1, 1e1000)")
//Ln function cases
@@ -371,6 +372,7 @@ suite("fold_constant_numeric_arithmatic") {
testFoldConst("SELECT LN(2)") // ln(2)
testFoldConst("SELECT LN(0.1)") // Small decimal
testFoldConst("SELECT LN(100)") // Larger number
+ testFoldConst("SELECT LN(cast('nan' as double))")
//dlog1 function cases
testFoldConst("SELECT dlog1(1)")
@@ -400,6 +402,8 @@ suite("fold_constant_numeric_arithmatic") {
testFoldConst("SELECT LOG(100, 1E308)") // Very large base
testFoldConst("SELECT LOG(1E-308, 10)") // Very small number
testFoldConst("SELECT LOG(100, 1E-308)") // Very small base
+ testFoldConst("SELECT LOG(2, cast('nan' as double))")
+ testFoldConst("SELECT LOG(cast('nan' as double), 2)")
//Log10 function cases
testFoldConst("SELECT LOG10(100) AS log10_case_1") //log10(100) = 2
@@ -416,6 +420,8 @@ suite("fold_constant_numeric_arithmatic") {
testFoldConst("SELECT LOG10(1E-308)") // Very small positive number
testFoldConst("SELECT LOG10(0.1)") // Decimal less than 1
testFoldConst("SELECT LOG10(0.01)") // Small decimal
+ testFoldConst("SELECT LOG10(cast('nan' as double))")
+ testFoldConst("SELECT DLOG10(cast('nan' as double))")
//Log2 function cases
testFoldConst("SELECT LOG2(2) AS log2_case_1") //log2(2) = 1
@@ -430,6 +436,7 @@ suite("fold_constant_numeric_arithmatic") {
testFoldConst("SELECT LOG2(0.5)") // Fraction
testFoldConst("SELECT LOG2(32)") // Power of 2
testFoldConst("SELECT LOG2(1024)") // Larger power of 2
+ testFoldConst("SELECT LOG2(cast('nan' as double))")
//Money_format function cases
testFoldConst("SELECT money_format(1234.56), money_format(-1234.56),
money_format(0.99), money_format(1234.5678)")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]