Viranshul-P opened a new pull request, #41736:
URL: https://github.com/apache/beam/pull/41736
Fixes #41735.
`WriteToAvro` without an explicit `schema` (and Beam YAML `WriteToAvro`)
derives the Avro schema with `beam_type_to_avro_type` and converts each row
with `beam_value_to_avro_value`. Three field kinds broke that:
1. **Map fields** crashed with `AttributeError: element_type`: the code read
`map_type.element_type`, but `MapType` has `value_type`.
2. **Nullable array, map or row fields** crashed on `None`: `nullable` was
only applied to atomic types, so the Avro type had no `null` branch, and the
value converter iterated the `None`. Such fields are now `[<type>, "null"]`,
the same order already used for nullable atomics, and `None` passes through.
3. **Two fields with the same row type** failed with `SchemaParseException:
redefined named type`: the nested record was defined again on every use. The
first use now defines it, and later uses refer to it by name, as Avro requires.
Schemas that worked before come out unchanged
(`test_avro_schema_to_beam_and_back` still passes). This PR only touches the
write path. Reading those files back with `ReadFromAvro(as_rows=True)` still
fails for nullable records and named-type references. That is in
`avro_type_to_beam_type`/`avro_value_to_beam_value`, which #41701 also edits,
so I'll send it separately after that one.
Test:
`avroio_test.py::test_schema_write_map_nullable_and_repeated_row_fields` writes
rows with all three field kinds and reads the file back with `fastavro.reader`.
It fails on master and passes with this change. `io/avroio_test.py` and
`yaml/yaml_io_test.py` pass (54 passed, 26 skipped, Windows 11, Python 3.12;
`test_sink_transform` is deselected because it hangs on Windows on master too).
yapf 0.43.0 and ruff 0.15.7 report nothing.
This change was written with help from Claude Code; the commits carry 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]