guide
guide9 min read

How to run a hive to iceberg migration: step-by-step with an agent-run cutover

Six steps from Hive inventory to a reversible Iceberg cutover, with an agent doing the repetitive work

The fastest safe way to migrate Hive tables to Apache Iceberg is to use the Spark procedures documented in the Apache Iceberg Hive migration guide: snapshot a table to test it, migrate it in place when you are ready, or add_files to bring existing data files into a table you built yourself. The data files usually stay where they are, because Iceberg adds a metadata layer over them. The hard part of a hive to iceberg migration is everything around the procedure: inventory, validation, reader cutover and rollback. This post walks through all six steps and marks which ones an agent can run.

Key Takeaways

  • •Iceberg's Spark procedures (snapshot, migrate, add_files) can adopt existing Parquet, ORC and Avro files without rewriting them, per the Iceberg Spark procedures docs.
  • •Use snapshot to rehearse, migrate for in-place conversion, and add_files when you want a new partition layout.
  • •Validation (row counts, aggregates, schema) is the step teams skip, and it is the one that makes the cutover reversible.
  • •Readers are the real migration surface: every job, dashboard and notebook that touches the Hive table needs a cutover plan.
  • •An agent can run the inventory, rehearsal and validation steps. We think a human should still approve the cutover and the drop of the backup.

What you decide before a hive to iceberg migration starts

Three decisions shape the rest of the work, and we would make them before touching a table. First, in place or side by side. Second, whether to keep your current partition layout or move to Iceberg's hidden partitioning. Third, which catalog will own the tables afterwards. The table below maps the three Iceberg procedures to the situations they fit.

ProcedureWhat it doesSource table afterwardsBest for
snapshotCreates a new Iceberg table that points at the source table's data filesUnchangedRehearsals and read-only validation
migrateReplaces the source table with an Iceberg table in the same catalog and keeps a backup tableKept as a backup by defaultIn-place conversion of tables you can briefly freeze
add_filesAdds existing data files to an Iceberg table you createdUnchangedNew partition spec or schema, or incremental backfill

Per the Iceberg docs, migrate needs a Spark session catalog wrapped with Iceberg's SparkSessionCatalog, and the source files must be in a format Iceberg supports (Parquet, ORC or Avro). If part of your estate is text or CSV, plan to rewrite those tables with CTAS instead. The procedures are the same whether a person or an agent calls them. What changes is who does the repetitive checking.

Step 1: Inventory every Hive table and its readers

List every table in the Hive metastore with its format, partition columns, size, last-modified time and owner. Then list the readers: scheduled jobs, BI dashboards, notebooks and downstream tables. A table with no readers in 90 days is a candidate to archive instead of migrate. In Claude Code or Cursor you can ask an MCP-connected agent directly: "What tables haven't been queried in 90 days?" and "What's the blast radius if I change this table?" Our Migration Agent runs this inventory, groups tables into waves by dependency, and flags tables in unsupported formats. We covered how the lineage behind that grouping stays current in a separate post on our Catalog Agent.

Output of this step: a wave plan. Wave one is leaf tables with few readers. The last wave is the central tables everything joins to.

Step 2: Rehearse with the snapshot procedure

Run snapshot against a wave-one table before changing anything. The call looks like CALL catalog.system.snapshot('db.orders', 'db.orders_iceberg_test'). It creates an Iceberg table over the same data files and leaves the Hive table untouched, so you can run real queries against it. The Iceberg docs position snapshot as a way to try Iceberg without committing to the migration, so treat the result as a rehearsal table, not as a production one. Do not run file-deleting maintenance such as expire_snapshots or orphan-file cleanup on it while the source table still exists.

What to look for: queries that fail on column types, partition columns stored in unusual ways, and tables where the metastore schema disagrees with the file schema. The Schema Agent compares both schemas column by column and reports drift before you hit it in production.

Step 3: Choose in-place migrate or add_files

If the current partition layout is fine and you can pause writers briefly, use migrate: CALL catalog.system.migrate('db.orders'). By default it keeps the original table as a backup named with a _BACKUP_ suffix, which is the rollback path. Leave the drop_backup option at its default until validation is finished.

If the Hive layout is the problem (for example, over-partitioned by day and hour, producing many small files), create a new Iceberg table with the partition spec you want, then use add_files to register the existing files, and let a later compaction job rewrite them. Iceberg's hidden partitioning means queries no longer need to filter on a separate partition column, which is one of the reasons teams migrate at all. Our opinion: use add_files for your largest, most-queried tables, because the migration is your one cheap chance to fix the layout.

Step 4: Validate before any reader moves

Validation should be mechanical and repeatable. For each migrated table, compare against the Hive original or backup:

  • •Row counts, in total and per partition.
  • •Aggregates on numeric columns (sums, min, max) and distinct counts on key columns.
  • •Schema: column names, types and nullability.
  • •Sample reads through every engine that will read the table, not only Spark.

Questions like "Why did row counts drop 40% overnight?" or "Is the customer_id join safe after the migration?" are the ones you want answered before the cutover, not after it. This is the step where an agent saves the most time, because the same checks run across hundreds of tables and the results are easy to diff. Claude Code can run these checks through MCP servers from your terminal; see the Claude Code documentation for how MCP servers are configured, and the MCP specification for the protocol itself.

Step 5: Cut over readers wave by wave

With the tables validated, move readers. Update catalog configuration in each engine, change table references where the name changed, and run each reader against the Iceberg table in parallel with the old path for at least one full schedule cycle. Writers go last, because an Iceberg table that is also being written through the old Hive path will diverge. Freeze the old writer, run migrate or a final add_files for the delta, validate again, then enable the new writer.

We would keep one rule here: the agent proposes each cutover as a diff (jobs touched, configs changed, validation results), and a person approves it. In Data Workers, the OSS edition (dw-claw) is read-only by default, so inventory, rehearsal and validation work with no write access. Writes and approval workflows arrive with Pro, where an audit trail records who approved which cutover. Our Autonomous Data Conductor can run later waves with a per-domain autonomy dial once the first waves have proven the process.

Step 6: Compact, expire and retire the backup

After a stable period, the cleanup begins. Run compaction with the rewrite_data_files procedure to fix small files, then expire old snapshots on a schedule so metadata does not grow without bound. Only then drop the Hive backup tables. Dropping a backup early is the one irreversible mistake in this process, so make it a separate, explicit approval and not part of the cutover.

Finish by recording the new state: owners, freshness expectations and lineage for each Iceberg table. If the catalog is the product of this migration, it should be accurate on day one. Our Migration Agent writes this metadata as it goes, so the catalog does not lag behind the platform.

What goes wrong in a hive to iceberg migration

  • •Readers nobody knew about. A forgotten notebook or export job still points at the Hive table. Inventory from query logs, not from documentation.
  • •Writers running during migrate. Pause them first or you risk losing the delta.
  • •Engine support gaps. A table that validates in Spark may behave differently in another engine's Iceberg connector. Test every engine.
  • •Early backup deletion. Keep the backup until the validation window is over.
  • •Treating the move as a one-day event. For a large estate, it is a series of waves over weeks.

Frequently Asked Questions

Do I have to rewrite my data to migrate from Hive to Iceberg? Not for Parquet, ORC or Avro tables. The snapshot, migrate and add_files procedures register existing files in Iceberg metadata. You rewrite data later, if you want a better layout, with compaction. Text and CSV tables need a rewrite.

Can I roll back a migration? Yes, if you keep the backup. migrate retains the original table as a backup by default, and snapshot and add_files never alter the source. Rollback is only hard after you drop the backup or after writers have moved to the Iceberg table and the Hive copy has gone stale.

Should I use migrate or add_files? Use migrate when the current partitioning is acceptable and you can pause writers. Use add_files when you want a different partition spec or schema. For a large, frequently queried table we lean toward add_files, because it lets you correct the layout at the same time.

What can an AI agent safely do in this process? In our view: inventory, dependency grouping, rehearsal, validation and reporting. Those steps are read-only and repeatable. Cutover and backup deletion are writes with business impact, so they belong behind approval, at least until the earlier waves have succeeded.

Do I need Data Workers to migrate? No. The Iceberg procedures work with any Spark setup, and the steps above can be run by hand. Data Workers helps by running the repetitive steps through MCP from Claude Code, Cursor or any MCP-compatible client, and by keeping the evidence of each step.