Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Databricks Certified Associate Developer for Apache Spark 3.5 - Python Databricks-Certified-Associate-Developer-for-Apache-Spark-3.5 Exam Questions

Last updated: · 13 practice questions with answers and explanations

Page: 1 / 14 Total 135 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Section 1: Apache Spark Architecture and Components

Skill tested: Trace DataFrame transformations, actions, jobs, stages, and tasks in Spark execution.

A batch application reads a large Parquet dataset, filters rows, selects two columns, groups by one selected column, and writes the aggregated result. The filter and projection can be evaluated from Parquet metadata and pushed into the scan. The group-by key is not already partitioned, and the write is an action. An engineer is reviewing the Spark UI and wants to explain the execution hierarchy without assuming that each API call creates a separate job. Which description is most accurate?

Correct Answer: C. The write action triggers a job; narrow transformations can be pipelined within stages, while the group-by shuffle creates a stage boundary and tasks operate on partitions.
Explanation:

DataFrame transformations are generally lazy; the write action causes Spark to execute the required lineage. Operations such as filters and projections can be pipelined when they do not require data exchange. Grouping by a key normally requires a shuffle, which introduces a stage boundary. Spark schedules tasks for partitions, not individual rows. The other descriptions incorrectly treat each transformation as a job, assume eager source execution, or characterize a shuffle-dependent aggregation as narrow.

Question 2

New Multiple answers

Topic: Section 1: Apache Spark Architecture and Components

Skill tested: Choose partitioning operations that control shuffle costs and parallelism.

A team joins two DataFrames repeatedly on the same customer key. Both have been read from storage with many small input partitions, and the join currently causes a large shuffle. The cluster has enough memory for both inputs, but the team must avoid collecting data to the driver and wants the join to remain distributed. They can change the DataFrame pipeline, but cannot change the source files. Which two actions are appropriate candidates to reduce unnecessary data movement for this workload? Select TWO.

Correct Answer: D. Repartition both DataFrames by the join key before the joins, so their data is distributed by that key.; E. Use repartition with a suitable partition count and the join key when that partitioning can be reused by the join stages.
Explanation:

Repartitioning by the join key can establish hash partitioning that is useful to a subsequent join, and choosing a suitable partition count helps preserve parallelism. It is worthwhile when that distribution can be reused; repartitioning itself is a shuffle, so it is not automatically beneficial for every pipeline. Coalescing both sides to one partition destroys parallelism and does not make a distributed join efficient. Caching avoids recomputation, not required shuffle exchanges. Collecting to Python lists violates the distributed-processing constraint and can exhaust driver memory.

Question 3

New Single answer

Topic: Section 2: Using Spark SQL

Skill tested: Configure JDBC reads and writes with partition bounds and parallelism in mind.

A Spark job must read a large relational table through JDBC and write transformed results back to a database. The database team has approved concurrent access, supplied an indexed numeric column suitable for range partitioning, and limited the job to eight parallel connections. The result table must be replaced on each run. Which approach best meets these requirements while keeping the work distributed?

Correct Answer: D. Use JDBC range partitioning on the indexed column with eight partitions, then write the output with JDBC and mode("overwrite").
Explanation:

JDBC range partitioning uses a numeric partition column and lower and upper bounds to divide the read into parallel queries; numPartitions controls the intended read parallelism. The scenario provides an indexed column and a connection limit, making eight partitions appropriate. Writing in overwrite mode replaces the destination according to the JDBC writer's overwrite behavior. A single-connection driver read is not distributed, omitting range parameters does not cause Spark to infer them, and append preserves existing rows rather than replacing the result.

Question 4

New Single answer

Topic: Section 2: Using Spark SQL

Skill tested: Apply partitionBy and overwrite modes without unintentionally replacing unrelated data.

A daily job writes a DataFrame of events as Parquet partitioned by `event_date`. The output path contains many dates, and the requirement is to refresh only the date being processed while preserving all other date partitions. The job writes one date per run. The team currently uses `mode("overwrite")` with `partitionBy("event_date")` and is concerned about the scope of replacement. Which adjustment is the safest match for the requirement?

Correct Answer: B. Keep overwrite mode and set `spark.sql.sources.partitionOverwriteMode` to `dynamic` for the write.
Explanation:

With dynamic partition overwrite enabled for a compatible file-source write, overwrite is applied to partitions that receive data, allowing the job to replace the date partition it writes while retaining other partitions. The default static overwrite behavior can replace a broader target, so the mode must be configured deliberately. Append does not automatically replace matching partitions. Removing partitioning and overwriting the path does not preserve unrelated data, and temporary views have no effect on file overwrite semantics.

