You are transforming data in a Fabric Notebook using PySpark. You need to handle schema evolution when loading data into a Delta table. Which TWO actions should you perform?
Trap 1: Drop the Delta table and recreate it whenever the source schema…
Dropping and recreating tables results in significant data loss and metadata overhead. This approach is highly inefficient and disrupts downstream consumption layers like Power BI or SQL endpoints that rely on the table persistence, making it a poor practice for maintaining robust production-level data engineering pipelines.
Trap 2: Manually alter the table schema using SQL ALTER TABLE commands…
Manual schema modification is error-prone and prevents automation. Data pipelines should be self-healing where possible. Relying on manual intervention creates bottlenecks and increases the risk of human error, which is detrimental to the scalability and reliability goals of a modern Fabric-based data platform.
Trap 3: Convert the Spark DataFrame to JSON format before writing it to the…
Writing as JSON forces a loss of Delta Lake's native optimization features like ACID compliance and schema enforcement. This bypasses the very engine features that make Delta Lake ideal for data transformations, leading to inefficient storage and degraded performance for any subsequent analytical queries performed on the data.
- A
Set the spark.databricks.delta.schema.autoMerge.enabled configuration to true.
Enabling auto-merge allows the Delta table to automatically incorporate new columns that appear in the source data. This configuration is essential for pipelines where downstream schemas are not strictly fixed, ensuring that the ingestion process does not crash when new fields are added to the source datasets.
- B
Use the .option('mergeSchema', 'true') parameter in the DataFrame write operation.
The mergeSchema option specifically tells the Delta writer to reconcile the incoming schema with the existing table schema. This is the programmatic way to trigger evolution per operation, providing developers granular control over when schema changes are applied to the persistent storage layer during notebook execution.
- C
Drop the Delta table and recreate it whenever the source schema changes.
Why wrong: Dropping and recreating tables results in significant data loss and metadata overhead. This approach is highly inefficient and disrupts downstream consumption layers like Power BI or SQL endpoints that rely on the table persistence, making it a poor practice for maintaining robust production-level data engineering pipelines.
- D
Manually alter the table schema using SQL ALTER TABLE commands before every execution.
Why wrong: Manual schema modification is error-prone and prevents automation. Data pipelines should be self-healing where possible. Relying on manual intervention creates bottlenecks and increases the risk of human error, which is detrimental to the scalability and reliability goals of a modern Fabric-based data platform.
- E
Convert the Spark DataFrame to JSON format before writing it to the Delta table.
Why wrong: Writing as JSON forces a loss of Delta Lake's native optimization features like ACID compliance and schema enforcement. This bypasses the very engine features that make Delta Lake ideal for data transformations, leading to inefficient storage and degraded performance for any subsequent analytical queries performed on the data.