Viranshul-P opened a new issue, #41735:
URL: https://github.com/apache/beam/issues/41735
### What happened?
`WriteToAvro` without an explicit `schema` builds the Avro schema from the
PCollection's Beam schema (`beam_schema_to_avro_schema`). Beam YAML
`WriteToAvro` goes through the same functions. On master (`1c20e381bc8`) three
kinds of fields break it:
```python
import typing
import apache_beam as beam
from apache_beam.io.avroio import WriteToAvro
class Point(typing.NamedTuple):
x: int
y: int
class Row(typing.NamedTuple):
counts: typing.Mapping[str, int] # 1
tags: typing.Optional[typing.List[str]] # 2
start: Point # 3
end: Point # 3
with beam.Pipeline() as p:
_ = (p
| beam.Create([Row({'a': 1}, None, Point(1, 2), Point(3,
4))]).with_output_types(Row)
| WriteToAvro('/tmp/out', num_shards=1))
```
1. Any map field: `AttributeError: element_type`. `beam_type_to_avro_type`
reads `map_type.element_type`, but `MapType` has `value_type`.
2. A nullable array, map or row field holding `None`: `TypeError: 'NoneType'
object is not iterable` (or `AttributeError` for a row). `nullable` is only
handled for atomic types, so the Avro type is not a union with `null`, and the
value converter iterates the `None`.
3. Two fields with the same row type: `SchemaParseException: redefined named
type: <schema id>`. The nested record is defined again on every use; Avro
allows a named type to be defined once and referenced by name after that.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Python SDK
- [x] Component: IO connector
- [x] Component: Beam YAML
---
Found and written up with Claude Code (Opus 5.5); posted by @Viranshul-P.
--
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]