riteshghorse commented on code in PR #29775:
URL: https://github.com/apache/beam/pull/29775#discussion_r1434304369
##########
learning/tour-of-beam/learning-content/core-transforms/map/co-group-by-key/description.md:
##########
@@ -284,42 +284,28 @@ static PCollection<String>
applyTransform(PCollection<String> fruits, PCollectio
{{end}}
{{if (eq .Sdk "python")}}
```
-weight := beam.ParDo(s, func(_ []byte, emit func(string, int)){
- emit("brazil", 1000)
- emit("australia", 150)
- emit("canada", 340)
-}, beam.Impulse(s))
-
-fruits := beam.ParDo(s, func(_ []byte, emit func(string, string)){
- emit("australia", "cherry")
- emit("brazil", "apple")
- emit("canada", "banan")
-}, beam.Impulse(s))
+fruits = p | 'Fruits' >> beam.Create([('australia', 'cherry'), ('brazil',
'apple'), ('canada', 'banana')])
+weights = p | 'Countries' >> beam.Create([('australia', 1000), ('brazil',
150), ('canada', 340)])
```
-Change `Alphabet` to `ProductWeight`:
+Change `alphabet` to `product_weight`:
```
-type WordsAlphabet struct {
- Country string
- Fruit string
- ProductWeight int
-}
+class ProductWeight:
+ def __init__(self, product_weight, fruit, country):
+ self.product_weight = product_weight
+ self.fruit = fruit
+ self.country = country
```
The union takes place through the keys:
```
-func applyTransform(s beam.Scope, fruits beam.PCollection, countries
beam.PCollection) beam.PCollection {
- grouped := beam.CoGroupByKey(s, fruits, countries)
- return beam.ParDo(s, func(key string, weightIter func(*int) bool,
fruitIter func(*string) bool, emit func(string)) {
-
- wa := &WordsAlphabet{
- Country: key,
- }
- weightIter(&wa.ProductWeight)
- fruitIter(&wa.Fruit)
- emit(wa.String())
-
- }, grouped)
-}
+def apply_transforms(fruits, weights):
+ def cogbk_result_to_product_weight(cgbk_result):
+ (country, values) = cgbk_result
+ return WordsAlphabet(values['weights'][0], values['fruits'][0],
country)
Review Comment:
```suggestion
return ProductWeight(values['weights'][0], values['fruits'][0],
country)
```
--
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]