Sample questions
Question 1Easy
Spark DataFrames differ from RDDs mainly because they:
- Have a named-column schema and use the Catalyst optimizer
- Cannot be distributed
- Are always stored on disk by default
- Support only numeric data for every job
Answer: A. Have a named-column schema and use the Catalyst optimizer
Explanation
Schema information lets Spark optimise queries; RDDs are opaque objects.
Step-by-step solution
- A DataFrame has named columns and a schema of types.
- Because Spark knows the schema, the Catalyst optimizer can rewrite the query plan.
- An RDD has no schema, so Spark cannot look inside its functions to optimise them.
- So the main difference is the named-column schema with Catalyst (option A).
Why the other options are wrong
- B. DataFrames can be distributed across the cluster, just like RDDs.
- C. DataFrames are not stored on disk by default; storage depends on caching and use.
- D. DataFrames support many data types, not only numeric ones.
Tip: Schema plus Catalyst gives optimised queries; prefer DataFrames for structured work.
Question 2Easy
A Spark DataFrame is best described as
- A distributed collection of rows organised into named columns
- A single-node spreadsheet that has to fit in the memory of a single machine
- A stream of bytes
- A graph of vertices only
Answer: A. A distributed collection of rows organised into named columns
Explanation
A DataFrame adds schema and lets the Catalyst optimiser plan queries.
Step-by-step solution
- Rows plus named columns.
- Has a schema.
- Optimised by Catalyst.
Why the other options are wrong
- B. It is distributed.
- C. It has a schema.
- D. That is a graph abstraction.
Question 3Medium
Which format is columnar and commonly used with Spark for efficient analytics?
- CSV
- Plain text log
- Parquet
- XML
Answer: C. Parquet
Explanation
Columnar layout allows column pruning and better compression; CSV is row-oriented text.
Step-by-step solution
- Parquet stores data column by column, not row by row.
- Column layout lets Spark read only the columns a query needs.
- Values of one column are similar, so they compress well.
- So the columnar format is Parquet (option C).
Why the other options are wrong
- A. CSV is row-oriented text.
- B. A plain text log is row-oriented text with no column layout.
- D. XML is a row-oriented, nested text format.
Tip: Row formats such as CSV suit raw data; columnar formats such as Parquet suit analytics.
Question 4Medium
What does the Catalyst optimiser do in Spark SQL?
- Stores data in HDFS and writes the result tables to the metastore
- Rewrites logical plans (for example pushing filters down) into efficient physical plans
- Replaces the cluster manager
- Encrypts queries
Answer: B. Rewrites logical plans (for example pushing filters down) into efficient physical plans
Explanation
It applies rule-based and cost-based optimisations such as predicate pushdown and column pruning.
Step-by-step solution
- Parse the query.
- Optimise the logical plan.
- Pick a physical plan.
Why the other options are wrong
- A. Storage is separate.
- C. Not its role.
- D. Not its function.
Question 5Medium
Why do DataFrames usually perform better than raw RDDs for structured data?
- They avoid using memory because they hold fewer rows in memory than an RDD does
- They do not need executors
- They carry a schema, enabling optimisation and compact binary storage
- They are not lazy
Answer: C. They carry a schema, enabling optimisation and compact binary storage
Explanation
Knowing the schema lets Spark optimise the plan and manage memory efficiently.
Step-by-step solution
- Schema known upfront.
- Catalyst optimises.
- Tungsten stores compactly.
Why the other options are wrong
- A. They use memory efficiently, not none.
- B. They run on executors.
- D. They are lazy as well.
Question 6Medium
Which of the following will usually trigger a shuffle in Spark SQL?
- select('a'), a column projection
- filter(col > 5), a row filter
- withColumn('b', col+1), a per-row expression
- groupBy().count()
Answer: D. groupBy().count()
Explanation
Aggregations by key need rows with the same key to meet in one partition.
Step-by-step solution
- Narrow: row-local ops.
- groupBy needs same keys together.
- So a shuffle.
Why the other options are wrong
- A. Projection is narrow and row-local.
- B. Filtering is narrow and partition-local.
- C. A per-row expression is narrow.
Question 7Medium
In the DataFrame API, df.filter(df.age > 30).select('name') will compute
- Immediately after filter is called because transformations in Spark always execute eagerly on the driver
- Only on the driver machine
- Only after an action triggers it, since both calls are lazy
- Never, since select is invalid
Answer: C. Only after an action triggers it, since both calls are lazy
Explanation
Both filter and select build the plan; show(), count() or write start execution.
Step-by-step solution
- filter: lazy.
- select: lazy.
- Action needed to run.
Why the other options are wrong
- A. Filter is a lazy transformation.
- B. It runs distributed on executors.
- D. select is valid.
Question 8Medium
Which is the best way to join a very large table with a very small one in Spark SQL?
- Shuffle both tables with sort-merge always for every job
- Collect the large table to the driver in current releases
- Cache the large table only
- Broadcast the small table to every executor
Answer: D. Broadcast the small table to every executor
Explanation
A broadcast join avoids shuffling the large table.
Step-by-step solution
- A broadcast join copies the small table to every executor.
- Each executor joins its local part of the large table with the copy.
- The large table is not shuffled, so the network cost stays low.
- So the best choice is to broadcast the small table (option D).
Why the other options are wrong
- A. A sort-merge join shuffles both tables, which is costly when one table is small.
- B. Collecting the large table to the driver would overload the driver's memory.
- C. Caching the large table does not avoid the shuffle needed for the join.
Tip: If the small table fits in executor memory, use a broadcast join.
Question 9Hard
In Spark, what does the Catalyst optimizer do for DataFrame queries?
- Encrypts data between nodes on each node
- Chooses the HDFS replication factor in current releases
- Rewrites the logical plan, e.g. predicate pushdown and column pruning
- Restarts failed executors
Answer: C. Rewrites the logical plan, e.g. predicate pushdown and column pruning
Explanation
Catalyst applies rule-based and cost-based optimisations before generating physical plans.
Step-by-step solution
- Catalyst is the optimizer behind Spark SQL and DataFrames.
- It works on the logical plan of a query.
- It applies rules such as predicate pushdown and column pruning.
- So Catalyst rewrites the logical plan (option C).
Why the other options are wrong
- A. Encrypting data between nodes is not Catalyst's job.
- B. The HDFS replication factor is a storage setting, not a Catalyst task.
- D. Restarting failed executors is part of cluster and fault recovery, not Catalyst.
Tip: Catalyst is the query optimizer: filter early and read only the columns you need.
Question 10Hard
A small dimension table is joined with a huge fact table in Spark. Which join strategy usually works best?
- Sort-merge join with a full shuffle of both tables, because every key is sorted before the join starts
- Broadcast hash join, sending the small table to all executors
- Cartesian product
- Collect the big table to the driver
Answer: B. Broadcast hash join, sending the small table to all executors
Explanation
Broadcasting the small table avoids shuffling the large one.
Step-by-step solution
- One side is small.
- Broadcast it to executors.
- Join locally, no big shuffle.
Why the other options are wrong
- A. More expensive when one side is small.
- C. Explodes the row count.
- D. Would exhaust driver memory.
Practise all 12 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 →