Repository navigation
[YAML] Fix Explode null collection handling, field extraction, and output schema inference - #41717
vishalmore90 wants to merge 1 commit into
Conversation
…tput schema inference
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly resolves #41715 by updating Beam YAML's Explode transform in both Python and Java to handle None/null iterable fields gracefully, extract fields safely in Python when names shadow methods, and infer accurate nullable/concrete element types in output schemas. The unit and YAML integration test coverage is thorough and well-structured.
🔍 General Feedback
- Both Python (
_Explode) and Java (JavaExplodeTransformProvider) now have consistent semantics forNone/nullcollections in cross-product and zip modes, as well as matching nullable output schema inference when zipping multiple fields. - Switching Java's cross-product row construction from
ImmutableList.copyOf(current)toRow.withSchema(outputSchema).addValues(Arrays.asList(current)).build()properly avoids Guava'sNullPointerExceptionwhen unexploded fields or array elements arenull.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @derrickaw for label yaml. 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). |
Summary
Fixes #41715.
Updates Beam YAML
Explodein both Python (_Explode) and Java (JavaExplodeTransformProvider) to handleNone/nullcollections and preserve accurate output schemas:Python (
sdks/python/apache_beam/yaml/yaml_mapping.py):Nonecollections inexplode_cross_product(emitting 0 rows, matching[]) and substitute()forNoneinputs inexplode_zipbeforeitertools.zip_longest.getattr(row, name)in_Explode.expandwith_row_to_dict(row.__dict__forbeam.Row,row._asdict()when callable,getattrfallback)._Explode.infer_output_typeto convert native schema types viaconvert_to_beam_type, unwrapOptional[...], infer element types viatrivial_inference.element_type, and mark multi-field zipped output fieldsOptional[...]soRowCoderacceptsNonepadding on unequal/null inputs.Java (
sdks/java/core/.../JavaExplodeTransformProvider.java):nulliterables in both cross-product and zip execution paths.ImmutableList.copyOf(current)withRow.withSchema(outputSchema).addValues(Arrays.asList(current)).build()so nullable non-exploded fields or null elements do not throwNullPointerException.!crossProduct && fields.size() > 1), matching thenullpadding behavior of zip mode.Tests & Changelog:
sdks/python/apache_beam/yaml/yaml_mapping_test.py.sdks/python/apache_beam/yaml/tests/explode.yaml.JavaExplodeTransformProviderTest.java.CHANGES.md.Verification
python -m unittest apache_beam.yaml.yaml_mapping_test(34 tests passed).sdks/python/apache_beam/yaml/tests/explode.yamlthroughYamlTransformonDirectRunner(all passed).validateChanges, and xlang integration tests deferred to GitHub Actions PreCommit checks (local environment has JDK 25 only).