mananmangal opened a new issue, #41024:
URL: https://github.com/apache/beam/issues/41024

   ### What happened?
   
   When a Beam `STRING` field is written to a `timestamptz` column, IcebergIO 
only accepts an offset after the time. A string ending in a zone ID, such as 
`2024-10-08 13:18:20.053 UTC`, fails with `DateTimeParseException`.
   
   Beam's own `BigQueryIO.readTableRows()` produces this form for BigQuery 
`TIMESTAMP` columns 
([`BigQueryAvroUtils.formatTimestamp`](https://github.com/apache/beam/blob/b4f149124fc94e2c0e6d4daa8e7250bb318cd5bd/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryAvroUtils.java#L227-L229)),
 so rows read from BigQuery can't be written to Iceberg without rewriting their 
timestamps first.
   
   Beam version: 2.77.0 (also reproduced on master at `b4f149124fc`)
   
   Repro:
   
   ```java
   Schema beamSchema = Schema.builder().addStringField("ts").build();
   Row row = Row.withSchema(beamSchema).addValue("2024-10-08 13:18:20.053 
UTC").build();
   org.apache.iceberg.Schema icebergSchema =
       new org.apache.iceberg.Schema(
           Types.NestedField.required(1, "ts", Types.TimestampType.withZone()));
   
   IcebergUtils.beamRowToIcebergRecord(icebergSchema, row);
   ```
   
   ```
   java.time.format.DateTimeParseException: Text '2024-10-08 13:18:20.053 UTC' 
could not be parsed at index 23
   ```
   
   `2024-10-08T13:18:20.053 UTC` and `2024-10-08 09:18:20.053 America/New_York` 
fail the same way. On 2.77.0 the space-separated forms fail earlier, at index 
10 (#40860).
   
   `IcebergUtils.getIcebergTimestampValue` parses with 
[`TIMESTAMPTZ_SPACE_FORMATTER`](https://github.com/apache/beam/blob/b4f149124fc94e2c0e6d4daa8e7250bb318cd5bd/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergUtils.java#L107-L115)
 and 
[`OffsetDateTime.parse`](https://github.com/apache/beam/blob/b4f149124fc94e2c0e6d4daa8e7250bb318cd5bd/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/IcebergUtils.java#L519-L525),
 which only accept an offset.
   
   BigQueryIO already accepts zone IDs when writing a string to a `TIMESTAMP` 
column: 
[`BigQueryUtils.TIMESTAMP_FORMATTER`](https://github.com/apache/beam/blob/b4f149124fc94e2c0e6d4daa8e7250bb318cd5bd/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java#L214-L231).
   
   Proposed fix: for `timestamptz`, accept either an offset or a zone ID after 
the time, optionally preceded by a space, e.g. `Z`, `+03:27`, ` UTC` or ` 
America/New_York`. Strings that parse today keep the same result. Strings 
without a zone, out-of-range dates, malformed separators, and strings with both 
an offset and a zone ID stay rejected. A local time in a daylight saving gap or 
overlap resolves as in `ZonedDateTime.ofLocal`, the same as BigQueryIO.
   
   Workaround: until this is fixed, rewrite the string with an offset before 
writing, e.g. `2024-10-08T13:18:20.053Z`.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [ ] Component: Python SDK
   - [x] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [x] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner
   


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

Reply via email to