Skip to main content
📘 Complete PDF

Databricks Certification Practice Test 06

Practice Test 06

Question 1 of 20
📋 Multiple Choice
Question 91
A Delta table already contains data. A Data Engineer attempts to write a DataFrame containing an additional column that does not exist in the destination table. To allow the write operation without manually recreating or altering the table schema beforehand, the engineer should enable _____.
A. Schema Enforcement
✓
B. Schema Evolution (mergeSchema)
C. Checkpointing
D. Z-Ordering
Answer
✅ B. Schema Evolution (mergeSchema)
Explanation

1. Concept Overview / Core Concept / Direct Confirmation To allow append or overwrite operations to introduce new columns into an existing Delta Lake table automatically, the engineer must enable **Schema Evolution** (typically configured via the `.option("mergeSchema", "true")` write option or Spark session setting).

2. Why This Answer Is Correct / Detailed Breakdown Delta Lake enforces schema validation by default (**Schema Enforcement** / **Schema Validation**). If an incoming DataFrame has columns that do not match the target table's schema, Delta Lake immediately rejects the write with an `AnalysisException` to prevent table corruption. - When an engineer explicitly activates **Schema Evolution**, Delta Lake relaxes this barrier for compatible changes. - If the incoming DataFrame contains new columns, Delta Lake automatically amends the table's schema definition in the `_delta_log`, adds the new columns as nullable fields, and populates the existing historical records with `NULL` for the newly introduced columns.

3. Why Other Options Are Incorrect / Distractor Analysis - **A. Schema Enforcement:** Schema enforcement is the default safety mechanism that *blocks* incoming data containing unexpected columns. Enabling strict schema enforcement causes the write to fail, which is the exact opposite of what the engineer wants. - **C. Checkpointing:** Checkpointing persists stream progress offsets and intermediate aggregation state to durable storage. It has no role in modifying Delta table column schemas. - **D. Z-Ordering:** Z-Ordering is a multidimensional data layout clustering technique run during `OPTIMIZE` to collocate related information in Parquet files. It does not evolve table schemas.

4. Architectural & Execution Context / Physical Execution When `mergeSchema = true` is passed: 1. The Delta transaction coordinator compares the source DataFrame schema with the target table schema. 2. If new columns are detected, a schema update action (`metaData`) is generated and written atomically as part of the commit in the `_delta_log/` JSON transaction file. 3. Existing underlying Parquet files are untouched; Delta readers simply project `NULL` for the new column when scanning legacy Parquet files that predate the column addition.

5. Practical Code Example

# Enabling Schema Evolution in PySpark
(new_customers_df.write
    .format("delta")
    .mode("append")
    .option("mergeSchema", "true")
    .saveAsTable("marketing.crm.customers")
)
-- In SQL MERGE statements, enable schema evolution via Spark config
SET spark.databricks.delta.schema.autoMerge.enabled = true;

6. Key Takeaway Schema Enforcement protects your table by default; Schema Evolution allows it to adapt by appending new columns on-demand using `mergeSchema`.

7. Best Practice & Production Recommendation In production pipelines, do not enable `mergeSchema` globally across all jobs. Keep schema enforcement active to catch accidental typos (e.g., `cust_id` vs `customer_id`). Explicitly pass `.option("mergeSchema", "true")` only in ingestion jobs where upstream source providers are known to introduce non-breaking schema additions (such as Auto Loader with `cloudFiles.schemaEvolutionMode = "addNewColumns"`).

8. Real-World Engineering Scenario An e-commerce mobile app released version 4.2, adding an optional `device_os_version` attribute to user telemetry JSON payloads. Downstream Bronze ingestion was configured with Auto Loader and Delta Lake schema evolution. When the new app traffic arrived, Delta Lake automatically added the column to the Bronze table without breaking nightly reporting or requiring emergency engineering on-call interventions.

9. Common Exam Trap / Anti-Pattern / Misconception On the Databricks certification exam, remember that Schema Evolution supports *compatible* changes (adding new columns, relaxing nullability from `NOT NULL` to `NULL`). It does NOT support incompatible changes (such as changing an existing column from `INT` to `STRING` or deleting columns). Incompatible type changes require explicit table migration or column rewriting.

10. Related InsightfulSaga Tutorial Review Delta schema controls in [Delta Lake Core Features and ACID Transactions](/tutorials/databricks/delta-lake-core).

Answered: 0 / 20
Question Navigator (Test 06)0% Answered