Skip to content

Commit

Permalink
Address Gabor feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Hongyue Zhang <[email protected]>
  • Loading branch information
dramaticlly committed Feb 13, 2025
1 parent 08efd36 commit dbee263
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/apache/iceberg/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ default Table registerTable(TableIdentifier identifier, String metadataFileLocat
*/
default Table registerTable(
TableIdentifier identifier, String metadataFileLocation, boolean overwrite) {
throw new UnsupportedOperationException("Registering tables with overwrite is not supported");
throw new UnsupportedOperationException("Registering tables is not supported");
}

/**
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/apache/iceberg/BaseMetastoreCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public Table registerTable(
// Throw an exception if this table already exists in the catalog.
if (tableExists(identifier) && !overwrite) {
throw new AlreadyExistsException("Table already exists: %s", identifier);
} else {
TableOperations ops = newTableOps(identifier);
InputFile metadataFile = ops.io().newInputFile(metadataFileLocation);
TableMetadata currentMetadata = tableExists(identifier) ? ops.current() : null;
ops.commit(currentMetadata, TableMetadataParser.read(ops.io(), metadataFile));
return new BaseTable(ops, fullTableName(name(), identifier), metricsReporter());
}

TableOperations ops = newTableOps(identifier);
InputFile metadataFile = ops.io().newInputFile(metadataFileLocation);
TableMetadata currentMetadata = tableExists(identifier) ? ops.current() : null;
ops.commit(currentMetadata, TableMetadataParser.read(ops.io(), metadataFile));
return new BaseTable(ops, fullTableName(name(), identifier), metricsReporter());
}

@Override
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/org/apache/iceberg/CachingCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ public void invalidateTable(TableIdentifier ident) {
tableCache.invalidateAll(metadataTableIdentifiers(canonicalized));
}

@Override
public Table registerTable(TableIdentifier identifier, String metadataFileLocation) {
Table table = catalog.registerTable(identifier, metadataFileLocation);
invalidateTable(identifier);
return table;
}

@Override
public Table registerTable(
TableIdentifier identifier, String metadataFileLocation, boolean overwrite) {
Expand Down
11 changes: 7 additions & 4 deletions core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2890,14 +2890,17 @@ public void testRegisterAndOverwriteExistingTable() {
catalog.createTable(identifier, SCHEMA);
Table table = catalog.loadTable(identifier);
TableOperations ops = ((BaseTable) table).operations();
assertThat(table.spec().isPartitioned()).isFalse();
String unpartitionedMetadataLocation = ops.current().metadataFileLocation();

// update table spec
table.updateSpec().addField(bucket("id", 16)).commit();
String newMetadataLocation = ops.refresh().metadataFileLocation();
assertThat(table.spec().isPartitioned()).isTrue();

// register and overwrite
catalog.registerTable(identifier, newMetadataLocation, true);
catalog.registerTable(identifier, unpartitionedMetadataLocation, true);

table.refresh();
assertThat(table.spec().isPartitioned()).isTrue();
assertThat(table.spec().isPartitioned()).isFalse();
assertThat(catalog.dropTable(identifier)).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,19 +672,19 @@ public void testRegisterExistingTable() throws IOException {
HadoopCatalog catalog = hadoopCatalog();
catalog.createTable(identifier, SCHEMA);
Table registeringTable = catalog.loadTable(identifier);
assertThat(registeringTable.spec().isPartitioned()).isFalse();
TableOperations ops = ((HasTableOperations) registeringTable).operations();
String oldMetadataLocation = ops.current().metadataFileLocation();
String unpartitionedMetadataLocation = ops.current().metadataFileLocation();
// update table spec
registeringTable.updateSpec().addField(bucket("id", 16)).commit();
String newMetadataLocation = ops.refresh().metadataFileLocation();
assertThat(registeringTable.spec().isPartitioned()).isTrue();
// register w/o overwrite
assertThatThrownBy(() -> catalog.registerTable(identifier, oldMetadataLocation, false))
assertThatThrownBy(
() -> catalog.registerTable(identifier, unpartitionedMetadataLocation, false))
.isInstanceOf(AlreadyExistsException.class)
.hasMessage("Table already exists: a.t1");
// register with overwrite
catalog.registerTable(identifier, newMetadataLocation, true);
assertThat(catalog.loadTable(identifier).spec().isPartitioned()).isTrue();
catalog.registerTable(identifier, unpartitionedMetadataLocation, true);
assertThat(catalog.loadTable(identifier).spec().isPartitioned()).isFalse();
assertThat(catalog.dropTable(identifier)).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,19 @@ public void testRegisterExistingTable() {
TableIdentifier identifier = TableIdentifier.of("a", "t1");
ecsCatalog.createTable(identifier, SCHEMA);
Table registeringTable = ecsCatalog.loadTable(identifier);
assertThat(registeringTable.spec().isPartitioned()).isFalse();
TableOperations ops = ((HasTableOperations) registeringTable).operations();
String oldMetadataLocation = ops.current().metadataFileLocation();
String unpartitionedMetadataLocation = ops.current().metadataFileLocation();
// update table spec
registeringTable.updateSpec().addField(bucket("id", 16)).commit();
String newMetadataLocation = ops.refresh().metadataFileLocation();
assertThat(registeringTable.spec().isPartitioned()).isTrue();
// register w/o overwrite
assertThatThrownBy(() -> ecsCatalog.registerTable(identifier, oldMetadataLocation, false))
assertThatThrownBy(
() -> ecsCatalog.registerTable(identifier, unpartitionedMetadataLocation, false))
.isInstanceOf(AlreadyExistsException.class)
.hasMessage("Table already exists: a.t1");
// register with overwrite
ecsCatalog.registerTable(identifier, newMetadataLocation, true);
assertThat(ecsCatalog.loadTable(identifier).spec().isPartitioned()).isTrue();
ecsCatalog.registerTable(identifier, unpartitionedMetadataLocation, true);
assertThat(ecsCatalog.loadTable(identifier).spec().isPartitioned()).isFalse();
assertThat(ecsCatalog.dropTable(identifier, true)).isTrue();
}
}

0 comments on commit dbee263

Please sign in to comment.