Batch LabMedium
Lab: Inventory Analytics
Estimated time: 30 mins
Who This Lab Is For
Intermediate developers looking to master advanced data routing, alerts, and side-output tag collections.
What You Will Learn
- How to split a single pipeline flow into multiple branches.
- How to output elements to tagged side-outputs using TaggedOutput.
- How to aggregate global inventories alongside logging alerts in parallel.
1. Business Scenario
Calculate total stock valuation and identify low stock items.
2. Input Dataset (\`dataset.csv\`)
Save the following raw rows locally as \`dataset.csv\` to test your pipeline:
text
item_code,name,stock_level,unit_cost
item1,Widget A,150,2.50
item2,Widget B,40,12.00
item3,Widget C,8,45.00
item4,Widget D,120,1.25
item5,Widget E,5,80.003. Starter Code Skeleton
Create a local file named \`starter.py\` and copy the following skeleton. Complete the missing transformations:
python
# starter.py - Inventory Analytics
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: Calculate values
# TODO: Separate low stock items using dynamic routing
# TODO: Output inventory reports
pass
if __name__ == "__main__":
run_pipeline()4. Lab Requirements
- Calculate total valuation per item (stock_level * unit_cost).
- Identify and tag low stock items (stock_level < 15) using Side Outputs.
- Calculate total inventory cost valuation globally.
5. Step-by-Step Guide & Solution
Advertisement
AdSense Slot #847392Leaderboard Banner (728x90)