Foundation LabEasy
Lab: Sales Report
Estimated time: 20 mins
Who This Lab Is For
Beginner developers seeking to perform row-level calculations and global mathematical aggregations.
What You Will Learn
- How to calculate derived values dynamically per row (quantity * price).
- How to use CombineGlobally with built-in mathematical operators.
- How to write single-value results to output files.
1. Business Scenario
Summarize transactions to calculate total sales revenue.
2. Input Dataset (\`dataset.csv\`)
Save the following raw rows locally as \`dataset.csv\` to test your pipeline:
text
transaction_id,product_id,quantity,unit_price
tx1,p1,1,999.99
tx2,p2,2,149.99
tx3,p3,1,250.00
tx4,p2,1,149.99
tx5,p4,10,4.993. Starter Code Skeleton
Create a local file named \`starter.py\` and copy the following skeleton. Complete the missing transformations:
python
# starter.py - Sales Report
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
def run_pipeline():
options = PipelineOptions()
with beam.Pipeline(options=options) as p:
# TODO: Parse sales quantities and unit prices
# TODO: Calculate revenue per transaction
# TODO: Sum global sales revenue
pass
if __name__ == "__main__":
run_pipeline()4. Lab Requirements
- Calculate individual transaction revenue (quantity * unit_price).
- Sum the revenues globally to calculate total catalog sales revenue.
- Output the final total revenue value as a single floating-point number.
5. Step-by-Step Guide & Solution
Advertisement
AdSense Slot #847392Leaderboard Banner (728x90)