RussellSpitzer commented on code in PR #12228:
URL: https://github.com/apache/iceberg/pull/12228#discussion_r2363249976
##########
core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java:
##########
@@ -71,23 +70,34 @@ public Table loadTable(TableIdentifier identifier) {
}
@Override
- public Table registerTable(TableIdentifier identifier, String
metadataFileLocation) {
+ public Table registerTable(
+ TableIdentifier identifier, String metadataFileLocation, boolean
overwrite) {
Preconditions.checkArgument(
identifier != null && isValidIdentifier(identifier), "Invalid
identifier: %s", identifier);
Preconditions.checkArgument(
metadataFileLocation != null && !metadataFileLocation.isEmpty(),
"Cannot register an empty metadata file location as a table");
- // Throw an exception if this table already exists in the catalog.
- if (tableExists(identifier)) {
- throw new AlreadyExistsException("Table already exists: %s", identifier);
- }
-
TableOperations ops = newTableOps(identifier);
- InputFile metadataFile = ops.io().newInputFile(metadataFileLocation);
- TableMetadata metadata = TableMetadataParser.read(ops.io(), metadataFile);
- ops.commit(null, metadata);
+ TableMetadata existing = ops.current();
+ if (tableExists(identifier)) {
Review Comment:
I think there is a bit of a lock issue here, ie between line 84 and 91 we
may have created the table. I'm not sure this is actually a problem since this
is a pretty destructive operation anyway. This implementation though is mixing
some logic here
IIMHO I think this should be completely replaced with a catalog specific impl
Something like
```
if (overwrite) {
CatalogSpecific registerTable logic
} else if (table doesn't exist) {
catalog specific lockTable
Catalog specific registerTable logic
catalog specific removeLock
} else {
// We can't overwrite and the table already exists
throw table already exists exception
}
```
Here we drop the "operations" path entirely
I think we should probably remove any
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]