Sample questions
Question 1Easy
Which transformation is narrow (no shuffle needed)?
- filter
- distinct
- groupByKey
- repartition
Answer: A. filter
Explanation
In a narrow transformation each output partition depends on one input partition; the others redistribute data by key or count.
Step-by-step solution
- A narrow transformation needs no shuffle, because each output partition comes from one input partition.
- Filter keeps or drops rows inside each partition, so no data has to move.
- Distinct, groupByKey and repartition all move rows between partitions.
- The correct answer is option A: filter is narrow.
Why the other options are wrong
- B. Distinct must compare rows across partitions, so it needs a shuffle.
- C. GroupByKey brings all rows with the same key together, which is a shuffle.
- D. Repartition redistributes rows across partitions, so it shuffles.
Tip: Map, filter and select are narrow; anything that groups, joins or redistributes is wide.
Question 2Easy
Which Spark component executes tasks and holds cached data?
- The driver
- Executors
- The scheduler UI
- The catalog
Answer: B. Executors
Explanation
Executors are worker processes; the driver coordinates them.
Step-by-step solution
- Executors run tasks on worker nodes.
- They also store data in memory for fast access.
- The driver manages executors but does not execute tasks itself.
- Schedulers handle task scheduling, not execution.
- Cached data is stored by executors during processing.
Why the other options are wrong
- A. The driver coordinates the job and does not execute tasks or hold the executors' cached data.
- C. The scheduler UI is a web page for monitoring jobs; it runs no tasks and stores no data.
- D. The catalog keeps table metadata, not running tasks or cached data partitions.
Tip: Remember: Executors do the work and hold cached data.
Question 3Easy
Spark transformations are lazy. This means:
- They are executed immediately in order
- They run on one CPU core to save power
- They build a plan that runs only when an action is called
- They are skipped entirely if the data is small enough to fit in memory
Answer: C. They build a plan that runs only when an action is called
Explanation
Laziness lets Spark optimise the whole plan before running it.
Step-by-step solution
- Spark transformations such as map, filter and select are lazy.
- Calling a transformation only adds a step to the plan.
- The work runs when an action such as count, collect or write is called.
- The correct answer is option C: they build a plan that runs only when an action is called.
Why the other options are wrong
- A. Transformations do not run when called; they wait for an action.
- B. Laziness is not about using one core; the work is spread across executors.
- D. Data size does not decide whether a transformation runs.
Tip: Transformations build the plan; actions such as count or collect run it.
Question 4Easy
The Spark driver is responsible for:
- Running all tasks itself without executors
- Replacing failed disks on worker machines
- Building the plan and scheduling tasks on executors
- Storing every partition of the data in its memory
Answer: C. Building the plan and scheduling tasks on executors
Explanation
The driver coordinates; executors do the distributed work.
Step-by-step solution
- The Spark driver runs the main program and builds the execution plan.
- It splits the job into stages and tasks.
- It sends the tasks to executors and tracks their results.
- The correct answer is option C: building the plan and scheduling tasks on executors.
Why the other options are wrong
- A. Tasks run on executors, not on the driver alone.
- B. Replacing failed disks is a hardware job for the cluster, not the Spark driver.
- D. Partitions are held by executors; the driver does not store every partition.
Tip: The driver plans and schedules; executors do the work and hold the data.
Question 5Medium
Compared with RDDs, DataFrames are usually faster because:
- DataFrames always run on GPUs instead of CPUs
- RDDs cannot be distributed across machines, so they always run on one node
- The schema lets the Catalyst optimiser plan and generate efficient code
- DataFrames skip the shuffle stage entirely
Answer: C. The schema lets the Catalyst optimiser plan and generate efficient code
Explanation
With known columns and types, Spark can reorder operations, prune columns and push filters down.
Step-by-step solution
- A DataFrame carries a schema, so Spark knows the column names and types.
- The Catalyst optimiser uses that schema to rewrite and plan the query.
- It can prune unused columns, push filters down and generate efficient code.
- The correct answer is 2: the schema lets Catalyst plan and generate efficient code.
Why the other options are wrong
- A. DataFrames run on the same CPU executors; GPUs are not the reason for the speed.
- B. RDDs are distributed across machines just like DataFrames.
- D. DataFrames still shuffle when grouping or joining, so the shuffle is not skipped.
Tip: Prefer DataFrames over RDDs when the data has columns, so Catalyst can optimise the plan.
Question 6Medium
coalesce(10) differs from repartition(10) because coalesce:
- Reduces partitions by merging them without a full shuffle
- Shuffles all the data evenly across the cluster into exactly ten partitions
- Sorts the data before writing it to ten files
- Always increases the number of partitions to ten
Answer: A. Reduces partitions by merging them without a full shuffle
Explanation
coalesce merges existing partitions (cheap but can be uneven); repartition does a full shuffle for even sizes.
Step-by-step solution
- coalesce merges partitions.
- It avoids a full shuffle.
- It only reduces the partition count.
Why the other options are wrong
- B. That describes repartition.
- C. It does not sort.
- D. It cannot increase partitions.
Tip: coalesce = fewer, no shuffle.
Question 7Medium
A 10 GB file is read with a split size of 128 MB. About how many input partitions result?
- 10
- 128
- 80
- 1,280
Answer: C. 80
Explanation
10 × 1024 MB / 128 MB = 80 partitions.
Step-by-step solution
- Total file size is 10 GB = 10 × 1024 MB = 10240 MB.
- Each partition is 128 MB, so divide 10240 by 128: 10240 / 128 = 80.
- Thus, the number of partitions is 80.
Why the other options are wrong
- A. Ten is the number of files, not partitions; the 10 GB file is split by size into many pieces.
- B. 128 is the split size in MB, not the number of partitions produced from the file.
- D. 1,280 would need 8 MB splits; with 128 MB splits, 10 GB gives about 80 partitions.
Tip: Always convert units before dividing for accurate results.
Question 8Medium
In the Spark code below, how many shuffle boundaries does the chain contain?
rdd.map(f).filter(g).reduceByKey(add).mapValues(h).sortByKey().collect()
- 1
- 3
- 5
- 2
Answer: D. 2
Explanation
reduceByKey and sortByKey each redistribute data by key; map, filter and mapValues are narrow.
Step-by-step solution
- Map, filter and mapValues are narrow, so they add no shuffle boundary.
- ReduceByKey redistributes data by key, which is the first shuffle boundary.
- SortByKey redistributes data by key range, which is the second shuffle boundary.
- The correct answer is option D: 2 shuffle boundaries.
Why the other options are wrong
- A. There are two wide steps, reduceByKey and sortByKey, so one is too few.
- B. Only reduceByKey and sortByKey are wide; map, filter and mapValues are narrow.
- C. Five is too many; only the two wide steps create shuffle boundaries.
Tip: Count the wide steps (reduceByKey, groupByKey, sortByKey, joins); narrow steps add no boundary.
Question 9Hard
One key holds 40% of all rows, and the task handling it runs for an hour while others finish in a minute. What is a common fix?
- Cache the table before running the join
- Salt the hot key to spread it over several partitions, then combine
- Reduce the number of executors to one
- Increase the driver's memory and run again with the same partitioning
Answer: B. Salt the hot key to spread it over several partitions, then combine
Explanation
Data skew concentrates work in one task; salting (or adaptive skew handling) splits the heavy key.
Step-by-step solution
- Hot key has 40% of data causing uneven load.
- Salting spreads data across partitions to balance tasks.
- Combine results after processing for correct output.
- This reduces task imbalance and improves performance.
- Final answer: Salt the hot key to spread it over several partitions, then combine.
Why the other options are wrong
- A. Caching does not fix skew; the hot key still lands in one slow task after the cache.
- C. One executor removes parallelism, making the job slower, not fixing the skewed key.
- D. More driver memory does not split the hot key; the same partitioning keeps the slow task.
Tip: Use salting to handle skewed data by distributing keys across partitions.
Question 10Hard
A Spark job writes output with 2,000 shuffle partitions, producing 2,000 tiny files. Which change is most direct?
- Call
collect() and write one output file from the driver process instead - Increase the number of executors to 2,000
- Coalesce or repartition to fewer partitions before writing
- Switch the output format from Parquet to CSV
Answer: C. Coalesce or repartition to fewer partitions before writing
Explanation
The number of output files follows the number of partitions at write time.
Step-by-step solution
- Shuffle partitions determine output file count.
- Reducing partitions reduces output files.
- Coalesce or repartition to fewer partitions before writing.
- This directly cuts the number of tiny files.
- Final answer: Coalesce or repartition to fewer partitions before writing.
Why the other options are wrong
- A. Collect pulls all data into one process, which can run out of memory and still does not fix the partition count.
- B. More executors do not reduce the partition count; the 2,000 partitions still create 2,000 files.
- D. Switching to CSV does not change the number of files; the partition count still sets the file count.
Tip: Reduce partitions before writing to cut output files.
Practise all 31 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →