mananmangal commented on code in PR #41027:
URL: https://github.com/apache/beam/pull/41027#discussion_r4486257554
##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergUtils.java:
##########
@@ -94,25 +95,49 @@ private IcebergUtils() {}
.put(EnumerationType.IDENTIFIER, Types.StringType.get())
.build();
- private static final DateTimeFormatter TIMESTAMP_SPACE_FORMATTER =
+ /**
+ * Parses Iceberg {@code timestamp} strings: an ISO-8601 date and time,
optionally separated by a
+ * space, a {@code 'T'}, or both, e.g. {@code 2024-10-08T13:18:20.053} or
{@code 2024-10-08
+ * 13:18:20.053}.
+ */
+ private static final DateTimeFormatter TIMESTAMP_FORMATTER =
new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(ISO_LOCAL_DATE)
+ .optionalStart()
.appendLiteral(' ')
+ .optionalEnd()
+ .optionalStart()
+ .appendLiteral('T')
+ .optionalEnd()
.append(ISO_LOCAL_TIME)
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT)
.withChronology(IsoChronology.INSTANCE);
- private static final DateTimeFormatter TIMESTAMPTZ_SPACE_FORMATTER =
+ /**
+ * Parses Iceberg {@code timestamptz} strings: {@link #TIMESTAMP_FORMATTER},
then an optional
+ * offset, then an optional space and zone ID, e.g. {@code
2024-10-08T13:18:20.053Z}, {@code
+ * 2024-10-08 13:18:20.053+03:27} or {@code 2024-10-08 13:18:20.053 UTC}. If
both are present, the
+ * offset takes precedence. Without either, UTC is assumed.
+ */
+ private static final DateTimeFormatter TIMESTAMPTZ_FORMATTER =
new DateTimeFormatterBuilder()
- .append(TIMESTAMP_SPACE_FORMATTER)
+ .append(TIMESTAMP_FORMATTER)
+ .optionalStart()
Review Comment:
Thanks. A space before `Z` is accepted: `appendZoneRegionId()` parses `Z` as
well as offsets such as `+03:27`, so `2024-10-08 09:51:20.053 Z` resolves to
`2024-10-08T09:51:20.053Z`. An optional space before `appendOffsetId()` would
only add a second way to parse the same text, so I've left it as is. Added
`2024-10-08 09:51:20.053 Z` to the test cases in 8f4b59a0249.
--
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]