924060929 commented on code in PR #70204:
URL: https://github.com/apache/doris/pull/70204#discussion_r4581418347


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java:
##########
@@ -172,40 +184,92 @@ private static LocalDateTime 
getDateCeilOrFloorForTimestampTz(DATE tag, LocalDat
         }
         ZoneId zoneId = ZoneId.of(timeZone);
 
-        // Get the ZonedDateTime for the date to determine its offset
-        ZonedDateTime zonedDate = 
utcDate.atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId);
-
-        // Use the date's offset to ensure consistent conversion for both date 
and origin
-        // This prevents historical timezone offset inconsistencies (e.g., 
Asia/Shanghai
-        // used +08:05:43 before 1900, then +08:00 after) from affecting the 
calculation
-        ZoneId fixedOffsetZone = ZoneId.ofOffset("UTC", zonedDate.getOffset());
-
-        // Convert UTC time to local time using the fixed offset from date
-        LocalDateTime localDate = 
utcDate.atZone(ZoneId.of("UTC")).withZoneSameInstant(fixedOffsetZone)
-                .toLocalDateTime();
-
-        // Handle origin: START_ORIGINAL_DAY is already in local time, don't 
convert it
-        // Only convert origin if it's a real UTC timestamp (from 
TimestampTzLiteral)
-        LocalDateTime localOrigin;
-        if (utcOrigin.equals(START_ORIGINAL_DAY)) {
-            localOrigin = START_ORIGINAL_DAY;
-        } else {
-            localOrigin = 
utcOrigin.atZone(ZoneId.of("UTC")).withZoneSameInstant(fixedOffsetZone)
-                    .toLocalDateTime();
+        // Seconds use the UTC time line in BE. They do not need a local 
calendar boundary.
+        if (tag == DATE.SECOND) {
+            return getDateCeilOrFloor(tag, utcDate, period, utcOrigin, 
getCeil);
         }
+        ZonedDateTime zonedDate = 
utcDate.atZone(ZoneOffset.UTC).withZoneSameInstant(zoneId);
+        LocalDateTime localDate = zonedDate.toLocalDateTime();
+
+        // The default origin is a local calendar value. A supplied origin is 
an instant.
+        // On Lord Howe, an Oct 5 origin uses +10:30 even if the Oct 6 input 
uses +11:00.
+        LocalDateTime localOrigin = utcOrigin.equals(START_ORIGINAL_DAY) ? 
START_ORIGINAL_DAY
+                : 
utcOrigin.atZone(ZoneOffset.UTC).withZoneSameInstant(zoneId).toLocalDateTime();
+        // Keep the input's occurrence for hour and minute boundaries in an 
overlap, as BE does.
+        ZoneOffset preferredOffset = tag == DATE.HOUR || tag == DATE.MINUTE ? 
zonedDate.getOffset() : null;
+
+        Instant input = utcDate.toInstant(ZoneOffset.UTC);
+        Instant selected = null;
+        LocalDateTime localResult = getOptionalCalendarBoundary(tag, 
localDate, period, localOrigin, getCeil);
+        // On Lord Howe, the 02:15 gap candidate becomes 02:45, after input 
02:35.
+        // Recompute each candidate from the original calendar origin.
+        while (localResult != null) {
+            Instant candidate = DateUtils.convertLocalToInstant(localResult, 
zoneId, preferredOffset);
+            if (getCeil || !candidate.isAfter(input)) {

Review Comment:
   [P2] Reject ceil candidates that resolve before the input
   
   The `getCeil` branch accepts the candidate without checking its instant. 
During a fall-back overlap, a later clock reading can refer to an earlier 
instant. With session zone `America/New_York`, calling `dayCeil(input, 1, 
origin)` with input `2024-11-03 01:15:00-05:00` (the second occurrence, 
`06:15Z`) and origin `2024-11-02 01:30:00-04:00` produces local candidate 
`2024-11-03 01:30`. For DAY, `preferredOffset` is null, so this resolves to the 
first occurrence (`05:30Z`). The ceil result is therefore **45 minutes before 
the input**. The subsequent gap-only search does not correct an overlap.
   
   I reproduced this by directly invoking the FE classes compiled at head 
`10f4ebaa65b`. The pre-change FE method with the same arguments returns 
`2024-11-04T05:30Z`; its origin-offset behavior is a separate issue, but it 
does not return a ceil before the input. BE already has the analogous overlap 
issue, so this finding specifically concerns the newly affected FE path.
   
   Please enforce the instant bound in both directions (`floor <= input`, `ceil 
>= input`) and recompute the adjacent grid boundary from the original origin 
when it fails. Under the current policy of resolving DAY boundaries to the 
first occurrence, this case should advance to `2024-11-04 01:30:00-05:00` 
(`06:30Z`). Please add this overlap case to the FE tests and the FE/BE 
regression comparison.



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