-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Docs: Add rewrite-table-path in spark procedure #12115
Open
dramaticlly
wants to merge
11
commits into
apache:main
Choose a base branch
from
dramaticlly:rewrite-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
662fb2b
Docs: Add rewrite-table-path in spark procedure
dramaticlly 3e94922
Address russell and yufei feedback
dramaticlly 149537d
Address russell and prashant feedback
dramaticlly 772d568
Apply suggestions from Russell
dramaticlly cd491ff
Apply suggestions from Russell
dramaticlly 819ed73
Remove extra between
dramaticlly 09694d2
Address szehon feedback on doc
dramaticlly ae9cbf5
Fix all periods
dramaticlly 6e81f40
Update docs/docs/spark-procedures.md
dramaticlly b09d4a3
Update warning for partition statistics files
dramaticlly e77d8b0
Copying/moving
dramaticlly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -972,4 +972,100 @@ CALL catalog_name.system.compute_table_stats(table => 'my_table', snapshot_id => | |
Collect statistics of the snapshot with id `snap1` of table `my_table` for columns `col1` and `col2` | ||
```sql | ||
CALL catalog_name.system.compute_table_stats(table => 'my_table', snapshot_id => 'snap1', columns => array('col1', 'col2')); | ||
``` | ||
``` | ||
|
||
## Table Replication | ||
|
||
The `rewrite-table-path` procedure prepares an Iceberg table for moving or copying to another location. | ||
|
||
### `rewrite-table-path` | ||
|
||
Stages a copy of the Iceberg table's metadata files where every absolute path source prefix is replaced by the specified target prefix. | ||
This can be the starting point to fully or incrementally copy an Iceberg table located under an absolute path under a | ||
source prefix to another under the target prefix. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "under an absolute path under a source prefix to another under the target prefix." is not easy to grok. |
||
|
||
!!! info | ||
This procedure only prepares metadata for an existing Iceberg table for a copy or move to a new location. | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Copying/Moving metadata and data files to the new location is not part of this procedure. | ||
|
||
|
||
| Argument Name | Required? | default | Type | Description | | ||
|--------------------|-----------|------------------------------------------------|--------|-------------------------------------------------------------------------| | ||
| `table` | ✔️ | | string | Name of the table | | ||
| `source_prefix` | ✔️ | | string | The existing prefix to be replaced | | ||
| `target_prefix` | ✔️ | | string | The replacement prefix for `source_prefix` | | ||
| `start_version` | | first metadata.json in table's metadata log | string | The name or path to the chronologically first metadata.json to rewrite | | ||
| `end_version` | | latest metadata.json | string | The name or path to the chronologically last metadata.json to rewrite | | ||
| `staging_location` | | new directory under table's metadata directory | string | The output location for newly modified metadata files | | ||
|
||
|
||
#### Modes of operation: | ||
|
||
- Full Rewrite: | ||
|
||
By default, the procedure operates in full rewrite mode, rewriting all reachable metadata files. This includes metadata.json, manifest lists, manifests, and position delete files. | ||
|
||
- Incremental Rewrite: | ||
|
||
If `start_version` is provided, the procedure will only rewrite metadata files created between `start_version` and `end_version`. `end_version` defaults to the latest metadata.json of the table. | ||
|
||
#### Output | ||
|
||
| Output Name | Type | Description | | ||
|----------------------|--------|-------------------------------------------------------------------------------------| | ||
| `latest_version` | string | Name of the latest metadata file rewritten by this procedure | | ||
| `file_list_location` | string | Path to a file containing a listing of comma-separated source and destination paths | | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
##### File List Copy Plan | ||
The file list contains the copy plan for all files added to the table between `startVersion` and `endVersion`. | ||
For each file, it specifies | ||
|
||
- Source Path: | ||
The original file path in the table, or the staging location if the file has been rewritten. | ||
|
||
- Target Path: | ||
The path with the replacement prefix. | ||
|
||
The following example shows a copy plan for three files: | ||
|
||
```csv | ||
sourcepath/datafile1.parquet,targetpath/datafile1.parquet | ||
sourcepath/datafile2.parquet,targetpath/datafile2.parquet | ||
stagingpath/manifest.avro,targetpath/manifest.avro | ||
``` | ||
|
||
#### Examples | ||
|
||
Full rewrite of a table's path from source location in HDFS to a target location in S3 bucket of table `my_table`. | ||
This produces a new set of metadata using the s3a prefix in the default staging location under table's metadata directory. | ||
|
||
```sql | ||
CALL catalog_name.system.rewrite_table_path( | ||
table => 'db.my_table', | ||
source_prefix => "hdfs://nn:8020/path/to/source_table", | ||
target_prefix => "s3a://bucket/prefix/db.db/my_table" | ||
); | ||
``` | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Incremental rewrite of a table's path from a source location to a target location between metadata versions | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`v2.metadata.json` and `v20.metadata.json`, with files written to an explicit staging location. | ||
|
||
```sql | ||
CALL catalog_name.system.rewrite_table_path( | ||
table => 'db.my_table', | ||
source_prefix => "s3a://bucketOne/prefix/db.db/my_table", | ||
target_prefix => "s3a://bucketTwo/prefix/db.db/my_table", | ||
start_version => "v2.metadata.json", | ||
end_version => "v20.metadata.json", | ||
staging_location => "s3a://bucketStaging/my_table" | ||
); | ||
``` | ||
|
||
Once the rewrite is completed, third-party tools ( | ||
eg. [Distcp](https://hadoop.apache.org/docs/current/hadoop-distcp/DistCp.html)) can be used to copy the newly created | ||
metadata files and data files to the target location. | ||
|
||
Lastly, [register_table](#register_table) procedure can be used to register copied table in the target location with catalog. | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
!!! warning | ||
Iceberg table with statistics files are not currently supported for path rewrite. | ||
dramaticlly marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we achieve moving with this procedure?