Viranshul-P opened a new pull request, #41701:
URL: https://github.com/apache/beam/pull/41701
Fixes #41700.
`avro_type_to_beam_type` ignored `logicalType` and mapped each field to its
primitive (`INT64`, `INT32`, `BYTES`, `STRING`). fastavro decodes logical types
to Python objects (`datetime`, `date`, `Decimal`, `UUID`), so
`ReadFromAvro(as_rows=True)` failed in the `RowCoder` for any such field, for
example the `TIMESTAMP` columns of a BigQuery Avro export. Beam YAML's
`ReadFromAvro` uses `as_rows: True` by default, so YAML pipelines hit this too.
This was first reported in #31656 (closed by the stale bot).
This PR maps the logical types to the Beam types the Java SDK's `AvroUtils`
uses, through the existing Python logical types:
| Avro | Beam field | Row value |
|---|---|---|
| `timestamp-millis`, `timestamp-micros` | `Timestamp` (micros_instant) |
`Timestamp` |
| `date` | `datetime.date` (date) | `datetime.date` |
| `decimal` | `decimal.Decimal` (decimal) | `Decimal` |
| `uuid` | `STRING` | `str(uuid)` |
`int`/`long` logical types with no Python Beam type (`time-millis`,
`time-micros`, `local-timestamp-*`) map to `Any`, as non-nullable unions
already do in this file, so their values pass through unchanged. Fields without
a logical type are not touched. The write side (`beam_type_to_avro_type`) is
unchanged; it doesn't handle logical types today either.
Test: `avroio_test.py::test_read_as_rows_with_logical_types` writes a file
with all six logical types (one nullable) and reads it with `as_rows=True`
through a `Reshuffle`, so the rows go through the `RowCoder`. It fails on
master with `TypeError: an integer is required` and passes with this change.
The rest of `avroio_test.py` and `yaml/yaml_io_test.py` pass (Windows 11,
Python 3.12; `test_sink_transform` hangs on Windows on master too, so I
deselected it). yapf 0.43.0 and ruff 0.15.7 report nothing.
This change was written with help from Claude Code; the commit carries a
`Generated-by` trailer.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]