Question 5

New Multiple answers

Topic: Section 3: Developing Apache Spark DataFrame/DataSet API Applications

Skill tested: Use explode and column operations to normalize nested array data.

A telemetry DataFrame has schema `device_id STRING, readings ARRAY`. Each input row can contain zero or more readings. Analysts need one output row per reading, retaining the device identifier and exposing the nested metric and value as top-level columns. Rows with an empty or null array should not generate a reading row. Which TWO transformations satisfy the requirement? Select TWO.

Correct Answer: A. Apply `explode("readings")` to create one row per array element, then select `device_id` and the element fields.; E. Use `selectExpr("device_id", "explode(readings) AS reading")`, then select `reading.metric` and `reading.value`.
Explanation:

The `explode` generator emits a row for each array element and emits no row for an empty or null array, matching the stated behavior. Selecting the generated struct's fields exposes `metric` and `value` as top-level columns while preserving `device_id`. The SQL-expression form in C performs the same operation. `explode_outer` retains a null-generated row unless filtered, while collecting arrays aggregates rather than expands them. Dropping or renaming columns does not flatten nested data.

Question 6

New Multiple answers

Topic: Section 3: Developing Apache Spark DataFrame/DataSet API Applications

Skill tested: Select join types and union operations that preserve required rows and schemas.

A reporting pipeline combines a current-customer DataFrame with a transaction DataFrame. It must retain every current customer, including customers with no transactions, and attach matching transaction columns where present. A second feed has the same logical columns as the first feed but lists them in a different order. The feeds must be combined without assigning values to the wrong columns. Which TWO operations meet these requirements? Select TWO.

Correct Answer: C. Use `unionByName` for the feeds after confirming their column names and compatible data types.; D. Use a left outer join from current customers to transactions on the customer key.
Explanation:

A left outer join keeps every row from the left, current-customer DataFrame, and supplies nulls for transaction columns when there is no match. `unionByName` aligns the two feed schemas by column name, avoiding the positional misalignment that ordinary `union` can cause when column orders differ. An inner join drops unmatched customers. A right join with transactions on the left preserves transaction rows, not necessarily all customers. The schemas still need compatible types.

Question 7

New Single answer

Topic: Section 3: Developing Apache Spark DataFrame/DataSet API Applications

Skill tested: Implement a Python UDF with an explicit return type for DataFrame expressions.

A pipeline applies a specialized Python-only normalization function to a string column. The function returns a Python string, and the result must be usable as a Spark DataFrame column in a subsequent filter and write. The team accepts Python UDF execution because the algorithm is unavailable as a built-in Spark SQL expression, but wants the schema to be reliable. What is the appropriate implementation?

Correct Answer: D. Register a Python UDF with a `StringType` return type and invoke it with the input Column in a DataFrame expression.
Explanation:

A Python UDF wraps a Python callable as a Spark expression and declares its return type, enabling Spark to include the result in a DataFrame schema and downstream transformations. Since the function returns strings, `StringType` is the appropriate declared type. A normal Python function cannot generally operate directly on a distributed Column. Collecting and recreating data on the driver is unsafe for large datasets, and calling `collect()` inside a UDF is not a valid distributed transformation pattern.

Question 8

New Single answer

Topic: Section 3: Developing Apache Spark DataFrame/DataSet API Applications

Skill tested: Convert between distributed DataFrames and bounded local Python collections safely.

A service receives a small, validated reference table whose maximum size is strictly limited to a few hundred rows. It needs to inspect the rows in Python to construct a local lookup structure, while the main fact dataset remains distributed. The team wants to avoid transferring an unbounded result to the driver. Which approach best fits this requirement?

Correct Answer: B. Collect only the bounded reference DataFrame to the driver and construct the local lookup from its returned rows.
Explanation:

A bounded reference DataFrame can be collected to the driver when its size is known to be small, allowing Python code to build the required local lookup. The fact DataFrame remains distributed, avoiding an unbounded driver transfer. Collecting the full fact data risks driver-memory exhaustion; `toLocalIterator` can reduce peak transfer behavior but retaining all unbounded rows in a list still violates the constraint. A temporary view is a SQL interface, not a Python sequence.

Question 9

New Single answer

Topic: Section 4: Troubleshooting and Tuning Apache Spark DataFrame API Applications

Skill tested: Diagnose key skew and choose a repartitioning strategy that addresses its cause.

A job joins two large DataFrames on `account_id`. The Spark UI shows most shuffle partitions complete quickly, while a small number run far longer and spill heavily. Inspection reveals that a few account IDs occur in a very large fraction of the rows. The task count is already adequate, and the source data cannot be changed. What is the most appropriate first tuning direction?

