gemini-code-assist[bot] commented on code in PR #38865:
URL: https://github.com/apache/beam/pull/38865#discussion_r3398545640
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonValueExtractors.java:
##########
@@ -189,7 +189,14 @@ static ValueExtractor<BigDecimal> decimalValueExtractor() {
*/
static ValueExtractor<DateTime> datetimeValueExtractor() {
return ValidatingValueExtractor.<DateTime>builder()
- .setExtractor(jsonNode -> DateTime.parse(jsonNode.textValue()))
+ .setExtractor(
+ jsonNode -> {
+ String text = jsonNode.textValue();
+ if (text.contains(" ")) {
+ text = text.replace(' ', 'T');
+ }
+ return DateTime.parse(text);
Review Comment:

Using `text.replace(' ', 'T')` replaces *all* occurrences of spaces with
`'T'`. If the datetime string contains other spaces (such as trailing spaces,
or spaces within timezone offsets/names like `+00:00` or `UTC`), they will also
be replaced with `'T'`, resulting in an invalid format (e.g.,
`"2018-05-28T20:17:40.123TZ"` or `"2018-05-28T20:17:40.123T"`). This will cause
parsing to fail.
To prevent this, you should only replace the first space (which separates
the date and time parts) using `replaceFirst`.
```suggestion
String text = jsonNode.textValue();
if (text.contains(" ")) {
text = text.replaceFirst(" ", "T");
}
return DateTime.parse(text);
```
--
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]