A company stores sensor readings in a Delta table. A data engineer needs to add a new column calibration_factor DOUBLE to the table without rewriting existing data files, and all future reads should show NULL for this column in existing rows. Which command achieves this with the LEAST disruption?
- A. ALTER TABLE sensors ADD COLUMN calibration_factor DOUBLE;✓ Correct
- B. df.write.option('mergeSchema', 'true').mode('append').save('/path/to/sensors');
- C. INSERT OVERWRITE sensors SELECT *, NULL AS calibration_factor FROM sensors;
- D. spark.sql("ALTER TABLE sensors SET TBLPROPERTIES ('delta.columnMapping.mode' = 'name')")
Explanation
Option A is correct. ALTER TABLE ... ADD COLUMN is the standard DDL command to add a new column to a Delta table. Delta Lake supports this operation without rewriting existing data files — existing rows will return NULL for the new column when read. This is a metadata-only operation. Option C is wrong — INSERT OVERWRITE rewrites all data, which is unnecessarily disruptive and resource-intensive. Option B is wrong — using mergeSchema with an append write adds the column but also writes new data; it is not appropriate when the goal is simply to add a column without writing any new records. Option D is wrong — setting column mapping mode enables features like column renaming and dropping, but does not itself add a new column; it is a prerequisite step for some schema evolution operations, not the column-addition command itself.