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


##########
be/src/core/value/timestamptz_value.cpp:
##########
@@ -168,7 +197,9 @@ void TimestampTzValue::convert_local_to_utc(const 
cctz::time_zone& local_time_zo
     cctz::civil_second local_cs(dt.year(), dt.month(), dt.day(), dt.hour(), 
dt.minute(),
                                 dt.second());
     const auto lookup = local_time_zone.lookup(local_cs);
-    cctz::time_point<cctz::seconds> local_tp = cctz::convert(local_cs, 
local_time_zone);
+    // Use the pre-transition offset to shift gap input by the gap length, 
e.g. New York's
+    // 2024-03-10 02:30 becomes 03:30. The preferred offset applies only to an 
overlap.
+    auto local_tp = lookup.pre;

Review Comment:
   The behaviour is fixed in pr https://github.com/apache/doris/pull/70204 and 
aligned with PostgreSQL(tested with PostgreSQL 18):
   ```
   SET TimeZone='America/New_York';
   SET DateStyle='ISO,YMD';
   WITH x AS(SELECT TIMESTAMPTZ '2024-03-10 03:15:00-04:00' as t, TIMESTAMPTZ 
'2024-03-09 00:30:00-05:00' AS o)
   
   <div class="line" data-lang="sql" style="box-sizing: border-box; margin: 
0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: medium; 
font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; 
font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; 
text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; 
-webkit-text-stroke-width: 0px; white-space: nowrap; text-decoration-thickness: 
initial; text-decoration-style: initial; text-decoration-color: initial;"><div 
class="batch" style="box-sizing: border-box; margin: 0px; display: flex; 
align-items: stretch;"><div class="io" style="box-sizing: border-box; margin: 
0px; flex: 1 0 auto; width: 1rem; display: flex;"><div class="output" 
data-markdown="| wall\_ceil\_in\_gap |
   |:-----------------|
   | 2024-03-10 03:30:00-04 |
   &gt; ``` status
   &gt; SELECT 1
   &gt; ```
   
   " style="box-sizing: border-box; margin: -0.45rem 0px -0.45rem 0.5rem; flex: 
1 0 auto; width: 1rem; border-left: 1px solid silver; padding: 0.5rem; 
min-height: 2.2rem;"><blockquote style="box-sizing: border-box; margin: 0.5rem 
0px 0px; display: block; overflow-x: auto;"><pre style="box-sizing: border-box; 
margin: 0px;"><code class="language-status" style="box-sizing: border-box; 
margin: 0px; display: block; border-left: 0.15rem solid rgb(42, 95, 205); 
padding-left: 0.3rem; color: rgb(42, 95, 205);">SELECT 1
   </code></pre></blockquote></div></div></div></div><div class="line" 
data-lang="sql" style="box-sizing: border-box; margin: 0px; color: rgb(0, 0, 
0); font-family: sans-serif; font-size: medium; font-style: normal; 
font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; 
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; 
text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 
0px; white-space: nowrap; text-decoration-thickness: initial; 
text-decoration-style: initial; text-decoration-color: initial;"><div 
class="icon plus" title="add" style="box-sizing: border-box; margin: 0px; 
opacity: 0.3;"><svg><use href="#plus"></use></svg></div><div class="batch" 
style="box-sizing: border-box; margin: 0px; display: flex; align-items: 
stretch;"><div class="controls" style="box-sizing: border-box; margin: 0px; 
flex: 0 0 1rem; display: flex; flex-direction: column; gap: 0.1rem; padding: 
0.1rem 0px;"><div class="icon hamburger" style=
 "box-sizing: border-box; margin: 0px; opacity: 0.3;"><svg><use 
href="#hamburger"></use></svg></div></div><div class="io" style="box-sizing: 
border-box; margin: 0px; flex: 1 0 auto; width: 1rem; display: flex;"><div 
class="input" data-markdown="```sql
   WITH x AS(SELECT TIMESTAMPTZ '2024-03-10 03:15:00-04:00' as t, TIMESTAMPTZ 
'2024-03-09 00:30:00-05:00' AS o)
    select date_bin(interval '1 hour', t, o) as duration_grid from x;
   ```
   " style="box-sizing: border-box; margin: 0px 0px 0px 0.5rem; flex: 0 0 
42rem; width: 1rem;"><div class="cm-editor ͼ1 ͼ2 ͼ4" style="box-sizing: 
border-box; margin: 0px; flex-direction: column; position: relative !important; 
display: flex !important; border: 1px solid silver;"><div class="cm-announced" 
aria-live="polite" style="box-sizing: border-box; margin: 0px; position: fixed; 
top: -10000px;"></div><div tabindex="-1" class="cm-scroller" style="box-sizing: 
border-box; margin: 0px; font-family: monospace; line-height: 1.4; height: 
53.0729px; overflow-x: auto; position: relative; z-index: 0; overflow-anchor: 
none; display: flex !important; align-items: flex-start !important;"><div 
class="cm-gutters cm-gutters-before" aria-hidden="true" style="box-sizing: 
border-box; margin: 0px; flex-shrink: 0; display: flex; height: 36.4062px; 
z-index: 200; inset-inline-start: 0px; background-color: rgb(245, 245, 245); 
color: rgb(108, 108, 108); border-width: 0px 1px 0px 0px; border-style: soli
 d; border-color: rgb(221, 221, 221); border-image: none; min-height: 
36.4062px; position: sticky;"><div class="cm-gutter cm-lineNumbers" 
style="box-sizing: border-box; margin: 0px; flex-direction: column; 
flex-shrink: 0; min-height: 100%; overflow: hidden; display: flex 
!important;"><div class="cm-gutterElement" style="box-sizing: border-box; 
margin: 0px; padding: 0px 3px 0px 5px; min-width: 20px; text-align: right; 
white-space: nowrap; height: 0px; visibility: hidden; pointer-events: 
none;"></div><div class="cm-gutterElement" style="box-sizing: border-box; 
margin: 0px; padding: 0px 3px 0px 5px; min-width: 20px; text-align: right; 
white-space: nowrap; height: 18.2031px;">1</div><div class="cm-gutterElement 
cm-activeLineGutter" style="box-sizing: border-box; margin: 0px; 
background-color: initial; padding: 0px 3px 0px 5px; min-width: 20px; 
text-align: right; white-space: nowrap; height: 18.2031px;">2</div></div><div 
class="cm-gutter cm-foldGutter" style="box-sizing: border-box; margi
 n: 0px; flex-direction: column; flex-shrink: 0; min-height: 100%; overflow: 
hidden; display: flex !important;"><div class="cm-gutterElement" 
style="box-sizing: border-box; margin: 0px; height: 0px; visibility: hidden; 
pointer-events: none;"><span title="Unfold line" style="box-sizing: border-box; 
margin: 0px; padding: 0px 1px; cursor: pointer;"></span></div><div 
class="cm-gutterElement" style="box-sizing: border-box; margin: 0px; height: 
18.2031px;"><span title="Fold line" style="box-sizing: border-box; margin: 0px; 
padding: 0px 1px; cursor: pointer;">⌄</span></div><div class="cm-gutterElement 
cm-activeLineGutter" style="box-sizing: border-box; margin: 0px; 
background-color: initial; height: 18.2031px;"></div></div></div><div 
spellcheck="false" autocorrect="off" autocapitalize="off" 
writingsuggestions="false" translate="no" contenteditable="true" 
class="cm-content" role="textbox" aria-multiline="true" data-language="sql" 
style="box-sizing: border-box; margin: 0px; flex: 2 0 853px;
  display: block; white-space: pre; overflow-wrap: normal; min-height: 100%; 
padding: 0px; outline: none; caret-color: transparent !important; 
-webkit-user-modify: read-write-plaintext-only; tab-size: 4;"><div 
class="cm-line" style="box-sizing: border-box; margin: 0px; display: block; 
padding: 0px 2px 0px 6px; caret-color: transparent !important;"><span 
class="ͼb" style="box-sizing: border-box; margin: 0px; color: rgb(119, 0, 
136);">WITH</span> x <span class="ͼb" style="box-sizing: border-box; margin: 
0px; color: rgb(119, 0, 136);">AS</span>(<span class="ͼb" style="box-sizing: 
border-box; margin: 0px; color: rgb(119, 0, 136);">SELECT</span> <span 
class="ͼi" style="box-sizing: border-box; margin: 0px; color: rgb(0, 136, 
85);">TIMESTAMPTZ</span> <span class="ͼe" style="box-sizing: border-box; 
margin: 0px; color: rgb(170, 17, 17);">'2024-03-10 03:15:00-04:00'</span> <span 
class="ͼb" style="box-sizing: border-box; margin: 0px; color: rgb(119, 0, 
136);">as</span> t, <span class="ͼi
 " style="box-sizing: border-box; margin: 0px; color: rgb(0, 136, 
85);">TIMESTAMPTZ</span> <span class="ͼe" style="box-sizing: border-box; 
margin: 0px; color: rgb(170, 17, 17);">'2024-03-09 00:30:00-05:00'</span> <span 
class="ͼb" style="box-sizing: border-box; margin: 0px; color: rgb(119, 0, 
136);">AS</span> o)</div><div class="cm-line cm-activeLine" style="box-sizing: 
border-box; margin: 0px; display: block; padding: 0px 2px 0px 6px; 
background-color: initial; caret-color: transparent !important;"> <span 
class="ͼb" style="box-sizing: border-box; margin: 0px; color: rgb(119, 0, 
136);">select</span> date_bin(<span class="ͼi" style="box-sizing: border-box; 
margin: 0px; color: rgb(0, 136, 85);">interval</span> <span class="ͼe" 
style="box-sizing: border-box; margin: 0px; color: rgb(170, 17, 17);">'1 
hour'</span>, t, o) <span class="ͼb" style="box-sizing: border-box; margin: 
0px; color: rgb(119, 0, 136);">as</span> duration_grid <span class="ͼb" 
style="box-sizing: border-box; margi
 n: 0px; color: rgb(119, 0, 136);">from</span> x;</div></div><div 
class="cm-layer cm-layer-above cm-cursorLayer" aria-hidden="true" 
style="box-sizing: border-box; margin: 0px; user-select: none; position: 
absolute; left: 0px; top: 0px; contain: size style; pointer-events: none; 
z-index: 150; animation-duration: 1200ms; animation-name: 
cm-blink2;"></div></div></div></div><div class="output" data-markdown="| 
duration\_grid |
   |:--------------|
   | 2024-03-10 01:30:00-05 |
   &gt; ``` status
   &gt; SELECT 1
   &gt; ```
   
   " style="box-sizing: border-box; margin: -0.45rem 0px -0.45rem 0.5rem; flex: 
1 0 auto; width: 1rem; border-left: 1px solid silver; padding: 0.5rem; 
min-height: 2.2rem;">
   duration_grid
   --
   2024-03-10 01:30:00-05
   
   <blockquote style="box-sizing: border-box; margin: 0.5rem 0px 0px; display: 
block; overflow-x: auto;"><pre style="box-sizing: border-box; margin: 
0px;"><code class="language-status" style="box-sizing: border-box; margin: 0px; 
display: block; border-left: 0.15rem solid rgb(42, 95, 205); padding-left: 
0.3rem; color: rgb(42, 95, 205);">SELECT 
1</code></pre></blockquote></div></div></div></div>
   ```



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