databricks Data Engineer Associate · Practice questions

Section 3: Data Transformation and Modeling Practice Questions

Review 10 sample questions with their correct answers and explanations. Sign up free to continue with the full topic quiz.

Sign up free for the full quiz

Question 1

A silver table defines the expectation EXPECT (quantity >= 0) ON VIOLATION DROP ROW. 1,000 rows arrive and 12 violate it. What is the result?

  1. 988 rows are written and 12 are counted as dropped — Correct
  2. 12 rows are written to a quarantine table automatically
  3. No rows are written and the update fails
  4. 1,000 rows are written with a warning

Correct answer

988 rows are written and 12 are counted as dropped

Explanation

DROP ROW removes violating rows and records them in the data quality metrics.

Question 2

A transformation adds an ingestion timestamp to each row. Which code is correct?

  1. df.withColumn('ingested_at', current_timestamp()) — Correct
  2. df.addColumn('ingested_at', current_timestamp())
  3. df.select('*', lit('current_timestamp').alias('ingested_at'))
  4. df.select('*', 'current_timestamp')

Correct answer

df.withColumn('ingested_at', current_timestamp())

Explanation

withColumn with current_timestamp() adds a column with the processing timestamp.

Question 3

A data engineer needs to cross join a 12-row months table with a 500-row stores table to build a calendar per store. How many rows will result?

  1. 12
  2. 6,000 — Correct
  3. 512
  4. 500

Correct answer

6,000

Explanation

A cross join returns every combination: 12 × 500 = 6,000 rows.

Question 4

A silver table must remove duplicate events that share the same event_id. Which PySpark code keeps one row per event_id?

  1. df.distinct('event_id').orderBy('event_id')
  2. df.drop('event_id').distinct()
  3. df.dropDuplicates(['event_id']) — Correct
  4. df.groupBy('event_id').count()

Correct answer

df.dropDuplicates(['event_id'])

Explanation

dropDuplicates with a subset of columns keeps one row per key. distinct() does not take column arguments, and groupBy().count() returns counts, not rows.

Question 5

An engineer needs average, minimum and maximum order value per country, in one pass. Which code is correct?

  1. df.select('country', avg('amount'), min('amount'), max('amount'))
  2. df.groupBy('country').avg('amount').min('amount').max('amount')
  3. df.groupBy('country').agg(avg('amount'), min('amount'), max('amount')) — Correct
  4. df.agg(groupBy('country'), avg('amount'), min('amount'), max('amount'))

Correct answer

df.groupBy('country').agg(avg('amount'), min('amount'), max('amount'))

Explanation

groupBy().agg() computes several aggregates at once. Chaining avg().min() fails because avg returns a DataFrame without the original column.

Question 6

A silver table stores customer records with a column email. An engineer must split full_name into first_name and last_name. Which PySpark code is correct?

  1. df.withColumnRenamed('full_name', 'first_name, last_name')
  2. df.withColumn('first_name', split('full_name', ' ')[0]).withColumn('last_name', split('full_name', ' ')[1]) — Correct
  3. df.select(split('full_name').alias('first_name', 'last_name'))
  4. df.withColumn('first_name', explode(split('full_name', ' '))).withColumn('last_name', explode(split('full_name', ' ')))

Correct answer

df.withColumn('first_name', split('full_name', ' ')[0]).withColumn('last_name', split('full_name', ' ')[1])

Explanation

split returns an array; indexing it gives the parts. explode works on arrays, not strings.

Question 7

Which statement about liquid clustering on Delta tables is correct?

  1. Liquid clustering is only available for external CSV tables
  2. Keys can change without a rewrite; OPTIMIZE clusters new data incrementally — Correct
  3. Liquid clustering requires the table to also be partitioned by the clustering columns
  4. Liquid clustering is configured with ZORDER BY in the table definition

Correct answer

Keys can change without a rewrite; OPTIMIZE clusters new data incrementally

Explanation

Liquid clustering replaces partitioning and Z-ordering. Keys can be changed with ALTER TABLE ... CLUSTER BY; clustering is applied incrementally by OPTIMIZE.

Question 8

A data engineer must define a gold streaming table in SQL that reads new rows from the silver table orders_silver. Which statement is correct?

  1. CREATE TABLE gold_orders STREAMING AS orders_silver
  2. CREATE MATERIALIZED STREAM gold_orders FROM orders_silver
  3. CREATE STREAMING VIEW gold_orders AS SELECT * FROM orders_silver
  4. CREATE OR REFRESH STREAMING TABLE gold_orders AS SELECT * FROM STREAM(orders_silver) — Correct

Correct answer

CREATE OR REFRESH STREAMING TABLE gold_orders AS SELECT * FROM STREAM(orders_silver)

Explanation

Streaming tables are created with CREATE OR REFRESH STREAMING TABLE and read incremental input with STREAM().

Question 9

In Lakeflow Declarative Pipelines, a silver table defines the expectation CONSTRAINT valid_amount EXPECT (amount > 0). What happens to rows with amount <= 0?

  1. They are dropped from the table and recorded in the metrics
  2. The pipeline update fails immediately
  3. They are moved to a quarantine table automatically
  4. They are kept, and the violation is counted in the metrics — Correct

Correct answer

They are kept, and the violation is counted in the metrics

Explanation

Without an ON VIOLATION clause, expectations only warn: invalid rows are kept and counted in data quality metrics. DROP ROW drops them; FAIL UPDATE stops the update.

Question 10

Which statement about expectations in Lakeflow Declarative Pipelines is correct?

  1. Expectations replace Unity Catalog permissions
  2. Expectations can only be defined in Python
  3. Their pass and fail counts are stored in the pipeline event log — Correct
  4. Expectations are evaluated only when users query the table

Correct answer

Their pass and fail counts are stored in the pipeline event log

Explanation

Expectation metrics are stored in the event log and shown in the pipeline UI, supporting monitoring of data quality over time.

Ready for the full quiz?

Create a free QuizAnalyst account to practice the complete question set and save your progress.

Sign up free for the full quiz