r33s3n6 opened a new issue, #68725: URL: https://github.com/apache/doris/issues/68725
### 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? `time_format('-10:00:00', '%a')` folds to the string `-null` in FE; BE returns NULL. Any date specifier (`%a %b %D %j %M %U %u %V %v %W %w %X %x`) on a negative time does this. FE folding: the string `-null`. BE: NULL. ``` SET enable_sql_cache = false SELECT time_format('-10:00:00', '%a') AS fe, time_format(CAST(s1 AS TIME), '%a') AS be FROM t +-------+------+ | fe | be | +-------+------+ | -null | NULL | +-------+------+ SET debug_skip_fold_constant = true SELECT time_format('-10:00:00', '%a') +--------------------------------+ | time_format('-10:00:00', '%a') | +--------------------------------+ | NULL | +--------------------------------+ ``` - **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: '-null', time_format(CAST(s1[#1] AS time(0)), '%a')` - **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? Both return NULL. ### How to Reproduce? Deployment: single FE + single BE, default session variables. ```sql CREATE TABLE t(id INT, s1 STRING) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num' = '1'); INSERT INTO t VALUES (1, '-10:00:00'); SET enable_sql_cache = false; SELECT time_format('-10:00:00', '%a') AS fe, time_format(CAST(s1 AS TIME), '%a') AS be FROM t; SET debug_skip_fold_constant = true; SELECT time_format('-10:00:00', '%a'); ``` ### Anything Else? `toFormatStringConservative` gets `null` from `formatTemporalLiteral` for date specifiers and, for a negative time, prepends `-`, producing the string `-null`; for a positive time the null makes folding fail and BE computes the result. - FE: [fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java#L177-L185](https://github.com/apache/doris/blob/4.1.4/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java#L177-L185) — `toFormatStringConservative`: `res = "-" + res` - BE: [be/src/exprs/function/date_time_transforms.h#L572-L575](https://github.com/apache/doris/blob/4.1.4/be/src/exprs/function/date_time_transforms.h#L572-L575) — `FunctionTimeFormat`: NULL when the format needs date fields 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]