Correct Answer: C. Treat the issue as key skew and consider a skew-aware strategy, such as salting the hot keys with a matching expansion on the other side where semantics permit.
Explanation:

The long-running, spill-heavy tasks concentrated on a few keys are characteristic of key skew. Increasing the shuffle partition count alone does not necessarily split identical keys, which hash to the same partition. Salting can distribute hot-key work, but the corresponding rows on the other side must be replicated or otherwise handled so join semantics remain correct. Coalescing reduces partitions and can worsen imbalance. Caching may save recomputation but does not redistribute skewed keys.

Question 10

New Single answer

Topic: Section 4: Troubleshooting and Tuning Apache Spark DataFrame API Applications

Skill tested: Explain AQE partition coalescing and runtime query-plan adaptation.

A batch aggregation initially produces many small shuffle partitions because input volume varies widely by day. Adaptive Query Execution is enabled, and the application uses Spark SQL/DataFrame operations. During a low-volume run, the final plan shows fewer post-shuffle tasks than the initial shuffle partition count. No application code explicitly calls `coalesce`. Which explanation best accounts for this observation?

Correct Answer: D. AQE can use runtime statistics to coalesce small post-shuffle partitions, reducing task overhead for the query.
Explanation:

With AQE enabled, Spark can use statistics gathered during execution to adapt a query plan, including coalescing small post-shuffle partitions. A low-volume run can therefore have fewer tasks in a later stage than the initial shuffle partition setting suggests. AQE does not eliminate required shuffle exchanges or rewrite source files. Nor does it force every write to a single task; parallelism continues to depend on the plan and data.

Question 11

New Multiple answers

Topic: Section 5: Structured Streaming

Skill tested: Configure watermark-based window aggregation and streaming deduplication semantics.

A streaming source emits event records with `event_time`, `device_id`, and a payload. Events can arrive up to 20 minutes late; beyond that, the application may discard them to bound state. The output must contain counts per 10-minute event-time window and device, and repeated device events should be deduplicated using event time and device identity. Which TWO design choices are appropriate? Select TWO.

Correct Answer: A. Apply a 20-minute watermark to `event_time` before the stateful operations, and group by an event-time window and `device_id` for the count.; B. Use streaming `dropDuplicates` on `event_time` and `device_id` with a watermark so retained deduplication state can be bounded.
Explanation:

An event-time window groups records according to their event timestamps, and a watermark establishes the lateness threshold used to manage state for supported stateful operations. Streaming deduplication on the chosen identity columns can use the watermark to bound retained state; records later than the allowed lateness may be dropped. Processing-time windows do not provide event-time semantics. Without a watermark, deduplication state can grow without a defined event-time bound, and collecting each batch to the driver is not an appropriate scalable streaming design.

Question 12

New Single answer

Topic: Section 5: Structured Streaming

Skill tested: Select a streaming output mode compatible with a stateful aggregation and sink.

A Structured Streaming query performs a windowed aggregation and writes results to a file sink. The team wants output files to contain only finalized aggregate results after the event-time watermark has passed each window's end. It does not need intermediate updates, and it wants to avoid repeatedly rewriting changing aggregate values. Which output mode is the best fit?

Correct Answer: C. Append mode, with the watermark allowing completed windows to be emitted as final rows.
Explanation:

Append mode emits rows that are newly added to the result table; for a supported event-time aggregation, a watermark allows Spark to determine when a window is sufficiently late and can be finalized for append output. Complete mode outputs the entire result table each trigger, rather than only newly finalized rows. Update mode can emit changed aggregate rows before finalization. Without a watermark, Spark lacks the stated lateness bound for finalizing event-time windows in this manner.

Question 13

New Single answer

Topic: Section 6: Using Spark Connect to Deploy Applications

Skill tested: Distinguish Spark Connect client execution from driver-side Spark application execution.

A data team wants analysts to submit DataFrame transformations from remote Python clients while the Spark driver and executors remain managed in a shared environment. Clients must not require a local Spark installation or directly access executor internals. The team is evaluating Spark Connect for this interaction model. Which description is accurate?

Correct Answer: A. Spark Connect sends DataFrame plans through a client-server protocol to a remote Spark server, where Spark executes the work.
Explanation:

Spark Connect separates the client from the Spark execution environment: a client builds DataFrame operations and communicates plans to a Spark server, which executes them in the managed Spark environment. The client does not need to host the driver or coordinate directly with executors. This is not client deploy mode, nor does it transfer the full dataset to the client for local execution. Direct local SparkContext and executor access are not the Spark Connect interaction model.