Repository navigation
[Python/YAML] Add File enrichment handler and error_handling (#41356) - #41453
shikhabhadoria wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR is the third in a three-part series (#41451, #41452, #41453) adding File enrichment handler support, on_miss, prefix, and error_handling dead-letter output to Beam YAML's Enrichment transform. The YAML integration and test coverage are well-structured, though there are a few issues in CHANGES.md placement, test helper signature compatibility, and underlying file handler/join error handling included in this branch.
🔍 General Feedback
- Note that this branch is stacked on #41451 and #41452 against
master, so the diff includes commits from all three PRs. - The
CHANGES.mdentries were accidentally inserted into the commented-out<!-- Template -->block at the top of the file rather than under the active# [2.79.0] - Unreleasedsection.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
💬 Inline Findings
-
CHANGES.md(line 31): 🟡 Medium: These release notes were added inside the commented-out<!-- Template -->section (lines 19–77) instead of under the active# [2.79.0] - Unreleased## I/Ossection around line 88. -
sdks/python/apache_beam/yaml/yaml_enrichment_test.py(line 50): 🟡 Medium:FakeEnrichmentTransform.__call__is used to mockenrichment_transform, which now acceptson_missandprefixparameters. Because@maybe_with_exception_handlinginspects the wrapped callable's signature andyaml_providerbinds defaults,FakeEnrichmentTransform.__call__should accepton_miss='null'andprefix=None(or**kwargs) to stay consistent withenrichment_transform's updated signature.
def __call__(self, enrichment_handler, *, handler_config, timeout=30, on_miss='null', prefix=None):
sdks/python/apache_beam/transforms/enrichment_handlers/file.py(line 71): 🟠 High:_load_parquet,_load_csv, and_load_jsoninsertrecords[None] = projectedwhenever a reference row has a null or emptyjoin_key. Returningself.records.get(None)when the input row's lookupkey is Nonecauses null foreign keys in the inputPCollectionto falsely match those null-keyed reference rows instead of being treated as lookup misses. ANonelookup key should always be a miss.
return None
-
sdks/python/apache_beam/transforms/enrichment_handlers/file.py(line 468): 🟠 High:_peek_schema()ignores field nullability on the Arrow schema (arrow_schema.field(c).nullable) and always returns non-Optionaltypes for Parquet columns. Becauseget_output_schema()caches_peek_schema()during pipeline construction, usingEnrichment(handler, on_miss='drop')(or'fail'/'dlq') on a Parquet reference file with nullable columns sets a non-nullableRowTypeConstrainton the outputPCollection, which fails when encodingNonevalues at runtime. -
sdks/python/apache_beam/transforms/enrichment.py(line 176): 🟡 Medium: In_EnrichmentJoinFn.process, theon_miss == 'null'branch invokesself._join_fn(...)outside thetry ... except Exception as exn:block below (lines 179–200). If a customjoin_fnraises an exception when handling a miss withon_miss='null'andwith_exception_handling(...)(or YAMLerror_handling) is enabled, the exception will fail the pipeline instead of being routed toself._dead_letter_tag.
…ing (apache#41356) Register the File enrichment handler in Beam YAML and send on_miss=dlq rows and caller failures to the standard error_handling output.
3130361 to
68c10d8
Compare
|
Rebased this onto current master so the diff is only the Beam YAML wiring. The earlier version also contained the #41451 and #41452 commits, which is why the line count matched the original PR. Merge after those two. The new tests need both APIs, so they fail on master alone; with all three branches together, 30 tests passed. |
|
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). |
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly wires FileEnrichmentHandler, on_miss, prefix, and error_handling into the Beam YAML Enrichment transform as part 3 of #41356. The implementation and test suite are well-structured and cover Parquet, CSV, on_miss modes, and RPC timeout routing to dead-letter outputs.
🔍 General Feedback
- Separating the
Enrichment/FileEnrichmentHandlerimport block from the GCP-specific handlers is a good improvement so local file enrichment only depends on coreEnrichment(RequestResponseIO) rather than GCP client libraries. - Remember to merge #41451 and #41452 first and rebase this branch before merging so CI passes against
master.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
/summarize-failures |
…apache#41356) Drop the unused json import flagged in review. Import FileEnrichmentHandler separately so a missing module does not disable Enrichment, and skip the file-handler tests until apache#41451 and apache#41452 are available.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41453 +/- ##
============================================
- Coverage 57.99% 57.99% -0.01%
Complexity 2831 2831
============================================
Files 1209 1209
Lines 173011 173032 +21
Branches 2320 2320
============================================
+ Hits 100334 100344 +10
- Misses 69968 69979 +11
Partials 2709 2709
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @shikhabhadoria, can you fix the lint issue? Thanks |
…pache#41356) Pass on_miss and prefix only when Enrichment.__init__ accepts them so PythonLint type checking against master Enrichment stays green.
|
@derrickaw Fixed. PythonLint was failing pyrefly because this branch calls
|
|
The Python 3.14 precommit failure is not from this PR.
It asserts |
|
Correction: Again, the prior 3.14 failure was unrelated to this PR: |
|
Hi @shikhabhadoria, can you git pull merge, I believe a recent PR for bigtable went in after your last pull and may resolve the Precommit failure we see currently. Thanks |
…ent-error-handling-41356
Refresh the branch onto latest master per review. Update skip/error messages so on_miss/prefix point at the follow-up to apache#41451, while error_handling continues to use with_exception_handling from that PR.
|
@derrickaw merged latest Also refreshed the dependency notes: YAML |
Addresses #41356. Part 3 of the YAML wiring for Enrichment.
Summary
enrichment_handler: File(FileEnrichmentHandler). The import is separate from the optional GCP handlers.on_missandprefixthroughenrichment_transformwhen that API is available (follow-up to [Python] Add with_exception_handling to RequestResponseIO and Enrichment (#41356) #41451).maybe_with_exception_handling_transform_fn, so YAMLerror_handlingusesEnrichment.with_exception_handlingfrom [Python] Add with_exception_handling to RequestResponseIO and Enrichment (#41356) #41451 for RPC/join failures.on_miss/prefixYAML tests skip until those APIs are present.Test plan
master(per @derrickaw)ruff check/yapfon the YAML filesChecklist
addresses #41356).CHANGES.mdwith noteworthy changes.