RDD Fundamentals
Learn the foundational concepts of Resilient Distributed Datasets (RDDs) in PySpark, including transformations, actions, and optimizations.
Question 1 of 20
Question 1
What does RDD stand for in PySpark?
Not this time. RDD stands for Resilient Distributed Dataset, a fundamental Spark data structure designed for parallel processing across multiple nodes.
Question 2
What are the key properties of an RDD?
Not this time. RDDs are immutable, distributed, and fault-tolerant, ensuring scalability and automatic recovery from failures.
Question 3
How can you create an RDD from a Python list?
Not this time. RDDs can be created from Python lists using
sparkContext.parallelize(), which distributes the data across Spark's cluster.Question 4
Which PySpark component is used to create RDDs?
Not this time. The
SparkContextacts as the gateway for interacting with Spark and is responsible for creating RDDs.Question 5
What is the main difference between transformations and actions in RDDs?
Not this time. Transformations are lazily evaluated and define a computation pipeline, whereas actions trigger execution and return results.
Question 6
Which of the following is an example of an RDD transformation?
Not this time. Transformations like
map()create a new RDD by applying a function to each element but do not execute immediately.Question 7
Which of the following is an example of an RDD action?
Not this time. Actions like
collect()trigger Spark to compute and return results to the driver, executing all preceding transformations.Question 8
How does Spark execute transformations on RDDs?
Not this time. Transformations in RDDs follow lazy evaluation, meaning computations are only performed when an action is called.
Question 9
Which method is used to apply a function to each element in an RDD?
Not this time. The
map()transformation applies a function to every element, producing a new RDD with transformed values.Question 10
What does the
filter()transformation do in an RDD?Not this time. The
filter()transformation removes elements that do not meet a specified condition, creating a new RDD with matching records.Question 11
Which RDD action returns the first element itself, rather than a list?
Not this time. first() returns the first element. take(1) returns a list holding it, top(1) returns a list with the largest element, and RDDs have no head() method.
Question 12
What is the purpose of the
reduce()action in RDDs?Not this time. The
reduce()action aggregates values in an RDD by applying a specified function, such as summing or multiplying elements.Question 13
Which storage level is used by default for caching an RDD?
Not this time. The default
MEMORY_ONLYstorage level keeps the RDD in memory, ensuring fast access but requiring enough RAM.Question 14
How can you persist an RDD in memory for faster access?
Not this time. You can use
cache()for temporary in-memory storage orpersist()to specify different storage levels.Question 15
What happens when an RDD transformation fails?
Not this time. Spark recomputes lost partitions from the original dataset using its lineage, ensuring fault tolerance.
Question 16
Which transformation is used to remove duplicate elements from an RDD?
Not this time. The
distinct()transformation eliminates duplicate records, creating a new RDD with only unique values.Question 17
What is the function of the
union()transformation in RDDs?Not this time. The
union()transformation combines two RDDs into one, retaining all elements, including duplicates.Question 18
How do you check the number of partitions in an RDD?
Not this time. You can use the
getNumPartitions()method to determine how many partitions an RDD is split into for parallel execution.Question 19
Why should you repartition an RDD?
Not this time. Repartitioning balances the workload by adjusting the number of partitions, improving performance and parallel processing.
Question 20
How do you convert an RDD into a DataFrame?
Not this time. RDDs can be converted into DataFrames with toDF() or spark.createDataFrame(). DataFrames are optimised by Catalyst, and newer environments such as Spark Connect support only the DataFrame API.
Sources
Where each fact comes from
Work it out
- CalculatorPartitions, brokers and disk for a Kafka topicMessages, their size, retention and readers in; the partitions, disk, network and brokers out.Kafka sizing calculator
- CalculatorSize a Spark or Databricks clusterThe Databricks workers to pick, or the executors, memory and shuffle partitions for your nodes, with every number explained.Spark sizing calculator