TheNeuralBit commented on code in PR #23224:
URL: https://github.com/apache/beam/pull/23224#discussion_r984987952


##########
website/www/site/content/en/documentation/programming-guide.md:
##########
@@ -3749,39 +3749,87 @@ the user ids from a `PCollection` of purchases one 
would write (using the `Selec
 purchases.apply(Select.fieldNames("userId"));
 {{< /highlight >}}
 
+{{< highlight python >}}
+input_pc = ... # {"user_id": ...,"bank": ..., "purchase_amount": ...}
+output_pc = input_pc | beam.Select(user_id=lambda item: str(item["user_id"]))

Review Comment:
   Let's recommend the string argument approach here:
   ```suggestion
   output_pc = input_pc | beam.Select("user_id")
   ```



##########
website/www/site/content/en/documentation/programming-guide.md:
##########
@@ -4061,6 +4203,18 @@ purchases.apply(Group.byFieldNames("userId")
     .aggregateField("costCents", Top.<Long>largestLongsFn(10), 
"topPurchases"));
 {{< /highlight >}}
 
+{{< highlight python >}}
+input_pc = ... # {"user_id": ...,"item_Id": ..., "cost_cents": ...}
+output_pc = input_pc | beam.GroupBy("user_id")
+       .aggregate_field("item_id",count,"num_purchases")
+       .aggregate_field("cost_cents",sum,"total_spendcents")

Review Comment:
   nit: `sum` will work here since it's a built-in that we detect, but you need 
to define `count`. What you want here is the CombineFn used in the [`Count` 
transform](https://beam.apache.org/releases/pydoc/current/apache_beam.transforms.combiners.html#apache_beam.transforms.combiners.Count).
   
   Unfortunately it looks like we don't expose the CombineFn like Java does via 
`Count.combineFn`. Unless I'm missing something.. do you know @robertwb or 
@tvalentyn?



-- 
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