Abacn opened a new issue, #26942:
URL: https://github.com/apache/beam/issues/26942
### What happened?
Found when writing rows containing `apache_beam.utils.timestamp.Timestamp`
(obtained from xlang PTransform, e.g. ReadFromJdbc)
The following pipeline writes correct timestamp to BigQuery:
```python
with Pipeline(options=options) as p:
input = p | beam.Create([1,2,3]) | beam.Map(lambda x:{"f_time":
Timestamp.now().to_utc_datetime()})
_ = input | WriteToBigQuery(
table='google.com:clouddfe:yathu_test.testavroload',
schema={
'fields': [{
'name': 'f_time', 'type': 'TIMESTAMP', 'mode': 'REQUIRED'
}]})
```
I get rows
Row | f_time
-- | --
1 | 2023-05-30 22:07:37.947323 UTC
2 | 2023-05-30 22:07:39.553978 UTCÂ
3 | 2023-05-30 22:07:39.554365 UTC
However, if set `temp_file_format=bigquery_tools.FileFormat.AVRO`, it is
then found the timestamps written to BigQuery has +4h offset:
Row | f_time
-- | --
4 | 2023-05-31 02:26:05.533746 UTC
5 | 2023-05-31 02:26:07.054265 UTC
6 | 2023-05-31 02:26:07.054786 UTC
To get the correct time zone, I need to set
`Timestamp.now().to_utc_datetime().replace(tzinfo=datetime.timezone.utc)`
This is due to that fastavro treating datetime.datetime object without a
time zone as locale time zone, while for json write we have the logic to treat
time zone correctly:
https://github.com/apache/beam/blob/b9730952a7abf60437ee85ba2df6dd30556d6560/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L149
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [ ] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Samza Runner
- [ ] Component: Twister2 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]