Lab Cheat Sheet

Want to…Statement
Create a namespaceCREATE NAMESPACE IF NOT EXISTS hms.db — required with HMS, implicit with type=hadoop
Create a tableCREATE TABLE hms.db.t (...) USING iceberg PARTITIONED BY (days(ts))
Write rowsINSERT INTO hms.db.t VALUES (...) / INSERT INTO ... SELECT ...
UpsertMERGE INTO hms.db.t t USING src s ON ... WHEN MATCHED ... WHEN NOT MATCHED ...
See commit historySELECT * FROM hms.db.t.history
See every snapshotSELECT * FROM hms.db.t.snapshots
See manifest filesSELECT * FROM hms.db.t.manifests
See data + delete filesSELECT * FROM hms.db.t.files — content: 0=data, 1=pos-delete, 2=eq-delete
See what a delete file actually deletesSELECT file_path, pos FROM hms.db.t.position_deletes — one row per superseded row (see What is actually inside the delete file)
See partitions across specsSELECT * FROM hms.db.t.partitions
Time travel by snapshotSELECT * FROM hms.db.t VERSION AS OF <id>
Time travel by timestampSELECT * FROM hms.db.t TIMESTAMP AS OF '<ts>'
Roll backCALL hms.system.rollback_to_snapshot('db.t', <id>)
Roll forwardCALL hms.system.set_current_snapshot('db.t', <id>)
Add/rename/widen/drop a columnALTER TABLE hms.db.t ADD/RENAME/ALTER/DROP COLUMN ...
Change partitioning going forwardALTER TABLE hms.db.t ADD/DROP PARTITION FIELD <transform>(col)
Stop a MERGE emitting small filesALTER TABLE hms.db.t SET TBLPROPERTIES ('write.distribution-mode'='hash') (see Isn't three files a lot for two rows?)
Compact small files + resolve deletesCALL hms.system.rewrite_data_files(table => 'db.t')
Compact manifestsCALL hms.system.rewrite_manifests('db.t')
Reclaim disk spaceCALL hms.system.expire_snapshots(table => 'db.t', older_than => ..., retain_last => N)
Clean up abandoned filesCALL hms.system.remove_orphan_files(table => 'db.t')
Find the live metadata.jsonSELECT file FROM hms.db.t.metadata_log_entries ORDER BY timestamp DESC LIMIT 1
See the pointer in PostgresSELECT "PARAM_VALUE" FROM "TABLE_PARAMS" … WHERE "PARAM_KEY" = 'metadata_location'
Pin the session timezoneSET spark.sql.session.timeZone = 'UTC' — set it in cluster defaults, not per job (see The end-to-end contract: convert at the edges, never in the middle)
Get a wall-clock column, not an instantdeclare it TIMESTAMP_NTZ — plain TIMESTAMP yields Iceberg timestamptz (see Read metadata.json straight, in Go, timestamptz does not store a timezone)
Swap lock for CASALTER TABLE hms.db.t SET TBLPROPERTIES ('engine.hive.lock-enabled' = 'false') — HMS 4.0.0+ only