Skip to content

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

Open
vishalmore90 wants to merge 1 commit into
apache:masterfrom
vishalmore90:fix-issue-41715
Open

vishalmore90 wants to merge 1 commit 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).

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

1 participant