Aggregations & Grouping⏱️ ~12 mins
14. Distributed Average Sensor Reading
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
Environmental monitoring stations calculate the arithmetic mean temperature across hundreds of remote geographic sensors.
### Problem Statement
Write a function `mean_reading(input_pcoll)` that calculates the global arithmetic mean across all numeric elements in a PCollection using `beam.combiners.Mean.Globally()`.
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:
[10, 20, 30]
Expected Output:
20.0
Sample Example 2
Input Stream:
[5, 5, 5]
Expected Output:
5.0
Topics:#CombineGlobally#Aggregations
solution.pyPython 3.11 (Apache Beam)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Input PCollection3 elements
| # | Element / Payload |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
Expected Output PCollection
20.0
Aggregations & Grouping⏱️ ~12 mins
14. Distributed Average Sensor Reading
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
Environmental monitoring stations calculate the arithmetic mean temperature across hundreds of remote geographic sensors.
### Problem Statement
Write a function `mean_reading(input_pcoll)` that calculates the global arithmetic mean across all numeric elements in a PCollection using `beam.combiners.Mean.Globally()`.
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:
[10, 20, 30]
Expected Output:
20.0
Sample Example 2
Input Stream:
[5, 5, 5]
Expected Output:
5.0
Topics:#CombineGlobally#Aggregations