Skip to content

[Python] Fix WriteToParquet with nested Row fields - #41737

Open
DhanushPillay wants to merge 6 commits into
apache:masterfrom
DhanushPillay:fix-parquet-nested-row-write-41101
Open

DhanushPillay wants to merge 6 commits into
apache:masterfrom
DhanushPillay:fix-parquet-nested-row-write-41101

Conversation

@DhanushPillay

Copy link
Copy Markdown

Fixes #41101

WriteToParquet failed when a schema'd beam.Row element had a field holding another beam.Row. PyarrowBatchConverter.produce_batch passed the nested row object directly to pa.array for a struct field, which pyarrow rejects.

This change adds an Arrow-type-aware converter that turns nested Row values (and rows inside lists and maps) into pyarrow-compatible structs before building the table.

Added regression coverage at both the converter and WriteToParquet pipeline levels.

Verification:

  • arrow_type_compatibility_test.py and parquetio_test.py: 103 passed, 1 skipped
  • Original issue repro writes and reads back nested rows correctly
  • ruff and yapf: clean
  • ./gradlew formatChanges validateChanges: successful

@github-actions github-actions Bot added python io core size/m M: 50-249 lines changed labels Nov 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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 nested StructType fields.
  • Minor consideration: PyarrowArrayBatchConverter.produce_batch could also benefit from _to_arrow_value_fn(self._arrow_type) if pa.Array batches are ever produced directly from beam.Row elements, though PyarrowBatchConverter (pa.Table) is the one used by WriteToParquet.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@DhanushPillay

Copy link
Copy Markdown
Author

/gemini review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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.py and parquetio_test.py thoroughly covers direct nested rows, rows in lists, rows in map dicts, rows in map key-value tuple sequences, and None handling.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

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 assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Python] WriteToParquet fails on schema'd PCollections whose nested struct fields hold beam.Row values

1 participant