Add Sample.Any to the Python SDK to match Java's Sample.any#39442
Open
SreeramaYeshwanthGowd wants to merge 1 commit into
Open
Add Sample.Any to the Python SDK to match Java's Sample.any#39442SreeramaYeshwanthGowd wants to merge 1 commit into
SreeramaYeshwanthGowd wants to merge 1 commit into
Conversation
Python only had Sample.FixedSizeGlobally, which runs a uniform reservoir sample and returns a single list. Add Sample.Any, the equivalent of Java's Sample.any, which returns up to n arbitrary elements as a PCollection without the random sampling cost. If the input has fewer than n elements, all are returned. Includes unit tests on the DirectRunner and a CHANGES.md entry. Fixes apache#18552
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
|
Assigning reviewers: R: @claudevdm for label python. 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Java has
Sample.any(n), which returns up to n arbitrary elements from a PCollection without the cost of a uniform random sample. The Python SDK has no equivalent. Its only global option isSample.FixedSizeGlobally(n), which runs a uniform reservoir sample and returns a singlelist[T]. This gap was reported in #18552.Solution
Add
Sample.Any, the Python equivalent of Java'sSample.any. It keeps up to n arbitrary elements using a smallCombineFnand returns them as a PCollection of individual elements. It makes no uniformity guarantee and is cheaper thanFixedSizeGloballybecause it skips the per element random sampling. If the input has fewer than n elements, all of them are returned. This mirrors Java's semantics and its element returning result type.Testing
Added unit tests in
combiners_test.pythat run on the DirectRunner and cover the normal case, an input smaller than n, a windowed input, an empty input, and n equal to zero. Also extended the existing display data test to cover the new transform.Fixes #18552
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.