github-actions[bot] commented on code in PR #70485:
URL: https://github.com/apache/doris/pull/70485#discussion_r4578728534


##########
be/src/exprs/function/function_date_or_datetime_computation.h:
##########
@@ -769,21 +769,52 @@ struct DateTimeOp {
         }
     }
 
+    static ToType execute(const ValueType0& from, const ValueType1& delta,
+                          FunctionContext* context) {
+        if constexpr (std::is_same_v<Transform, 
AddYearsImpl<TYPE_TIMESTAMPTZ>> ||
+                      std::is_same_v<Transform, 
SubtractYearsImpl<TYPE_TIMESTAMPTZ>>) {
+            // Use the local date for calendar years. In +08:00, 2024-02-29 
00:00
+            // is 2024-02-28 16:00 UTC. A year added in UTC gives March 1 
locally.
+            // The DATETIME transform changes February 29 to February 28 when 
needed.
+            const auto& timezone = context->state()->timezone_obj();
+            DateV2Value<DateTimeV2ValueType> local;
+            from.convert_utc_to_local(timezone, local);

Review Comment:
   [P2] Validate the UTC source before converting to local time
   
   The new branch skips the UTC-input `is_valid_date()` check previously made 
by `TimestampTzValue::date_add_interval`. With `time_zone='-08:00'` and 
`debug_skip_fold_constant=true`, `years_add(CAST('0000-02-28 20:00:00 -08:00' 
AS TIMESTAMPTZ(6)), 1)` now succeeds: the existing BE string parser packs UTC 
`0000-02-29 04:00` (invalid under Doris's year-zero rule), but this conversion 
produces valid local February 28, and the year change hides the invalid source 
before the final UTC check. The old path rejected it; adding zero still errors. 
Validate `from.is_valid_date()` before conversion and cover add/sub at this 
boundary. This concerns the BE source date, distinct from the existing FE 
target-clamping finding.



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