A DataFrame is a distributed collection of data organized into named columns, similar to a table in a database or a spreadsheet.
Click to reveal answer
beginner
What is an RDD in Apache Spark?
RDD stands for Resilient Distributed Dataset. It is a low-level distributed collection of objects that can be processed in parallel.
Click to reveal answer
intermediate
Why are DataFrames preferred over RDDs for most Spark applications?
DataFrames provide better performance through optimization, easier syntax, and support for SQL queries, unlike RDDs which require manual optimization and more code.
Click to reveal answer
intermediate
How do DataFrames improve performance compared to RDDs?
DataFrames use a query optimizer called Catalyst that automatically optimizes query plans, making operations faster than RDDs which do not have this optimization.
Click to reveal answer
intermediate
What is one advantage of RDDs over DataFrames?
RDDs offer more control and flexibility for low-level transformations and actions, which can be useful for complex custom processing.
Click to reveal answer
Which of the following is a key reason DataFrames are preferred over RDDs?
ARDDs are easier to use than DataFrames
BRDDs support SQL queries natively
CDataFrames have built-in optimization for queries
DDataFrames do not support named columns
✗ Incorrect
DataFrames use the Catalyst optimizer to improve query performance, which RDDs do not have.
What does RDD stand for in Apache Spark?
AResilient Distributed Dataset
BRandom Data Distribution
CReliable Data Document
DRapid Data Delivery
✗ Incorrect
RDD stands for Resilient Distributed Dataset, a core Spark data structure.
Which Spark data structure supports SQL queries directly?
ADataFrame
BRDD
CBoth DataFrame and RDD
DNeither DataFrame nor RDD
✗ Incorrect
DataFrames support SQL queries natively, making them easier for structured data processing.
What is a disadvantage of using RDDs compared to DataFrames?
ARDDs have named columns
BRDDs are faster than DataFrames
CRDDs support SQL queries natively
DRDDs require manual optimization
✗ Incorrect
RDDs do not have built-in query optimization and require manual tuning.
Which of the following is true about DataFrames?
AThey are harder to use than RDDs
BThey organize data into named columns
CThey do not support distributed processing
DThey cannot be optimized
✗ Incorrect
DataFrames organize data into named columns, similar to tables.
Explain why DataFrames are generally preferred over RDDs in Apache Spark.
Think about performance and ease of use.
You got /5 concepts.
Describe a scenario where using RDDs might be better than DataFrames.
Consider when you want more control over data processing.
You got /4 concepts.
Practice
(1/5)
1. Why are DataFrames generally preferred over RDDs in Apache Spark for data processing?
easy
A. Because RDDs support SQL queries natively
B. Because DataFrames provide better optimization and easier syntax for structured data
C. Because DataFrames require more code to write
D. Because RDDs are faster for all types of data
Solution
Step 1: Understand DataFrames and RDDs
DataFrames are optimized for structured data and support SQL-like operations, while RDDs are low-level and less optimized.
Step 2: Compare ease of use and performance
DataFrames require less code and Spark optimizes their execution, making them faster and easier to use than RDDs for structured data.
Final Answer:
Because DataFrames provide better optimization and easier syntax for structured data -> Option B
Quick Check:
DataFrames = optimized + easy syntax [OK]
Hint: DataFrames = faster + simpler for tables [OK]
Common Mistakes:
Thinking RDDs support SQL natively
Believing DataFrames need more code
Assuming RDDs are always faster
2. Which of the following is the correct way to create a DataFrame from a JSON file in Spark?
easy
A. spark.read.textFile("path/to/file.json")
B. spark.read.loadJson("path/to/file.json")
C. spark.createDataFrame("path/to/file.json")
D. spark.read.json("path/to/file.json")
Solution
Step 1: Recall Spark DataFrame reading syntax
The correct method to read JSON files into a DataFrame is spark.read.json(path).
Step 2: Check other options for correctness
Options B, C, and D use incorrect or non-existent methods for JSON DataFrame creation.
Final Answer:
spark.read.json("path/to/file.json") -> Option D
Quick Check:
Use spark.read.json() for JSON files [OK]
Hint: Use spark.read.json() to load JSON files [OK]
Common Mistakes:
Using non-existent methods like loadJson
Confusing createDataFrame with reading files
Using textFile which returns RDD, not DataFrame
3. Given the following Spark code, what will be the output schema of the DataFrame?
val df = spark.read.json("people.json")
df.printSchema()
medium
A. root
|-- age: long (nullable = true)
|-- name: string (nullable = true)