Repository navigation
[Python] Fix WriteToParquet with nested Row fields - #41737
DhanushPillay wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR resolves #41101 by adding recursive Arrow-type-aware value converters in PyarrowBatchConverter to transform nested beam.Row (as well as dataclass/NamedTuple) values—including those nested within lists and maps—into pyarrow-compatible dictionaries prior to constructing Arrow arrays. The implementation is clean, avoids conversion overhead for primitive fields by returning None for non-nested converters, and includes thorough unit and pipeline-level regression tests.
🔍 General Feedback
- The pre-computed converter approach in
PyarrowBatchConverter.__init__is well-structured and ensures zero per-element conversion overhead for columns that do not contain nestedStructTypefields. - Minor consideration:
PyarrowArrayBatchConverter.produce_batchcould also benefit from_to_arrow_value_fn(self._arrow_type)ifpa.Arraybatches are ever produced directly frombeam.Rowelements, thoughPyarrowBatchConverter(pa.Table) is the one used byWriteToParquet.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR resolves #41101 by adding recursive Arrow-type-aware value converters in PyarrowBatchConverter to transform nested beam.Row (as well as dataclass and NamedTuple) values—including those inside lists and maps—into pyarrow-compatible dictionaries prior to constructing Arrow arrays. Following the previous review, convert_map now cleanly handles both dict and sequence-of-pairs representations with corresponding unit test coverage.
🔍 General Feedback
- The pre-computed converter functions in
PyarrowBatchConverter.__init__avoid per-element conversion overhead for columns without nested struct types. - The test suite in
arrow_type_compatibility_test.pyandparquetio_test.pythoroughly covers direct nested rows, rows in lists, rows in map dicts, rows in map key-value tuple sequences, andNonehandling.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @tvalentyn for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #41101
WriteToParquetfailed when a schema'dbeam.Rowelement had a field holding anotherbeam.Row.PyarrowBatchConverter.produce_batchpassed the nested row object directly topa.arrayfor a struct field, which pyarrow rejects.This change adds an Arrow-type-aware converter that turns nested
Rowvalues (and rows inside lists and maps) into pyarrow-compatible structs before building the table.Added regression coverage at both the converter and
WriteToParquetpipeline levels.Verification:
arrow_type_compatibility_test.pyandparquetio_test.py: 103 passed, 1 skippedruffandyapf: clean./gradlew formatChanges validateChanges: successful