Hive schema evolution rollback safety after ALTER TABLE changes
0 reputation · 17 May 2024, 11:16 UTC
0 reputation · 17 May 2024, 11:16 UTC
After an ALTER TABLE ... CHANGE, ADD, or DROP COLUMN, the Hive metastore immediately records the new column definitions while the underlying data files remain unchanged, creating a schema‑metadata mismatch.
The objective is to provide a safe rollback that restores both metadata and data to a consistent state without manual re‑creation of the table or re‑loading of files. Current Hive behavior lacks built‑in transactional undo for DDL operations, and rolling back only the metastore can leave files misaligned, causing query failures or compilation errors; assessing consistency involves checking DESCRIBE FORMATTED before and after the change and reviewing event logs for missing ROLLBACK entries. Is there a supported atomic rollback mechanism for Hive DDL? Can Hive transactions be extended to encompass DDL so that COMMIT/ROLLBACK safely reverses both metadata and data? What is the recommended procedure to guarantee consistency when rolling back after a schema modification?
35775 reputation · 17 May 2024, 22:36 UTC
Hive does not provide a supported atomic rollback mechanism for DDL statements such as ALTER TABLE ... CHANGE, ADD, or DROP COLUMN. Hive transactions can only roll back DML (INSERT, UPDATE, DELETE); DDL changes are committed to the metastore immediately and cannot be undone by a transaction rollback.
The metastore is updated instantly after the ALTER, while the underlying data files stay unchanged, creating a schema‑metadata mismatch.
DESCRIBE FORMATTED <table> and save the output. This captures the pre‑change metastore state.ls -l $TABLE_LOCATION). Unchanged files confirm the metadata‑only shift.DROP TABLE <table>.LOCATION:
CREATE TABLE <table> LIKE <table> STORED AS <storage_format> LOCATION '<original_path>';
MSCK REPAIR TABLE <table> to reconcile any stale partition metadata.ALTER TABLE <table> RECOVER PARTITIONS (available in newer Hive versions) to re‑attach the original partitions.Please confirm whether the target table is ACID‑managed. The rollback steps differ based on this property, and the recommendation above assumes a non‑ACID table.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.