Skip to content

[YAML] Fix Explode null collection handling, field extraction, and output schema inference - #41717

Open
vishalmore90 wants to merge 3 commits into
apache:masterfrom
vishalmore90:fix-issue-41715
Open

vishalmore90 wants to merge 3 commits into
apache:masterfrom
vishalmore90:fix-issue-41715

Conversation

@vishalmore90

Copy link
Copy Markdown
Contributor

Summary

Fixes #41715.

Updates Beam YAML Explode in both Python (_Explode) and Java (JavaExplodeTransformProvider) to handle None/null collections and preserve accurate output schemas:

  1. Python (sdks/python/apache_beam/yaml/yaml_mapping.py):

    • Explicitly skip None collections in explode_cross_product (emitting 0 rows, matching []) and substitute () for None inputs in explode_zip before itertools.zip_longest.
    • Replace getattr(row, name) in _Explode.expand with _row_to_dict (row.__dict__ for beam.Row, row._asdict() when callable, getattr fallback).
    • Update _Explode.infer_output_type to convert native schema types via convert_to_beam_type, unwrap Optional[...], infer element types via trivial_inference.element_type, and mark multi-field zipped output fields Optional[...] so RowCoder accepts None padding on unequal/null inputs.
  2. Java (sdks/java/core/.../JavaExplodeTransformProvider.java):

    • Guard against null iterables in both cross-product and zip execution paths.
    • Replace ImmutableList.copyOf(current) with Row.withSchema(outputSchema).addValues(Arrays.asList(current)).build() so nullable non-exploded fields or null elements do not throw NullPointerException.
    • Mark exploded output fields nullable when zipping multiple fields (!crossProduct && fields.size() > 1), matching the null padding behavior of zip mode.
  3. Tests & Changelog:

    • Added Python unit tests in sdks/python/apache_beam/yaml/yaml_mapping_test.py.
    • Added YAML test pipelines in sdks/python/apache_beam/yaml/tests/explode.yaml.
    • Updated/added Java unit tests in JavaExplodeTransformProviderTest.java.
    • Updated CHANGES.md.

Verification

  • Ran python -m unittest apache_beam.yaml.yaml_mapping_test (34 tests passed).
  • Ran all 5 pipelines in sdks/python/apache_beam/yaml/tests/explode.yaml through YamlTransform on DirectRunner (all passed).
  • Java unit tests, Spotless, Python formatter/lint, validateChanges, and xlang integration tests deferred to GitHub Actions PreCommit checks (local environment has JDK 25 only).

@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 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 for None/null collections 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) to Row.withSchema(outputSchema).addValues(Arrays.asList(current)).build() properly avoids Guava's NullPointerException when unexploded fields or array elements are null.

💡 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: @derrickaw for label yaml.
Backup reviewer: chamikaramj (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).

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.48%. Comparing base (e80c6a4) to head (5681058).
⚠️ Report is 86 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/yaml/yaml_mapping.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41717   +/-   ##
=========================================
  Coverage     59.48%   59.48%           
  Complexity     5153     5153           
=========================================
  Files          1470     1470           
  Lines        187848   187865   +17     
  Branches       3828     3828           
=========================================
+ Hits         111735   111750   +15     
- Misses        72709    72711    +2     
  Partials       3404     3404           
Flag Coverage Δ
python 80.72% <95.45%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@derrickaw

Copy link
Copy Markdown
Collaborator

Hi @vishalmore90, can you address the changes.md merge conflict and the python formatting check failure? Thanks

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]: Beam YAML Explode transform crashes on None/null collections and fails on non-standard field names

2 participants