📖 Scenario: You work as a data analyst at a company that uses Google Cloud. Your team wants to analyze sales data using Apache Spark on Google Dataproc, a managed cloud service that makes big data processing easier and faster.Google Dataproc lets you create clusters of virtual machines to run Spark jobs without managing the infrastructure yourself.
🎯 Goal: Build a simple Spark program that simulates loading sales data, sets a configuration for a sales threshold, filters sales above that threshold, and prints the filtered results. This mimics how you would use Dataproc to process data efficiently.
📋 What You'll Learn
Create a dictionary with sales data for 5 products and their sales numbers
Create a variable for the sales threshold
Use a dictionary comprehension to filter products with sales above the threshold
Print the filtered dictionary
💡 Why This Matters
🌍 Real World
Google Dataproc helps companies run big data jobs on the cloud easily. Filtering sales data is a common task to find important insights quickly.
💼 Career
Data analysts and data engineers use Dataproc and Spark to process large datasets efficiently without managing servers.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Apples': 150, 'Bananas': 90, 'Cherries': 120, 'Dates': 60, 'Elderberries': 30
Apache Spark
Hint
Use curly braces {} to create a dictionary with product names as keys and sales numbers as values.
2
Set the sales threshold
Create a variable called sales_threshold and set it to 100
Apache Spark
Hint
Just assign the number 100 to the variable sales_threshold.
3
Filter sales above the threshold
Use a dictionary comprehension to create a new dictionary called filtered_sales that includes only products from sales_data with sales greater than sales_threshold
Apache Spark
Hint
Use {product: sales for product, sales in sales_data.items() if sales > sales_threshold} to filter the dictionary.
4
Print the filtered sales
Print the filtered_sales dictionary
Apache Spark
Hint
Use print(filtered_sales) to show the filtered dictionary.
Practice
(1/5)
1. What is the main purpose of Google Dataproc in data processing?
easy
A. To run Spark and Hadoop jobs easily in the cloud
B. To store large amounts of data permanently
C. To create visual dashboards for data
D. To write SQL queries on local machines
Solution
Step 1: Understand Google Dataproc's role
Google Dataproc is designed to simplify running big data jobs like Spark and Hadoop in the cloud.
Step 2: Compare options with this role
Only To run Spark and Hadoop jobs easily in the cloud describes running Spark and Hadoop jobs easily in the cloud, which matches Dataproc's main purpose.
Final Answer:
To run Spark and Hadoop jobs easily in the cloud -> Option A
Quick Check:
Dataproc = Run Spark/Hadoop jobs [OK]
Hint: Remember Dataproc runs Spark/Hadoop jobs in cloud [OK]
Common Mistakes:
Confusing Dataproc with storage services
Thinking Dataproc creates dashboards
Assuming Dataproc runs queries locally
2. Which of the following is the correct way to create a cluster in Google Dataproc using gcloud CLI?
easy
A. gcloud dataproc clusters create my-cluster --region=us-central1
B. gcloud dataproc create cluster my-cluster --zone=us-central1
C. gcloud create dataproc cluster my-cluster --region=us-central1
D. gcloud clusters dataproc create my-cluster --region=us-central1
Solution
Step 1: Recall correct gcloud command syntax
The correct command to create a Dataproc cluster is 'gcloud dataproc clusters create' followed by the cluster name and region.
Step 2: Match options with correct syntax
gcloud dataproc clusters create my-cluster --region=us-central1 matches the correct syntax exactly. Other options have wrong order or missing keywords.
Final Answer:
gcloud dataproc clusters create my-cluster --region=us-central1 -> Option A