simhadri-g commented on code in PR #5241:
URL: https://github.com/apache/hive/pull/5241#discussion_r1595464852


##########
common/src/java/org/apache/hadoop/hive/common/type/TimestampTZUtil.java:
##########
@@ -213,4 +205,26 @@ public static Timestamp convertTimestampToZone(Timestamp 
ts, ZoneId fromZone, Zo
   public static double convertTimestampTZToDouble(TimestampTZ timestampTZ) {
     return timestampTZ.getEpochSecond() + timestampTZ.getNanos() / 
DateUtils.NANOS_PER_SEC;
   }
+
+  public static Timestamp legacyLeapYearConversions(Timestamp ts, ZoneId 
fromZone, ZoneId toZone) {
+    DateTimeFormatter dtf = FORMATTER;
+    Timestamp result = Timestamp.valueOf(
+        
dtf.format(dtf.withResolverStyle(ResolverStyle.LENIENT).parse(formatDate(ts, 
fromZone, toZone))));

Review Comment:
   We need to use the legacyDateFormatter because of HIVE-24074: Incorrect 
handling of timestamp in Parquet/Avro when written in certain time zones in 
versions before Hive 3.x . Only with this can we get the correct timezone 
conversion for these dates.
   
   So formatDate(ts, fromZone, toZone) uses legacyDateFormatter  and returns 
`0200-02-29 00:00:00`. If we don't use the legacyDateFormatter we get 
`0200-02-28 22:55:25`which is incorrect. 
   
   Once we have `0200-02-29 00:00:00` we need to parse it with 
DateTimeFormatter with ResolverStyle.LENIENT , this converts 0200-02-29 
00:00:00 to the correct value `0200-03-01 00:00:00.0 ` .
   We need to format this again to return the timestamp.



##########
common/src/java/org/apache/hadoop/hive/common/type/TimestampTZUtil.java:
##########
@@ -213,4 +205,26 @@ public static Timestamp convertTimestampToZone(Timestamp 
ts, ZoneId fromZone, Zo
   public static double convertTimestampTZToDouble(TimestampTZ timestampTZ) {
     return timestampTZ.getEpochSecond() + timestampTZ.getNanos() / 
DateUtils.NANOS_PER_SEC;
   }
+
+  public static Timestamp legacyLeapYearConversions(Timestamp ts, ZoneId 
fromZone, ZoneId toZone) {
+    DateTimeFormatter dtf = FORMATTER;
+    Timestamp result = Timestamp.valueOf(
+        
dtf.format(dtf.withResolverStyle(ResolverStyle.LENIENT).parse(formatDate(ts, 
fromZone, toZone))));

Review Comment:
   We need to use the legacyDateFormatter because of HIVE-24074: Incorrect 
handling of timestamp in Parquet/Avro when written in certain time zones in 
versions before Hive 3.x . Only with this can we get the correct timezone 
conversion for these dates.
   
   So formatDate(ts, fromZone, toZone) uses legacyDateFormatter  and returns 
`0200-02-29 00:00:00`. If we don't use the legacyDateFormatter we get 
`0200-02-28 22:55:25`which is incorrect. 
   
   Once we have `0200-02-29 00:00:00` we need to parse it with 
DateTimeFormatter with ResolverStyle.LENIENT , this converts 0200-02-29 
00:00:00 to the correct value `0200-03-01 00:00:00.0 ` .
   
   
   Lastly, We need to format this again to return the timestamp.



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