SreeramaYeshwanthGowd opened a new pull request, #39442:
URL: https://github.com/apache/beam/pull/39442

   ### 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 is `Sample.FixedSizeGlobally(n)`, which 
runs
   a uniform reservoir sample and returns a single `list[T]`. This gap was 
reported
   in #18552.
   
   ### Solution
   
   Add `Sample.Any`, the Python equivalent of Java's `Sample.any`. It keeps up 
to n
   arbitrary elements using a small `CombineFn` and returns them as a 
PCollection
   of individual elements. It makes no uniformity guarantee and is cheaper than
   `FixedSizeGlobally` because 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.py` that 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:
   
    - [x] Mention the appropriate issue in your description (for example: 
`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, comment `fixes #<ISSUE NUMBER>` instead.
    - [x] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual 
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more 
tips on [how to make review process 
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to