Skip to content

Commit

Permalink
Allow parsing ISO8601 timestamp in Delta lake transaction log
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Jan 8, 2025
1 parent d7beb3c commit b6856b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import static java.math.RoundingMode.UNNECESSARY;
import static java.time.ZoneOffset.UTC;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
import static java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.YEAR;
Expand Down Expand Up @@ -184,7 +185,14 @@ private static Long readPartitionTimestamp(String timestamp)
@VisibleForTesting
static Long readPartitionTimestampWithZone(String timestamp)
{
ZonedDateTime zonedDateTime = LocalDateTime.parse(timestamp, PARTITION_TIMESTAMP_FORMATTER).atZone(UTC);
ZonedDateTime zonedDateTime;
try {
zonedDateTime = LocalDateTime.parse(timestamp, PARTITION_TIMESTAMP_FORMATTER).atZone(UTC);
}
catch (DateTimeParseException _) {
// TODO: avoid this exception-driven logic
zonedDateTime = ZonedDateTime.parse(timestamp, ISO_ZONED_DATE_TIME);
}
return packDateTimeWithZone(zonedDateTime.toInstant().toEpochMilli(), UTC_KEY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ void testReadPartitionTimestampWithZone()
assertThat(readPartitionTimestampWithZone("1970-01-01 00:00:00.00001")).isEqualTo(0L);
assertThat(readPartitionTimestampWithZone("1970-01-01 00:00:00.000001")).isEqualTo(0L);
}

@Test
void testReadPartitionTimestampWithZoneIso8601()
{
assertThat(readPartitionTimestampWithZone("1970-01-01T00:00:00.000000Z")).isEqualTo(0L);
assertThat(readPartitionTimestampWithZone("1970-01-01T01:00:00.000000+01:00")).isEqualTo(0L);
}
}

0 comments on commit b6856b8

Please sign in to comment.