-
Notifications
You must be signed in to change notification settings - Fork 5.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
[Iceberg]Support renaming table on hive file catalog #24312
base: master
Are you sure you want to change the base?
[Iceberg]Support renaming table on hive file catalog #24312
Conversation
7cd47c9
to
366408c
Compare
try { | ||
if (!metadataFileSystem.rename(getTableMetadataDirectory(databaseName, tableName), getTableMetadataDirectory(newDatabaseName, newTableName))) { | ||
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory"); | ||
if (!isIcebergTable(table)) { |
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 - How about we put the positive condition in if-else instead since the implementation is valid for tables and views both :
if (isIcebergTable) {}
else {}
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.
Done.
} | ||
else { | ||
// If the directory `.prestoPermissions` exists, copy it to the new table metadata directory | ||
if (metadataFileSystem.exists(new Path(metadataDirectory, PRESTO_PERMISSIONS_DIRECTORY_NAME))) { |
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 I think it would be better to move Iceberg logic handle in different method and call that from here.
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.
Good suggestion, I have refactored the code, extracted two methods to make it more concise. Please take a look when available.
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 the changes are fine, however the code complexity seems high due to all the nested conditionals. I would consider factoring out some methods or subclassing as mentioned in my comment.
try { | ||
if (!metadataFileSystem.rename(getTableMetadataDirectory(databaseName, tableName), getTableMetadataDirectory(newDatabaseName, newTableName))) { | ||
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory"); | ||
if (!isIcebergTable(table)) { |
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 don't think we need to do it for this PR, but all these conditionals make me think that it is worth considering to subclass the FileHiveMetastore
and create a FileIcebergHiveMetastore
or something similar to capture the differences in behavior. It seems a bit messy currently.
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.
Agreed, seems there are indeed some implementation details that differ between them and need to be special handled. It is worth considering to put these different details into Iceberg's own subclass.
Thanks for the release note! Nit of formatting suggestion:
|
366408c
to
4a0b64d
Compare
Thanks @steveburnett, fixed. Please take a look when available. |
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.
@hantangwangd Can we add some tests in iceberg which tests these newly added code lines?
{ | ||
try { | ||
if (!metadataFileSystem.rename(originalMetadataDirectory, newMetadataDirectory)) { | ||
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory"); |
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: We can add some more details in exception here around which table directory is being renamed
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.
Fixed!
|
||
// Rename file `.prestoSchema` to change it to the new metadata path | ||
// This will atomically execute the table renaming behavior | ||
if (!metadataFileSystem.rename(new Path(originalMetadataDirectory, PRESTO_SCHEMA_FILE_NAME), new Path(newMetadataDirectory, PRESTO_SCHEMA_FILE_NAME))) { | ||
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory"); |
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: We can add some more details in exception here around which table directory is being renamed
if (metadataFileSystem.exists(new Path(originalMetadataDirectory, PRESTO_PERMISSIONS_DIRECTORY_NAME))) { | ||
if (!FileUtil.copy(metadataFileSystem, new Path(originalMetadataDirectory, PRESTO_PERMISSIONS_DIRECTORY_NAME), | ||
metadataFileSystem, new Path(newMetadataDirectory, PRESTO_PERMISSIONS_DIRECTORY_NAME), false, metadataFileSystem.getConf())) { | ||
throw new PrestoException(HIVE_METASTORE_ERROR, "Could not rename table directory"); |
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: We can add some more details in exception here around which table directory is being renamed
4a0b64d
to
e3fa5dc
Compare
e3fa5dc
to
7330926
Compare
I constructed a test environment based on a customized |
Description
This PR support renaming table behavior for iceberg tables on hive file catalog.
Motivation and Context
Support renaming table for Iceberg connector on as many catalog types as possible
Impact
Iceberg connector configured with hive file catalogs can now support renaming table
Test Plan
Contributor checklist
Release Notes