MigrateTable
TheMigrateTable action migrates an existing non-Iceberg table to Iceberg format. This enables existing tables to leverage Iceberg’s features like time travel, schema evolution, and ACID transactions.
Interface
Overview
Migrating a table to Iceberg involves:- Reading the existing table metadata
- Converting the schema and partition specification
- Creating Iceberg metadata files
- Preserving the original data files (no data rewrite required)
- Optionally creating a backup of the original table
Methods
tableProperties
Sets multiple table properties in the newly created Iceberg table.properties- A map of property key-value pairs to set
this for method chaining
Example:
Properties with the same key will be overwritten by later calls.
tableProperty
Sets a single table property in the newly created Iceberg table.name- The property namevalue- The property value
this for method chaining
Example:
dropBackup
Drops the backup of the original table after a successful migration.this for method chaining
Example:
backupTableName
Sets a custom table name for the backup of the original table.tableName- The name to use for the backup table
this for method chaining
Example:
executeWith
Sets an executor service for parallel file reading during migration.service- The executor service to use
this for method chaining
Example:
By default, migration does not use an executor service and processes files sequentially.
Result
TheResult interface provides statistics about the migration operation.
Methods
migratedDataFilesCount
Returns the number of data files that were migrated to Iceberg. Returns:long - Number of migrated data files
Usage Examples
Basic Table Migration
Migration with Table Properties
Migration with Multiple Properties
Migration with Custom Backup Name
Migration Without Backup
Parallel Migration for Large Tables
Complete Migration Workflow
Best Practices
- Test in development first: Migrate a copy of the table in a non-production environment
-
Keep backups initially: Don’t use
dropBackup()until you’ve verified the migration - Set appropriate properties: Configure Iceberg properties for your workload during migration
- Use parallel execution for large tables: Enable parallelism for tables with many files
- Verify after migration: Check schema, partitioning, and data integrity after migration
- Plan for downtime: Coordinate with users as the table may be briefly unavailable
Migration is a metadata-only operation and doesn’t rewrite data files, making it fast even for large tables.
Migration Checklist
Before migrating:- Backup the original table metadata
- Verify table schema compatibility
- Plan for table downtime window
- Test migration in development environment
- Prepare rollback procedure
- Verify table is readable
- Check snapshot and metadata
- Validate row counts
- Test query performance
- Update applications to use new table
Supported Table Formats
The specific table formats that can be migrated depend on the implementation:- Spark: Hive tables, Delta Lake tables
- Flink: Hive tables
- Other engines: Consult documentation for supported formats
Related
- SnapshotTable - Create an independent snapshot of a table
- RewriteDataFiles - Optimize data layout after migration
- ComputeTableStats - Compute statistics for the migrated table