-
Notifications
You must be signed in to change notification settings - Fork 3k
API: Register existing tables in Iceberg HiveCatalog #3851
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,10 +36,12 @@ | |
| import org.apache.hadoop.hive.metastore.api.UnknownDBException; | ||
| import org.apache.iceberg.BaseMetastoreCatalog; | ||
| import org.apache.iceberg.BaseMetastoreTableOperations; | ||
| import org.apache.iceberg.BaseTable; | ||
| import org.apache.iceberg.CatalogProperties; | ||
| import org.apache.iceberg.CatalogUtil; | ||
| import org.apache.iceberg.ClientPool; | ||
| import org.apache.iceberg.TableMetadata; | ||
| import org.apache.iceberg.TableMetadataParser; | ||
| import org.apache.iceberg.TableOperations; | ||
| import org.apache.iceberg.catalog.Namespace; | ||
| import org.apache.iceberg.catalog.SupportsNamespaces; | ||
|
|
@@ -49,6 +51,7 @@ | |
| import org.apache.iceberg.exceptions.NoSuchTableException; | ||
| import org.apache.iceberg.hadoop.HadoopFileIO; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.io.InputFile; | ||
| import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
|
|
@@ -211,6 +214,23 @@ public void renameTable(TableIdentifier from, TableIdentifier originalTo) { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public org.apache.iceberg.Table registerTable(TableIdentifier identifier, String metadataFileLocation) { | ||
|
Contributor
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. Could we put this in BaseMetastoreCatalog? It doesn't look like there is anything Hive-specific here, so other catalog implementations could potentially benefit.
Contributor
Author
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. This is a good point. Potentially, other catalogs can benefit from this. However,
Contributor
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. Sure, thanks |
||
| Preconditions.checkArgument(isValidIdentifier(identifier), "Invalid identifier: %s", identifier); | ||
|
|
||
| // Throw an exception if this table already exists in the catalog. | ||
| if (tableExists(identifier)) { | ||
| throw new org.apache.iceberg.exceptions.AlreadyExistsException("Table already exists: %s", identifier); | ||
| } | ||
|
|
||
| TableOperations ops = newTableOps(identifier); | ||
| InputFile metadataFile = fileIO.newInputFile(metadataFileLocation); | ||
| TableMetadata metadata = TableMetadataParser.read(ops.io(), metadataFile); | ||
| ops.commit(null, metadata); | ||
|
|
||
| return new BaseTable(ops, identifier.toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void createNamespace(Namespace namespace, Map<String, String> meta) { | ||
| Preconditions.checkArgument( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,8 @@ protected void doRefresh() { | |
| @SuppressWarnings("checkstyle:CyclomaticComplexity") | ||
| @Override | ||
| protected void doCommit(TableMetadata base, TableMetadata metadata) { | ||
| String newMetadataLocation = writeNewMetadata(metadata, currentVersion() + 1); | ||
| String newMetadataLocation = base == null && metadata.metadataFileLocation() != null ? | ||
| metadata.metadataFileLocation() : writeNewMetadata(metadata, currentVersion() + 1); | ||
|
Comment on lines
+213
to
+214
Contributor
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. Looks like this change is not related. Can we remove it?
Contributor
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. Is it used by the new test?
Contributor
Author
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. Without this change, registering a table creates a new metadata file with a new version instead of using the version provided by the metadata file. Yes, the tests also rely on this. |
||
| boolean hiveEngineEnabled = hiveEngineEnabled(metadata, conf); | ||
| boolean keepHiveStats = conf.getBoolean(ConfigProperties.KEEP_HIVE_STATS, false); | ||
|
|
||
|
|
||
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.
FYI @bryanck. What do you think about this?
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.
LGTM, it is very straightforward, I just had one question below...