Doris-Breakwater commented on issue #71183:
URL: https://github.com/apache/doris/issues/71183#issuecomment-7297580666

   Breakwater-GitHub-Analysis-Slot: slot_872d1e949905
   
   Confirmed from source as a backend datetime correctness bug on 
`b4140d0b0538` and `917b20be838` (4.1.5). The same conversion is present at the 
inspected `master` and `branch-4.1` heads. [Reported 
master](https://github.com/apache/doris/blob/b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927/be/src/core/value/vdatetime_value.cpp#L2546-L2564),
 
[4.1.5](https://github.com/apache/doris/blob/917b20be83878e98f94e3ebf7efccc80346e3e50/be/src/core/value/vdatetime_value.cpp#L2546-L2564),
 [master 
head](https://github.com/apache/doris/blob/d2111336efa0b1a64d98d65d86bb633fc5d9ed71/be/src/core/value/vdatetime_value.cpp#L2546-L2564),
 [4.1 
head](https://github.com/apache/doris/blob/2cd3b9f5f6ffaeffb90335f04b3918cea0cf0509/be/src/core/value/vdatetime_value.cpp#L2546-L2564)
   
   `TIMESTAMPADD(MINUTE, ...)` and `DATE_ADD(... INTERVAL ... MINUTE)` bind to 
`MinutesAdd`. `DATE_SUB(... INTERVAL ... MINUTE)` binds to `MinutesSub`, whose 
backend implementation delegates to addition with the opposite sign. The 
`BIGINT` minute count becomes a `uint64_t` magnitude in `TimeInterval`. 
Multiplication by 60 wraps modulo `2^64` before the date-range check. I checked 
the arithmetic for the reported add cases. The effective offsets are `+300`, 
`-120`, and `+44` seconds, which explains the dates in the report, including 
the result that moves by less than a minute. [SQL 
binding](https://github.com/apache/doris/blob/b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/DatetimeFunctionBinder.java#L185-L257),
 [backend 
addition](https://github.com/apache/doris/blob/b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927/be/src/exprs/function/function_date_or_datetime_computation.h#L100-L145),
 [backend subtraction](https://github.com/apache/
 
doris/blob/b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927/be/src/exprs/function/function_date_or_datetime_computation.h#L447-L485)
   
   Bound the signed minute count by the full supported datetime span before 
taking an absolute value or negating it, then keep the existing date-range 
check for the actual base timestamp. Use the existing out-of-range error. The 
early check also covers `INT64_MIN`, for which signed negation and `abs` 
overflow. Add regression coverage for the reported literals and a `BIGINT` 
column, both signs and `INT64_MIN`, valid offsets that preserve fractional 
seconds, and offsets that cross the datetime bounds. Check frontend constant 
folding as well as backend evaluation. The quarter fix is a precedent for 
checking the unit conversion before calendar arithmetic. [Datetime range 
contract](https://doris.apache.org/docs/4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/minutes-add/),
 [quarter fix](https://github.com/apache/doris/pull/68410)
   
   The supplied SQL and build versions are sufficient for triage. Runtime 
results above come from the report, with independent source and arithmetic 
checks. The branch regression runs, including the `INT64_MIN` and 
constant-folding cases, remain to be verified.
   


-- 
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]

Reply via email to