This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 616a17942e0 branch-4.2: [fix](cast) Compare fractional literal values
in their own precision when casting to BOOLEAN #68729 (#70023)
616a17942e0 is described below
commit 616a17942e000bf12cae5986dca665221cda6069
Author: morrySnow <[email protected]>
AuthorDate: Thu Nov 5 09:43:09 2026 +0800
branch-4.2: [fix](cast) Compare fractional literal values in their own
precision when casting to BOOLEAN #68729 (#70023)
picked from master #68729
Co-authored-by: Abhinav <[email protected]>
---
.../nereids/trees/expressions/literal/FractionalLiteral.java | 2 +-
.../nereids/trees/expressions/literal/DoubleLiteralTest.java | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java
index 4a287143db0..e622e4c45af 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/FractionalLiteral.java
@@ -89,7 +89,7 @@ public abstract class FractionalLiteral extends
NumericLiteral {
} else if (targetType.isBooleanType()) {
Object value = getValue();
if (value instanceof Float || value instanceof Double) {
- if (((Number) value).floatValue() == 0) {
+ if (((Number) value).doubleValue() == 0) {
return BooleanLiteral.FALSE;
} else {
return BooleanLiteral.TRUE;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteralTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteralTest.java
index 052137d6921..bbbadbbb35b 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteralTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DoubleLiteralTest.java
@@ -56,6 +56,18 @@ class DoubleLiteralTest {
f1 = new DoubleLiteral(Double.POSITIVE_INFINITY);
Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+ // nonzero doubles that round to zero when narrowed to float must
still be TRUE
+ f1 = new DoubleLiteral(Double.MIN_VALUE);
+ Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+ f1 = new DoubleLiteral(-Double.MIN_VALUE);
+ Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+ f1 = new DoubleLiteral(1e-300);
+ Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+ f1 = new DoubleLiteral(1e-46);
+ Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+ f1 = new DoubleLiteral(5e-324);
+ Assertions.assertTrue(((BooleanLiteral)
f1.uncheckedCastTo(BooleanType.INSTANCE)).getValue());
+
// To integral
f1 = new DoubleLiteral(12.999);
Expression expression = f1.uncheckedCastTo(TinyIntType.INSTANCE);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]