[fix](fe) Fix datediff folding for zero date#64084
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: FE constant folding for DATEDIFF used Java proleptic date arithmetic, while BE runtime evaluates DATEDIFF by subtracting Doris day numbers. For zero-date inputs such as 0000-01-01, Java date arithmetic disagrees with Doris day-number semantics, so folded DATEDIFF could return a different result from runtime execution and from TO_DAYS(a) - TO_DAYS(b). This change reuses the FE day-number calculation used by TO_DAYS for DATEDIFF folding, keeping folded and runtime semantics consistent for zero-date boundary cases.
### Release note
None
### Check List (For Author)
- Test: Unit Test
- Attempted: ./run-fe-ut.sh --run org.apache.doris.nereids.rules.expression.FoldConstantTest
- Result: failed before running tests because current FE compile fails in LogicalPlanBuilder.java with missing ctx.HOT(); the DATEDIFF-specific compile errors found in the first run were fixed and did not recur.
- Behavior changed: No
- Does this need documentation: No
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
|
run buildall |
TPC-H: Total hot run time: 29093 ms |
TPC-DS: Total hot run time: 168752 ms |
TPC-H: Total hot run time: 29560 ms |
TPC-DS: Total hot run time: 172066 ms |
FE Regression Coverage ReportIncrement line coverage |
|
run p0 |
|
run cloud_p0 |
|
run external |
|
run nonConcurrent |
FE Regression Coverage ReportIncrement line coverage |
3 similar comments
FE Regression Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
|
/review |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
There was a problem hiding this comment.
Code review completed. I did not find any blocking correctness issue in this PR.
Critical checkpoint conclusions:
- Goal and test: The PR aims to make Nereids constant folding for
datediffuse Doris day-number semantics instead of Java date arithmetic. The change accomplishes this for the modified DateV2/DateTimeV2 folding paths, and the added FE unit cases cover the reported0000-01-01boundary for DateV2 and DateTimeV2 operands. - Scope and clarity: The change is small and focused. It reuses the existing FE
to_daysday-number calculation rather than adding a separate divergent implementation. - Concurrency and lifecycle: No concurrency, locking, static initialization, or non-trivial lifecycle behavior is introduced.
- Configuration and compatibility: No new configuration, storage format, FE-BE protocol, or incompatible behavior is introduced.
- Parallel paths: BE runtime
datediffsubtractsdaynr()values, and the exposed FE helper mirrors BEcalc_daynrspecial handling. I did not find another changed path that needs the same modification in this PR. - Conditional logic: The zero-date special handling already exists in the shared day-number helper and matches BE semantics.
- Test coverage: Coverage is limited to FE unit tests and specifically includes the zero-date folding case. I did not run tests locally in this review.
- Observability: No new observability is needed for this constant-folding change.
- Transaction, persistence, and data writes: Not applicable.
- Performance and memory: The new logic is constant-time and does not introduce material allocation or memory-tracking concerns.
User focus response: No additional user-provided review focus was supplied.
FE Regression Coverage ReportIncrement line coverage |
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: FE constant folding for DATEDIFF used Java proleptic date arithmetic, while BE runtime evaluates DATEDIFF by subtracting Doris day numbers. For zero-date inputs such as 0000-01-01, Java date arithmetic disagrees with Doris day-number semantics, so folded DATEDIFF could return a different result from runtime execution and from TO_DAYS(a) - TO_DAYS(b). This change reuses the FE day-number calculation used by TO_DAYS for DATEDIFF folding, keeping folded and runtime semantics consistent for zero-date boundary cases.
Release note
None
Check List (For Author)
What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)