jacktengg commented on code in PR #70485:
URL: https://github.com/apache/doris/pull/70485#discussion_r4586815417


##########
be/src/exprs/function/function_date_or_datetime_computation.h:
##########
@@ -769,21 +769,57 @@ 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>>) {
+            // Parsed UTC 0000-02-29 can become valid local February 28 in 
-08:00.
+            // Reject it before changing years can hide the invalid UTC source.
+            if (!from.is_valid_date()) [[unlikely]] {
+                throw_out_of_bound_date_int(Transform::name, from, delta);
+            }
+            // 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);
+            using LocalTransform =
+                    std::conditional_t<std::is_same_v<Transform, 
AddYearsImpl<TYPE_TIMESTAMPTZ>>,
+                                       AddYearsImpl<TYPE_DATETIMEV2>,
+                                       SubtractYearsImpl<TYPE_DATETIMEV2>>;
+            const auto local_result = LocalTransform::execute(local, delta);
+            TimestampTzValue result;
+            // Keep the input offset when the target time occurs twice during 
a DST change.
+            // This also keeps years_add(ts, 0) equal to ts in the repeated 
hour.
+            result.convert_local_to_utc(timezone, local_result, 
from.utc_offset(timezone));

Review Comment:
   fixed



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