[
https://issues.apache.org/jira/browse/BEAM-13080?focusedWorklogId=670995&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-670995
]
ASF GitHub Bot logged work on BEAM-13080:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 27/Oct/21 19:56
Start Date: 27/Oct/21 19:56
Worklog Time Spent: 10m
Work Description: InigoSJ commented on a change in pull request #15753:
URL: https://github.com/apache/beam/pull/15753#discussion_r737798869
##########
File path: sdks/python/apache_beam/transforms/util.py
##########
@@ -723,12 +723,33 @@ class Reshuffle(PTransform):
Reshuffle is experimental. No backwards compatibility guarantees.
"""
+ def __init__(self, num_buckets=None):
+ """
+ :param num_buckets: If set, specifies the maximum random keys that would be
+ generated.
+ """
+ self.num_buckets = num_buckets
+
+ valid_buckets = isinstance(num_buckets, int) and num_buckets > 0
+ if not (num_buckets is None or valid_buckets):
+ raise ValueError(
+ 'If `num_buckets` is set, it has to be an '
+ 'integer greater than 0, got %s' % num_buckets)
+
def expand(self, pcoll):
# type: (pvalue.PValue) -> pvalue.PCollection
+ if self.num_buckets:
+ keyed = pcoll | 'AddRandomKeys' >> Map(
+ lambda t: (random.randint(0, self.num_buckets), t)).with_input_types(
Review comment:
That looks way better!
I made the change using `1 << 32`, since [`getrandbits`]
(https://docs.python.org/3/library/random.html#random.getrandbits) returns a
_positive_ integer of that many bits and `1 << 32 - 2**32 = 0`
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 670995)
Time Spent: 2h (was: 1h 50m)
> Specify numBuckets in Python Reshuffle
> --------------------------------------
>
> Key: BEAM-13080
> URL: https://issues.apache.org/jira/browse/BEAM-13080
> Project: Beam
> Issue Type: New Feature
> Components: sdk-py-core
> Reporter: Inigo San Jose Visiers
> Priority: P2
> Time Spent: 2h
> Remaining Estimate: 0h
>
> While Java has `withNumBuckets` to set the amount of generated keys, Python
> doesn't.
> This is particularly need when your input data is not so high and you need to
> take advantage for DoFn methods `start / finish bundle`.
> https://beam.apache.org/releases/javadoc/2.33.0/org/apache/beam/sdk/transforms/Reshuffle.ViaRandomKey.html#withNumBuckets-java.lang.Integer-
--
This message was sent by Atlassian Jira
(v8.3.4#803005)