This is an automated email from the ASF dual-hosted git repository.

vbalaji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 68e703e3a49 [MINOR] Handle parsing of all zero timestamps with MDT 
suffixes. (#10481)
68e703e3a49 is described below

commit 68e703e3a4987a1d9ec6e20fae0ad7436f77bd3c
Author: Prashant Wason <pwa...@uber.com>
AuthorDate: Tue Jan 16 14:49:57 2024 -0800

    [MINOR] Handle parsing of all zero timestamps with MDT suffixes. (#10481)
---
 .../common/table/timeline/HoodieInstantTimeGenerator.java   |  4 ++++
 .../common/table/timeline/TestHoodieActiveTimeline.java     | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git 
a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstantTimeGenerator.java
 
b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstantTimeGenerator.java
index 2e48e40820d..3fb9a0698b6 100644
--- 
a/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstantTimeGenerator.java
+++ 
b/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstantTimeGenerator.java
@@ -90,6 +90,10 @@ public class HoodieInstantTimeGenerator {
       LocalDateTime dt = LocalDateTime.parse(timestampInMillis, 
MILLIS_INSTANT_TIME_FORMATTER);
       return Date.from(dt.atZone(ZoneId.systemDefault()).toInstant());
     } catch (DateTimeParseException e) {
+      // MDT uses timestamps which add suffixes to the instant time. Hence, we 
are checking for all timestamps that start with all zeros.
+      if (timestamp.startsWith(HoodieTimeline.INIT_INSTANT_TS)) {
+        return new Date(0);
+      }
       throw new ParseException(e.getMessage(), e.getErrorIndex());
     }
   }
diff --git 
a/hudi-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
 
b/hudi-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
index ce0b5dad335..847d7d9e7b9 100755
--- 
a/hudi-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
+++ 
b/hudi-common/src/test/java/org/apache/hudi/common/table/timeline/TestHoodieActiveTimeline.java
@@ -609,6 +609,19 @@ public class TestHoodieActiveTimeline extends 
HoodieCommonTestHarness {
     System.out.println(defaultSecsGranularityDate.getTime());
   }
 
+  @Test
+  public void testAllZeroTimestampParsing() throws ParseException {
+    String allZeroTs = "00000000000000";
+    Date allZeroDate = 
HoodieActiveTimeline.parseDateFromInstantTime(allZeroTs);
+    assertEquals(allZeroDate, new Date(0), "Parsing of all zero timestamp 
should succeed");
+
+    // MDT uses timestamps which add suffixes to the instant time. These 
should also be parsable for all zero case.
+    for (int index = 0; index < 10; ++index) {
+      allZeroDate = HoodieActiveTimeline.parseDateFromInstantTime(allZeroTs + 
"00" + index);
+      assertEquals(allZeroDate, new Date(0), "Parsing of all zero timestamp 
should succeed");
+    }
+  }
+
   @Test
   public void testMetadataCompactionInstantDateParsing() throws ParseException 
{
     // default second granularity instant ID

Reply via email to