Skip to content

Conversation

@laithalzyoud
Copy link
Contributor

@laithalzyoud laithalzyoud commented Aug 12, 2024

A follow up PR on #10024

@laithalzyoud laithalzyoud changed the title Add CopyTable action interface Spark: Add CopyTable action interface Aug 12, 2024
@laithalzyoud
Copy link
Contributor Author

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 RewriteTableLocation or something similar

@manuzhang
Copy link
Member

Since it's just rewriting metadata, manifest and position delete files with the new location prefix and not actually copying the table

Isn't an implementation of this interface actually copying the table?

@laithalzyoud
Copy link
Contributor Author

Since it's just rewriting metadata, manifest and position delete files with the new location prefix and not actually copying the table

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

@flyrain
Copy link
Contributor

flyrain commented Aug 12, 2024

cc @szehon-ho @huaxingao

@flyrain
Copy link
Contributor

flyrain commented Aug 12, 2024

Isn't an implementation of this interface actually copying the table?

NO. I think it makes sense to go with a name like RewriteFileLocation, or RewriteFilePaths

@manuzhang
Copy link
Member

I'm a bit lost in the context. If I run this action without copying the table (e.g. rewrite s3 to gcs), isn't it in a corrupt status?

@laithalzyoud
Copy link
Contributor Author

I'm a bit lost in the context. If I run this action without copying the table (e.g. rewrite s3 to gcs), isn't it in a corrupt status?

@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 👍

@laithalzyoud laithalzyoud changed the title Spark: Add CopyTable action interface Spark: Add RewriteTableLocaiton action interface Aug 13, 2024
@laithalzyoud laithalzyoud changed the title Spark: Add RewriteTableLocaiton action interface Spark: Add RewriteTableLocation action interface Aug 13, 2024

import org.apache.iceberg.Table;

public interface RewriteTableLocation extends Action<RewriteTableLocation, RewriteTableLocation.Result> {
Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@laithalzyoud laithalzyoud changed the title Spark: Add RewriteTableLocation action interface Spark: Add RewriteTablePath action interface Aug 18, 2024
@flyrain
Copy link
Contributor

flyrain commented Aug 21, 2024

@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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

@szehon-ho szehon-ho Oct 1, 2024

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.
Copy link
Contributor

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?

Copy link
Contributor Author

@laithalzyoud laithalzyoud Aug 30, 2024

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() {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

Laith Alzyoud added 2 commits September 16, 2024 16:56
…into add-copy-table-action-interface

# Conflicts:
#	api/src/main/java/org/apache/iceberg/actions/ActionsProvider.java
…Path.java


Fix typo

Co-authored-by: Eduard Tudenhoefner <etudenhoefner@gmail.com>
@laithalzyoud
Copy link
Contributor Author

Hello @nastra @anuragmantri! What's left to merge this PR?

@laithalzyoud
Copy link
Contributor Author

@nastra can you rerun the workflows please? I fixed a formatting error

@nastra
Copy link
Contributor

nastra commented Sep 25, 2024

@nastra can you rerun the workflows please? I fixed a formatting error

The formatting error seems to still exist

@laithalzyoud
Copy link
Contributor Author

@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?

@laithalzyoud
Copy link
Contributor Author

Hey @nastra @manuzhang @anuragmantri @flyrain! Can we merge this now?

Copy link
Contributor

@flyrain flyrain left a 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.

Copy link
Member

@szehon-ho szehon-ho left a 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. */
Copy link
Member

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
Copy link
Member

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> {
Copy link
Member

@szehon-ho szehon-ho Oct 1, 2024

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?

Copy link
Contributor

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.

Copy link
Member

@szehon-ho szehon-ho Oct 14, 2024

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);
Copy link
Member

@szehon-ho szehon-ho Oct 1, 2024

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);
Copy link
Member

@szehon-ho szehon-ho Oct 1, 2024

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 */
Copy link
Member

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();
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

@szehon-ho szehon-ho Oct 1, 2024

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 {
Copy link
Member

@szehon-ho szehon-ho Oct 4, 2024

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

Copy link
Contributor Author

@laithalzyoud laithalzyoud Oct 7, 2024

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.

Copy link
Member

@szehon-ho szehon-ho Oct 7, 2024

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.

Copy link
Contributor Author

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 👍

Copy link
Member

@szehon-ho szehon-ho Oct 14, 2024

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.

Copy link
Contributor

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?

@laithalzyoud
Copy link
Contributor Author

@szehon-ho I addressed the comments! PTAL 👍

@laithalzyoud
Copy link
Contributor Author

@szehon-ho PTAL

String stagingLocation();

/**
* path to a list of comma-separated pairs of source and target path for data and metadata
Copy link
Member

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.

Copy link
Member

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.

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.

Copy link
Member

@szehon-ho szehon-ho left a 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();
Copy link
Member

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> {
Copy link
Member

@szehon-ho szehon-ho Oct 14, 2024

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.

@laithalzyoud
Copy link
Contributor Author

Thanks for the review @szehon-ho. I addressed the comments, PTAL

Copy link
Member

@szehon-ho szehon-ho left a 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);
Copy link
Member

@szehon-ho szehon-ho Oct 16, 2024

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.

Copy link
Contributor

@flyrain flyrain Oct 17, 2024

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.

Copy link
Member

@szehon-ho szehon-ho Oct 17, 2024

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?

Copy link
Contributor

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.

Copy link
Member

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);
Copy link
Member

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.

@szehon-ho szehon-ho merged commit d61a98d into apache:main Oct 18, 2024
@szehon-ho
Copy link
Member

Merged , thanks @laithalzyoud

@laithalzyoud
Copy link
Contributor Author

Thanks @szehon-ho! Will follow up with the implementation PR soon 👍

@flyrain
Copy link
Contributor

flyrain commented Oct 18, 2024

Great! Thanks a lot for working on it, guys!

zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants