r33s3n6 opened a new issue, #68723: URL: https://github.com/apache/doris/issues/68723
### 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? `date_add('0000-02-28', 1)` folds to 0000-02-29 in FE and is 0000-03-01 in BE; `last_day('0000-02-01')` is 0000-02-29 and 0000-02-28. `dayofyear`, `weekday`, `week` and other date functions differ for year 0 too. FE folding: `0000-02-29`, `0000-02-29`. BE: `0000-03-01`, `0000-02-28`. ``` SET enable_sql_cache = false SELECT date_add('0000-02-28', 1) AS fe1, last_day('0000-02-01') AS fe2 +------------+------------+ | fe1 | fe2 | +------------+------------+ | 0000-02-29 | 0000-02-29 | +------------+------------+ SELECT date_add(dt1, 1) AS be1, last_day(dt1) AS be2 FROM t +------------+------------+ | be1 | be2 | +------------+------------+ | 0000-03-01 | 0000-02-28 | +------------+------------+ SET debug_skip_fold_constant = true SELECT date_add('0000-02-28', 1), last_day('0000-02-01') +---------------------------+------------------------+ | date_add('0000-02-28', 1) | last_day('0000-02-01') | +---------------------------+------------------------+ | 0000-03-01 | 0000-02-28 | +---------------------------+------------------------+ ``` - **FE constant folding**: all arguments are literals, so Nereids folds the call during planning. Check: EXPLAIN shows the literal `0000-02-29` under `constant exprs:` in place of the call. - **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 and BE agree on whether year 0 is a leap year. ### How to Reproduce? Deployment: single FE + single BE, default session variables. ```sql CREATE TABLE t(id INT, dt1 DATE) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, '0000-02-28'); SET enable_sql_cache = false; SELECT date_add('0000-02-28', 1) AS fe1, last_day('0000-02-01') AS fe2; SELECT date_add(dt1, 1) AS be1, last_day(dt1) AS be2 FROM t; SET debug_skip_fold_constant = true; SELECT date_add('0000-02-28', 1), last_day('0000-02-01'); ``` ### Anything Else? FE date functions use `java.time` (proleptic ISO calendar, where year 0 is a leap year); BE's `is_leap` has `&& year`, so year 0 is not. - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateV2Literal.java#L62-L63](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateV2Literal.java#L62-L63) — `plusDays` through `java.time` - BE: [be/src/util/time_lut.h#L36-L38](https://github.com/apache/doris/blob/4.1.4/be/src/util/time_lut.h#L36-L38) — `is_leap`: `&& year` 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
