-
Notifications
You must be signed in to change notification settings - Fork 3k
Spark: Add RewriteTablePath action interface #10920
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
Spark: Add RewriteTablePath action interface #10920
Conversation
|
Does everyone agree that CopyTable is a good name for this action? Since it's just rewriting metadata, manifest and position delete files with the new location prefix and not actually copying the table, maybe it's better to name it something more specific like |
Isn't an implementation of this interface actually copying the table? |
There is an explanation in the original PR that explains the functionality of this action |
NO. I think it makes sense to go with a name like |
|
I'm a bit lost in the context. If I run this action without copying the table (e.g. rewrite |
@manuzhang Not really, since the rewritten files are stored in a staging directory, when you copy the new table to the new location you copy all the data files + the rewritten metadata files from the staging location and ignore the old metadata files. So the table in the old location will not be corrupted 👍 |
api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java
Outdated
Show resolved
Hide resolved
|
|
||
| import org.apache.iceberg.Table; | ||
|
|
||
| public interface RewriteTableLocation extends Action<RewriteTableLocation, RewriteTableLocation.Result> { |
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.
I'd try to avoid using the name TableLocation, which is a dedicated name for the location of the table as a table property. Given the action is to rewrite the file paths within all metadata files, is rewriteFilePath more suitable?
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.
To be more specific, it's rewriteMetadataFilePath?
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.
Mostly in metadata files. I think it has to touch position/eq delete files as well as they have the absolute file paths as well.
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.
@flyrain Yes it does modify position files as well. RewriteFilePath implies that the method rewrites a single file. Maybe RewriteTablePath?
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.
Yeah, the path rewritten could be a directory as well. I think RewriteTablePath is fine, other alternative cuold be RewriteAbsolutePath or Just RewritePath.
|
@amogh-jahagirdar @nastra, @anuragmantri, you may be interested as well. |
| * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath endVersion(String endVersion); |
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.
endVersion is not clear. What do you think about copyVersion?
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.
We can use copyVersion if only a single version will be rewritten by the script, however the original implementation included functionality to rewrite all version between lastCopiedVersion and endVersion
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 about:
Last metadata version to copy, identified by name of a metadata.json file in the table's metadata log. This action will rewrite all metadata files added before this, up to this file itself.
Can we not support HadoopFileIO initially, so we can simplify definition of the argument?
| RewriteTablePath stagingLocation(String stagingLocation); | ||
|
|
||
| /** | ||
| * Set the target table. It is optional if the start version is provided. |
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.
What is start version here? Could you clarify where start version is provided?
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.
Start version is the same as lastCopiedVersion, maybe we should name them as startVersion and endVersion, or remove this and always rewrite the paths for the full table. @flyrain Do you remember why you added such a feature?
| } | ||
|
|
||
| @Override | ||
| public String dataFileListLocation() { |
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.
Nit: Should we clarify more by renaming them targetDataLocation, targetMetadataLocation and copiedVersion ?
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.
These are the location for a .txt list of files (data/metadata) to copy, so I don't think the suggested names are suitable for them
core/src/main/java/org/apache/iceberg/actions/BaseRewriteTablePathActionResult.java
Outdated
Show resolved
Hide resolved
…into add-copy-table-action-interface # Conflicts: # api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java
core/src/main/java/org/apache/iceberg/actions/BaseRewriteTablePath.java
Outdated
Show resolved
Hide resolved
…Path.java Fix typo Co-authored-by: Eduard Tudenhoefner <etudenhoefner@gmail.com>
|
Hello @nastra @anuragmantri! What's left to merge this PR? |
… into add-copy-table-action-interface
|
@nastra can you rerun the workflows please? I fixed a formatting error |
The formatting error seems to still exist |
Should be ok now. Can you rerun again? |
|
Hey @nastra @manuzhang @anuragmantri @flyrain! Can we merge this now? |
flyrain
left a comment
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.
Thanks @laithalzyoud for working on it. LGTM. Left one minor question.
szehon-ho
left a comment
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.
Hi, @laithalzyoud and @flyrain . I think the Action is valuable but a bit confusing at first glance to user. I took a look and left some comments to try to make it cleaner.
| this.getClass().getName() + " does not implement computeTableStats"); | ||
| } | ||
|
|
||
| /** Instantiates an action to rewrite table files absolute path. */ |
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.
It does not seem like a correct sentence, what do you think of: 'rewrite all absolute paths in table metadata'?
| public interface RewriteTablePath extends Action<RewriteTablePath, RewriteTablePath.Result> { | ||
|
|
||
| /** | ||
| * Passes the source and target prefixes that will be used to replace the source prefix with the |
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.
The sentence repeats itself, what do you think of 'Configure a source prefix that will be replaced by the specified target prefix in all paths'
|
|
||
| import org.apache.iceberg.Table; | ||
|
|
||
| public interface RewriteTablePath extends Action<RewriteTablePath, RewriteTablePath.Result> { |
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.
I think we need a overall javadoc describing this. In particular, I think the concept of 'target version' needs to be explained here. I think its clearer to say 'last metadata version'
Rewrites a set of the table's metadata files to a staging directory, replacing all source prefixes in absolute paths with a specified target prefix.
There are two modes.
1. A complete copy rewrites all metadata files to the staging directory.
2. An incremental copy rewrites a set of metadata files to the staging directory, consisting of metadata files added since a specified 'last metadata version'.
For incremental copy, the 'last metadata version' is specified by a name of a metadata.json file, with all metadata files added after this file being marked for rewrite.
The action can be used as the starting point to fully or incrementally copy an Iceberg table located under the source prefix to the target prefix. It returns the following:
1. The name of the latest metadata.json file copied.
2. A listing of rewritten table metadata files, relative to staging directory, that can be copied to the target prefix.
3. A listing of table data files, relative to source prefix, that can be copied to the target prefix.
@flyrain does it make sense?
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.
+1, thanks for the suggestion.
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.
Thanks.
To update with our latest conversation, how about replace the last list with
1. A listing of all files added in the table between startVersion and endVersion, with both the original path and a target path under the target prefix. This list includes files in the original table and those that have been rewritten to staging. All files can be copied to their specified target path to form the copied table.
2. The name of the latest metadata.json rewritten to staging. After the files are copy, this can become the root of the copied table.
| * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath lastCopiedVersion(String lastCopiedVersion); |
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.
Based on previous suggestion, how about
Last copied metadata version, identified by name of a metadata.json file in the table's metadata log. This action will rewrite all metadata files added after this.
Can we not support HadoopFileIO initially, so we can simplify definition of the argument?
| * "00001-8893aa9e-f92e-4443-80e7-cfa42238a654.metadata.json". | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath endVersion(String endVersion); |
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 about:
Last metadata version to copy, identified by name of a metadata.json file in the table's metadata log. This action will rewrite all metadata files added before this, up to this file itself.
Can we not support HadoopFileIO initially, so we can simplify definition of the argument?
|
|
||
| /** The action result that contains a summary of the execution. */ | ||
| interface Result { | ||
| /** Return staging location */ |
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.
Nit: omit 'return' as its redundant.
'staging location of rewritten files'
| String stagingLocation(); | ||
|
|
||
| /** Return directory of data files list. */ | ||
| String dataFileListLocation(); |
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.
This is a directory, or is it a path to the listing? I thought it was path according to https://github.com/apache/iceberg/pull/10024/files
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.
It's a directory actually, but I think we can make it a file path in the implementation for a better UX
| * @param targetTable the target table | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath targetTable(Table targetTable); |
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.
This is just a convenience to get the last metadata.json file location , right? That table is never used elsewhere here.
What do you guys think to omit this one (I feel the user can load the table independently and get the path). As it is now, its pretty confusing in my opinion.
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.
Yes I also think it's unnecessary, startVersion should be enough
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.
The original intent was to provide flexibility in case Spark could access both tables. However, I now agree with your point—it makes sense to keep the interface simpler by removing that part.
| RewriteTablePath targetTable(Table targetTable); | ||
|
|
||
| /** The action result that contains a summary of the execution. */ | ||
| interface Result { |
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.
Actually a few more comments here, I think we need additional list for
- position delete files
- equality delete files
- puffin files
Does it make sense?
Also, what do you guys think to return source, target path pair for each file. Each source path is either the original file path in the table, or the rewritten one in staging. The target path is the one under target prefix (the target one is always the latest referred to by all rewritten metadata paths). This would make the subsequent move is easier to perform. I know in the earlier implementation this existed.
cc @flyrain for thoughts
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.
@szehon-ho I don't think it makes sense, because metadataFileList file will contain all metadata files paths (metadata.json, manifests, manifest lists, position/equality delete files etc), so there's no point of having multiple lists. I agree with returning source and target path for each file, will keep that in mind for the implementation PR.
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.
yea i thought a bit over the weekend, and multiple list is too complicated.
How about we dont need multiple list (metadataFileList and dataFileList), and just have one list (fileList). My main concern is deleteFile, which list it should be part of. It doesnt truly fit into either. I feel In the end, we want to have just a list of Pair<String, String> , which is source and target. Source can be source if rewritten, or original source if not.
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.
Since deleteFiles already exists under the metadata folder in the storage then it makes sense to have them in the metadataFileList. I think the expectation was for the user to copy all files in metadataFileList to /metadata and dataFileList to /data in the new target location. But I agree with your suggestion, we can further narrow it down to one list as well and just have the source,target paths for all of them and the user can just initiate the copy from source to target without worrying about if it's data or metadata files 👍
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.
Since deleteFiles already exists under the metadata folder in the storage
I thought its generally not the case, and they co-exist with the data files in the partition folder. Hence my initial comment.
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.
DeleteFiles are not considered as metadata files even they are in the directory /metadata. It's more and more clear to me that we may just use one list holding pairs of (sourcePath, targetPath). WDYT?
|
@szehon-ho I addressed the comments! PTAL 👍 |
|
@szehon-ho PTAL |
| String stagingLocation(); | ||
|
|
||
| /** | ||
| * path to a list of comma-separated pairs of source and target path for data and metadata |
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 about:
Path to a list of comma-separated pairs of source path to target path for all files in the table added between startVersion and endVersion. Note that this list includes data files from the original table and metadata files rewritten to staging.
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.
Also tagging @KolonelKustard who is planning to consume this functionality if any thoughts on whether this is nice to consume for the copy part.
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.
+1
Having a single list means that as the table format evolves and the implementations of this copy action evolve, hopefully there's fewer changes for downstream users of this action.
Having the target path saves downstream users having to duplicate the prefix re-writing rules already applied by this actions implementations. Which hopefully makes using this a bit less error-prone.
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.
Sorry for delay. Looking better, I added some more comments.
| /** The action result that contains a summary of the execution. */ | ||
| interface Result { | ||
| /** staging location of rewritten files */ | ||
| String stagingLocation(); |
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.
Nit: let's capitalize these field javadocs?
|
|
||
| import org.apache.iceberg.Table; | ||
|
|
||
| public interface RewriteTablePath extends Action<RewriteTablePath, RewriteTablePath.Result> { |
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.
Thanks.
To update with our latest conversation, how about replace the last list with
1. A listing of all files added in the table between startVersion and endVersion, with both the original path and a target path under the target prefix. This list includes files in the original table and those that have been rewritten to staging. All files can be copied to their specified target path to form the copied table.
2. The name of the latest metadata.json rewritten to staging. After the files are copy, this can become the root of the copied table.
|
Thanks for the review @szehon-ho. I addressed the comments, PTAL |
szehon-ho
left a comment
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.
Thanks it looks good to me. Just one more thing came up for me, what do you think?
| * @param targetPrefix the target prefix | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath rewriteLocationPrefix(String sourcePrefix, String targetPrefix); |
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.
One more thing came up while discussing internally. This was brought up by @huaxiangsun today. Its possible that the data and metadata are in different locations. In this case, we would need an optional API
rewriteLocationPrefix(String sourceDataPrefix, String sourceMetadataPrefix, String targetDataPrefix, String targetMetadataPrefix)
What do you think @laithalzyoud @flyrain let me know if we missed something though.
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.
I think it's useful, and I'm OK with either adding it in this PR or in a followup PR. Another option is to add a list of mappings like this {(sourcePrefix1, targetPrefix1), (sourcePrefix2, targetPrefix2), ...}. We will need to figure out the overlap though, but I think it is solvable. It's a not blocker for me.
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.
Is there a use case for something beyond data and metadata? Just wondering if that's unnecessary complicated. With this four-arg API we can just check data/metadata dont overlap, else throw exception and mention they can use the two-arg API?
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.
Theoretically, data/metadata file could be anywhere. For example, there is a use case where people store old partitions in a cheaper storage. I understand that's not a common use case, but just like the different directories between data files and metadata files, it could happen.
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.
I see what you mean. Makes sense, we can tackle that in follow on then as you mentioned.
| * @param targetPrefix the target prefix | ||
| * @return this for method chaining | ||
| */ | ||
| RewriteTablePath rewriteLocationPrefix(String sourcePrefix, String targetPrefix); |
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.
I see what you mean. Makes sense, we can tackle that in follow on then as you mentioned.
|
Merged , thanks @laithalzyoud |
|
Thanks @szehon-ho! Will follow up with the implementation PR soon 👍 |
|
Great! Thanks a lot for working on it, guys! |
A follow up PR on #10024