gemini-code-assist[bot] commented on code in PR #38046:
URL: https://github.com/apache/beam/pull/38046#discussion_r3086189985
##########
sdks/python/apache_beam/yaml/yaml_provider.py:
##########
@@ -1207,6 +1207,22 @@ def log_and_return(x):
return pcoll | "LogForTesting" >> beam.Map(log_and_return)
+ class Reshuffle(beam.PTransform):
+ """Reshuffles the elements of a PCollection.
+
+ Redistributes the elements of a PCollection to prevent fusion or balance
+ load.
+
+ Args:
+ num_buckets: (optional) Specifies the maximum random keys that would be
+ generated. If not set, a default value is used.
+ """
+ def __init__(self, num_buckets: Optional[int] = None):
+ self.num_buckets = num_buckets
+
+ def expand(self, pcoll):
+ return pcoll | beam.Reshuffle(num_buckets=self.num_buckets)
Review Comment:

The `beam.Reshuffle` transform in the Python SDK does not accept a
`num_buckets` argument in its constructor. Passing this argument will result in
a `TypeError` at runtime. Additionally, `beam.Reshuffle` in the Python SDK is
primarily designed for `KV` pairs. Since Beam YAML typically operates on Rows
(dictionaries), applying `beam.Reshuffle` directly may fail if the input is not
a `KV`. You should remove the unsupported `num_buckets` parameter and ensure
the transform handles non-KV inputs if necessary for YAML compatibility.
```python
class Reshuffle(beam.PTransform):
"""Reshuffles the elements of a PCollection.
Redistributes the elements of a PCollection to prevent fusion or balance
load.
"""
def expand(self, pcoll):
return pcoll | beam.Reshuffle()
```
--
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]