Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc: Add a page explaining migration from other table formats to iceberg #6600

Merged
merged 22 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8e6b9a7
add doc for iceberg-delta-lake
JonasJ-ap Jan 16, 2023
65f5888
add compatibility notice for TimestampType
JonasJ-ap Jan 24, 2023
198f389
make the doc the for general table migration
JonasJ-ap Mar 23, 2023
d731a89
refactor table migration doc draft 1
JonasJ-ap Mar 24, 2023
bb9ee84
add terminal graphs
JonasJ-ap Mar 27, 2023
73cc129
adjust web pages alignment
JonasJ-ap Mar 27, 2023
954efda
add pictures link (pictures should be contributed to iceberg-docs ins…
JonasJ-ap Mar 27, 2023
e7f37b3
Re-organize pages and revise contents
JonasJ-ap Mar 31, 2023
0ecbefb
revise delta lake migration page
JonasJ-ap Apr 4, 2023
04c2e91
revise migration introduction and add hive migration page
JonasJ-ap Apr 5, 2023
fd631d2
correct links in these pages
JonasJ-ap Apr 6, 2023
732f306
refactor delta-lake-migration and simplify the description
JonasJ-ap Apr 6, 2023
8960c32
Add link to CTAS, INSERT for full data migration
JonasJ-ap Apr 6, 2023
da2a8c0
add space before each section headers
JonasJ-ap Apr 6, 2023
886930b
remove timestampType read warning since the vectorized support for in…
JonasJ-ap Apr 13, 2023
8b59815
polish delta lake migration part
JonasJ-ap Apr 22, 2023
c2ee4bd
add reader/writer switching description to snapshot/migration steps
JonasJ-ap Apr 22, 2023
7a99342
revise hive migration link
JonasJ-ap Apr 22, 2023
e2a1f37
fix code examples in delta lake migration
JonasJ-ap Apr 22, 2023
5c31585
address final comments
JonasJ-ap Apr 22, 2023
ac462fa
updates link
JonasJ-ap Apr 22, 2023
436dd2d
finalize code example
JonasJ-ap Apr 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions docs/delta-lake-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "Delta Lake Migration"
url: delta-lake-migration
menu:
main:
parent: "Migration"
weight: 300
---
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->

# Delta Lake Table Migration
jackye1995 marked this conversation as resolved.
Show resolved Hide resolved
Delta Lake is a table format that supports Parquet file format and provides time travel and versioning features. When migrating data from Delta Lake to Iceberg,
it is common to migrate all snapshots to maintain the history of the data.

Currently, Iceberg supports the Snapshot Table action for migrating from Delta Lake to Iceberg tables.
Since Delta Lake tables maintain transactions, all available transactions will be committed to the new Iceberg table as transactions in order.
For Delta Lake tables, any additional data files added after the initial migration will be included in their corresponding transactions and subsequently added to the new Iceberg table using the Add Transaction action.
The Add Transaction action, a variant of the Add File action, is still under development.

## Enabling Migration from Delta Lake to Iceberg
The `iceberg-delta-lake` module is not bundled with Spark and Flink engine runtimes. To enable migration from delta lake features, the minimum required dependencies are:
- [iceberg-delta-lake](https://repo1.maven.org/maven2/org/apache/iceberg/iceberg-delta-lake/1.2.1/iceberg-delta-lake-1.2.1.jar)
- [delta-standalone-0.6.0](https://repo1.maven.org/maven2/io/delta/delta-standalone_2.13/0.6.0/delta-standalone_2.13-0.6.0.jar)
- [delta-storage-2.2.0](https://repo1.maven.org/maven2/io/delta/delta-storage/2.2.0/delta-storage-2.2.0.jar)

### Compatibilities
The module is built and tested with `Delta Standalone:0.6.0` and supports Delta Lake tables with the following protocol version:
* `minReaderVersion`: 1
* `minWriterVersion`: 2

Please refer to [Delta Lake Table Protocol Versioning](https://docs.delta.io/latest/versioning.html) for more details about Delta Lake protocol versions.

### API
The `iceberg-delta-lake` module provides an interface named `DeltaLakeToIcebergMigrationActionsProvider`, which contains actions that helps converting from Delta Lake to Iceberg.
The supported actions are:
* `snapshotDeltaLakeTable`: snapshot an existing Delta Lake table to an Iceberg table

### Default Implementation
The `iceberg-delta-lake` module also provides a default implementation of the interface which can be accessed by
```java
DeltaLakeToIcebergMigrationActionsProvider defaultActions = DeltaLakeToIcebergMigrationActionsProvider.defaultActions()
```

## Snapshot Delta Lake Table to Iceberg
The action `snapshotDeltaLakeTable` reads the Delta Lake table's transactions and converts them to a new Iceberg table with the same schema and partitioning in one iceberg transaction.
The original Delta Lake table remains unchanged.

The newly created table can be changed or written to without affecting the source table, but the snapshot uses the original table's data files.
Existing data files are added to the Iceberg table's metadata and can be read using a name-to-id mapping created from the original table schema.

When inserts or overwrites run on the snapshot, new files are placed in the snapshot table's location. The location is default to be the same as that
of the source Delta Lake Table. Users can also specify a different location for the snapshot table.

{{< hint info >}}
Because tables created by `snapshotDeltaLakeTable` are not the sole owners of their data files, they are prohibited from
actions like `expire_snapshots` which would physically delete data files. Iceberg deletes, which only effect metadata,
are still allowed. In addition, any operations which affect the original data files will disrupt the Snapshot's
integrity. DELETE statements executed against the original Delta Lake table will remove original data files and the
`snapshotDeltaLakeTable` table will no longer be able to access them.
{{< /hint >}}

#### Usage
| Required Input | Configured By | Description |
|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| Source Table Location | Argument [`sourceTableLocation`](https://iceberg.apache.org/javadoc/latest/org/apache/iceberg/delta/DeltaLakeToIcebergMigrationActionsProvider.html#snapshotDeltaLakeTable(java.lang.String)) | The location of the source Delta Lake table |
| New Iceberg Table Identifier | Configuration API [`as`](https://iceberg.apache.org/javadoc/latest/org/apache/iceberg/delta/SnapshotDeltaLakeTable.html#as(org.apache.iceberg.catalog.TableIdentifier)) | The identifier specifies the namespace and table name for the new iceberg table |
| Iceberg Catalog | Configuration API [`icebergCatalog`](https://iceberg.apache.org/javadoc/latest/org/apache/iceberg/delta/SnapshotDeltaLakeTable.html#icebergCatalog(org.apache.iceberg.catalog.Catalog)) | The catalog used to create the new iceberg table |
| Hadoop Configuration | Configuration API [`deltaLakeConfiguration`](https://iceberg.apache.org/javadoc/latest/org/apache/iceberg/delta/SnapshotDeltaLakeTable.html#deltaLakeConfiguration(org.apache.hadoop.conf.Configuration)) | The Hadoop Configuration used to read the source Delta Lake table. |

For detailed usage and other optional configurations, please refer to the [SnapshotDeltaLakeTable API](https://iceberg.apache.org/javadoc/latest/org/apache/iceberg/delta/SnapshotDeltaLakeTable.html)

#### Output
| Output Name | Type | Description |
| ------------|------|-------------|
| `imported_files_count` | long | Number of files added to the new table |

#### Added Table Properties
The following table properties are added to the Iceberg table to be created by default:

| Property Name | Value | Description |
|-------------------------------|-------------------------------------------|--------------------------------------------------------------------|
| `snapshot_source` | `delta` | Indicates that the table is snapshot from a delta lake table |
| `original_location` | location of the delta lake table | The absolute path to the location of the original delta lake table |
| `schema.name-mapping.default` | JSON name mapping derived from the schema | The name mapping string used to read Delta Lake table's data files |

#### Examples
```java
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.catalog.Catalog;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.delta.DeltaLakeToIcebergMigrationActionsProvider;

String sourceDeltaLakeTableLocation = "s3://my-bucket/delta-table";
String destTableLocation = "s3://my-bucket/iceberg-table";
TableIdentifier destTableIdentifier = TableIdentifier.of("my_db", "my_table");
Catalog icebergCatalog = ...; // Iceberg Catalog fetched from engines like Spark or created via CatalogUtil.loadCatalog
Configuration hadoopConf = ...; // Hadoop Configuration fetched from engines like Spark and have proper file system configuration to access the Delta Lake table.

DeltaLakeToIcebergMigrationActionsProvider.defaultActions()
.snapshotDeltaLakeTable(sourceDeltaLakeTableLocation)
.as(destTableIdentifier)
.icebergCatalog(icebergCatalog)
.tableLocation(destTableLocation)
.deltaLakeConfiguration(hadoopConf)
.tableProperty("my_property", "my_value")
.execute();
```
60 changes: 60 additions & 0 deletions docs/hive-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: "Hive Migration"
url: hive-migration
menu:
main:
parent: "Migration"
weight: 200
---
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->

# Hive Table Migration
Apache Hive supports ORC, Parquet, and Avro file formats that could be migrated to Iceberg.
When migrating data to an Iceberg table, which provides versioning and transactional updates, only the most recent data files need to be migrated.

Iceberg supports all three migration actions: Snapshot Table, Migrate Table, and Add Files for migrating from Hive tables to Iceberg tables. Since Hive tables do not maintain snapshots,
the migration process essentially involves creating a new Iceberg table with the existing schema and committing all data files across all partitions to the new Iceberg table.
After the initial migration, any new data files are added to the new Iceberg table using the Add Files action.

## Enabling Migration from Hive to Iceberg
The Hive table migration actions are supported by the Spark Integration module via Spark Procedures.
The procedures are bundled in the Spark runtime jar, which is available in the [Iceberg Release Downloads](https://iceberg.apache.org/releases/#downloads).

## Snapshot Hive Table to Iceberg
To snapshot a Hive table, users can run the following Spark SQL:
```sql
CALL catalog_name.system.snapshot('db.source', 'db.dest')
```
See [Spark Procedure: snapshot](../spark-procedures/#snapshot) for more details.

## Migrate Hive Table To Iceberg
To migrate a Hive table to Iceberg, users can run the following Spark SQL:
```sql
CALL catalog_name.system.migrate('db.sample')
```
See [Spark Procedure: migrate](../spark-procedures/#migrate) for more details.

## Add Files From Delta Lake Table to Iceberg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say hive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Thank you for catching this. Sorry for the typo.

Have opened a new PR here: #7407, to address that.

To add data files from a Hive table to a given Iceberg table, users can run the following Spark SQL:
```sql
CALL spark_catalog.system.add_files(
table => 'db.tbl',
source_table => 'db.src_tbl'
)
```
See [Spark Procedure: add_files](../spark-procedures/#add_files) for more details.
79 changes: 79 additions & 0 deletions docs/table-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: "Overview"
url: table-migration
menu:
main:
parent: "Migration"
weight: 100
---
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->

# Table Migration
Apache Iceberg supports converting existing tables in other formats to Iceberg tables. This section introduces the general concept of table migration, its approaches, and existing implementations in Iceberg.

## Migration Approaches
There are two methods for executing table migration: full data migration and in-place metadata migration.

Full data migration involves copying all data files from the source table to the new Iceberg table. This method makes the new table fully isolated from the source table, but is slower and doubles the space.
In practice, users can use operations like [Create-Table-As-Select](../spark-ddl/#create-table--as-select), [INSERT](../spark-writes/#insert-into), and Change-Data-Capture pipelines to perform such migration.

In-place metadata migration preserves the existing data files while incorporating Iceberg metadata on top of them.
This method is not only faster but also eliminates the need for data duplication. However, the new table and the source table are not fully isolated. In other words, if any processes vacuum data files from the source table, the new table will also be affected.

In this doc, we will describe more about in-place metadata migration.

![In-Place Metadata Migration](../../../img/iceberg-in-place-metadata-migration.png)

Apache Iceberg supports the in-place metadata migration approach, which includes three important actions: **Snapshot Table**, **Migrate Table**, and **Add Files**.

## Snapshot Table
The Snapshot Table action creates a new iceberg table with a different name and with the same schema and partitioning as the source table, leaving the source table unchanged during and after the action.

- Create a new Iceberg table with the same metadata (schema, partition spec, etc.) as the source table and a different name. Readers and Writers on the source table can continue to work.

![Snapshot Table Step 1](../../../img/iceberg-snapshotaction-step1.png)

- Commit all data files across all partitions to the new Iceberg table. The source table remains unchanged. Readers can be switched to the new Iceberg table.

![Snapshot Table Step 2](../../../img/iceberg-snapshotaction-step2.png)
jackye1995 marked this conversation as resolved.
Show resolved Hide resolved

- Eventually, all writers can be switched to the new Iceberg table. Once all writers are transitioned to the new Iceberg table, the migration process will be considered complete.

## Migrate Table
JonasJ-ap marked this conversation as resolved.
Show resolved Hide resolved
The Migrate Table action also creates a new Iceberg table with the same schema and partitioning as the source table. However, during the action execution, it locks and drops the source table from the catalog.
Consequently, Migrate Table requires all modifications working on the source table to be stopped before the action is performed.

Stop all writers interacting with the source table. Readers that also support Iceberg may continue reading.

![Migrate Table Step 1](../../../img/iceberg-migrateaction-step1.png)

JonasJ-ap marked this conversation as resolved.
Show resolved Hide resolved
- Create a new Iceberg table with the same identifier and metadata (schema, partition spec, etc.) as the source table. Rename the source table for a backup in case of failure and rollback.

![Migrate Table Step 2](../../../img/iceberg-migrateaction-step2.png)

- Commit all data files across all partitions to the new Iceberg table. Drop the source table. Writers can start writing to the new Iceberg table.

![Migrate Table Step 3](../../../img/iceberg-migrateaction-step3.png)

## Add Files
After the initial step (either Snapshot Table or Migrate Table), it is common to find some data files that have not been migrated. These files often originate from concurrent writers who continue writing to the source table during or after the migration process.
In practice, these files can be new data files in Hive tables or new snapshots (versions) of Delta Lake tables. The Add Files action is essential for incorporating these files into the Iceberg table.

# Migrating From Different Table Formats
jackye1995 marked this conversation as resolved.
Show resolved Hide resolved
* [From Hive to Iceberg](../hive-migration)
* [From Delta Lake to Iceberg](../delta-lake-migration)