Repository navigation
[Python] Respect without_defaults in Top.Of with the global window - #41570
Thanatos9404 wants to merge 2 commits into
Conversation
With default windowing, Top.Of took a per-bundle path that always added an empty accumulator, and _TopPerBundle emitted one for bundles without elements, so has_defaults=False still produced [] for an empty input. Add the empty accumulator only when has_defaults is set, and emit nothing for a bundle without elements. Fixes apache#41568
There was a problem hiding this comment.
📋 Review Summary
This PR properly ensures Top.Of(n).without_defaults() as well as Top.Largest and Top.Smallest with has_defaults=False respect the has_defaults flag when operating on a PCollection with default global windowing. The implementation cleanly avoids injecting the default empty accumulator and suppresses emitting empty heaps from _TopPerBundle.finish_bundle when a bundle processed no elements.
🔍 General Feedback
- The changes to
Top.Of.expandand_TopPerBundleare minimal, accurate, and preserve backward-compatible graph structure whenhas_defaults=True. - Unit tests in
combiners_test.pythoroughly cover empty and non-empty inputs acrossTop.Of,Top.Largest, andTop.Smallest.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @tvalentyn for label python. 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). |
# Conflicts: # CHANGES.md
Fixes #41568
With default windowing,
Top.Oftakes a per-bundle path. That path always flattened in an empty accumulator so the output would never be empty, and_TopPerBundle.finish_bundlealso emitted one for a bundle without elements. SoTop.Of(n).without_defaults(),Top.Largest(n, has_defaults=False)andTop.Smallest(n, has_defaults=False)still produced[]for an empty input. With other windowing the flag already worked, because that path usesCombineGlobally(...).without_defaults().Now:
has_defaultsis set, so the graph for the default case is unchanged;_TopPerBundleemits nothing for a bundle that had no elements.Tests in
combiners_test.py:test_empty_global_top_without_defaultschecksTop.Of,Top.LargestandTop.Smalleston an empty input, and fails without the change.test_global_top_without_defaultschecks that a non-empty input still gives its result.test_empty_global_top(with defaults) still gives[[]], and the rest ofcombiners_test.pypasses. yapf is clean. I also added aCHANGES.mdentry under Bugfixes for 2.79.0.