Skip to main content

7. Word Frequency AggregatorEasy

Aggregations & Grouping⏱️ ~12 mins

7. Word Frequency Aggregator

Enterprise Architecture Context

In production stream-processing architectures (Google Cloud Dataflow / Flink), pipeline stages must handle parallel transformations without data loss, managing schema mutations and aggregations across distributed worker workers.

Problem Statement

### Business Context Real-time search trend monitoring calculates the volume of incoming search query tokens across distributed workers. ### Problem Statement Write a function `count_words(input_pcoll)` that takes a `PCollection` of word strings and counts the total frequency of each word, outputting `(word, count)` tuples using `beam.CombinePerKey(sum)`.

Key Learning Objectives

  • Understand distributed Apache Beam execution DAG stages and pipeline lifecycle.
  • Apply idiomatic functional Python transforms using the pipe operator |.
  • Ensure data consistency and idempotency across distributed stream workers.

Sample Data Fixtures

Sample Example 1
Input Stream:
['apple', 'banana', 'apple']
Expected Output:
[('apple', 2), ('banana', 1)]
Sample Example 2
Input Stream:
['beam', 'beam', 'beam']
Expected Output:
[('beam', 3)]
Topics:#CombinePerKey#KV Pairs
Support