You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "r33s3n6 (via GitHub)" <gi...@apache.org> on 2026/10/04 08:59:04 UTC
[I] [Bug] ceil(DOUBLE) folded by FE returns +0 for values in (-1, 0), BE returns -0 [doris]
r33s3n6 opened a new issue, #68719:
URL: https://github.com/apache/doris/issues/68719
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues.
### Version
4.1.4 (doris-4.1.4-rc04-ad35a140c7f), single FE + single BE
### What's Wrong?
`ceil(-0.5)` on a DOUBLE is -0 when BE computes it and +0 when FE folds the constant, so `signbit(ceil(...))` is 1 and 0. `round(-0.4)` behaves the same.
FE folding: `signbit(...)` = 0. BE: 1.
```
SET enable_sql_cache = false
SELECT signbit(ceil(CAST(-0.5 AS DOUBLE))) AS fe, signbit(ceil(d1)) AS be FROM t
+------+------+
| fe | be |
+------+------+
| 0 | 1 |
+------+------+
SET debug_skip_fold_constant = true
SELECT signbit(ceil(CAST(-0.5 AS DOUBLE)))
+-------------------------------------+
| signbit(ceil(CAST(-0.5 AS DOUBLE))) |
+-------------------------------------+
| 1 |
+-------------------------------------+
```
- **FE constant folding**: all arguments are literals, so Nereids folds the call during planning. Check: EXPLAIN shows the literal in place of the call: `final projections: FALSE, signbit(ceil(d1[#1]))`
- **BE execution**: the arguments are columns (or `SET debug_skip_fold_constant = true`), so BE computes the call. Check: EXPLAIN keeps the call.
### What You Expected?
FE folding and BE give the same sign of zero, so `signbit` agrees.
### How to Reproduce?
Deployment: single FE + single BE, default session variables.
```sql
CREATE TABLE t(id INT, d1 DOUBLE)
DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1');
INSERT INTO t VALUES (1, -0.5);
SET enable_sql_cache = false;
SELECT signbit(ceil(CAST(-0.5 AS DOUBLE))) AS fe, signbit(ceil(d1)) AS be FROM t;
SET debug_skip_fold_constant = true;
SELECT signbit(ceil(CAST(-0.5 AS DOUBLE)));
```
### Anything Else?
FE converts the double to `BigDecimal` (through `DecimalV3Literal`), which has no negative zero; BE calls the C library `ceil`, which returns -0.
- FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L404-L408](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L404-L408) — `ceil(DoubleLiteral)`: through `BigDecimal`
- BE: [be/src/exprs/function/round.h#L255-L258](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/round.h#L255-L258) — `roundWithMode`: C `floor`/`ceil`
Found with AI assistance.
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
Re: [I] [Bug] ceil(DOUBLE) folded by FE returns +0 for values in (-1, 0), BE returns -0 [doris]
Posted by "Doris-Breakwater (via GitHub)" <gi...@apache.org>.
Doris-Breakwater commented on issue #68719:
URL: https://github.com/apache/doris/issues/68719#issuecomment-5978346755
Breakwater-GitHub-Analysis-Slot: slot_f96fff56a738
**Assessment:** This is a credible, source-supported FE constant-folding inconsistency for `DOUBLE` signed zero. The supplied SQL results show `signbit(ceil(-0.5))` changing with the execution path. I reviewed the reported 4.1.4 source, but did not run a Doris cluster.
**Mechanism verified in source:** Nereids evaluates `ceil(DoubleLiteral)` and `round(DoubleLiteral)` by converting the input to `BigDecimal`/`DecimalV3Literal`, rounding there, and converting the result back to `double` ([FE implementation](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L363-L410), [decimal conversion](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java#L88-L113)). That path loses the negative sign when the rounded value is zero. The FE `signbit` fold checks the double's raw sign bit ([source](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java#L729-L734)), so it then returns false. For `DOUBLE`, BE dispatches `ceil` and `round` to floating-point math functions ([source
](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/round.h#L245-L260)), which preserve `-0.0` for these inputs; BE `signbit` uses `std::signbit` ([source](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/math.cpp#L784-L794)). A standalone Java `BigDecimal` check and local C `libm` check produced the corresponding opposite zero signs. `debug_skip_fold_constant` disables both FE and BE fold rules ([FE](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java#L845-L852), [BE](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnBE.java#L128-L140)), consistent with the reported comparison.
**Suggested next step:** Align FE folding of `DOUBLE` rounding functions with BE signed-zero semantics, then add a regression that compares folded and unfolded `signbit(ceil(CAST(-0.5 AS DOUBLE)))` and `signbit(round(CAST(-0.4 AS DOUBLE)))`. Cover `-0.0`, positive zero, boundary values, and two-argument overloads where applicable, while keeping `DECIMAL` behavior separate. The existing `signbit` negative-zero regression covers direct literals, but not zero produced by rounding.
**Missing information:** No logs or profile are needed to investigate this specific discrepancy. For release tracking, please confirm the exact FE/BE binary build: the reported `rc04` label is paired with commit `ad35a140c7f`, which corresponds to the local `4.1.4` tag; the relevant source files are identical between local `4.1.4-rc04` and `4.1.4` tags.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org