Skip to content

Commit

Permalink
Update groupbykey.py (#32359)
Browse files Browse the repository at this point in the history
The original example was not actually counting the produce but grouping the produce per season. Maybe it's better to rename the variables to reflect this, in order to not confuse the reader.
  • Loading branch information
cgrotz authored Oct 3, 2024
1 parent eb84ff6 commit 6561abf
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def groupbykey(test=None):
import apache_beam as beam

with beam.Pipeline() as pipeline:
produce_counts = (
produce_per_season = (
pipeline
| 'Create produce counts' >> beam.Create([
| 'Create produce list' >> beam.Create([
('spring', '🍓'),
('spring', '🥕'),
('spring', '🍆'),
Expand All @@ -54,12 +54,12 @@ def groupbykey(test=None):
('fall', '🍅'),
('winter', '🍆'),
])
| 'Group counts per produce' >> beam.GroupByKey()
| 'Group produce per season' >> beam.GroupByKey()
| beam.MapTuple(lambda k, vs: (k, sorted(vs))) # sort and format
| beam.Map(print))
# [END groupbykey]
if test:
test(produce_counts)
test(produce_per_season)


if __name__ == '__main__':
Expand Down

0 comments on commit 6561abf

Please sign in to comment.