Skip to content
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

Support force option on RegisterTable procedure #5327

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Support delete corrupted Iceberg table
  • Loading branch information
yabola committed Aug 12, 2022
commit 2063631aee5a22273ad3f552ae9c33f840557cbc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NotFoundException;
import org.apache.iceberg.hadoop.HadoopFileIO;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -169,10 +170,19 @@ public boolean dropTable(TableIdentifier identifier, boolean purge) {

TableOperations ops = newTableOps(identifier);
TableMetadata lastMetadata;
if (purge && ops.current() != null) {
lastMetadata = ops.current();
} else {
lastMetadata = null;
try {
if (purge && ops.current() != null) {
lastMetadata = ops.current();
} else {
lastMetadata = null;
}
} catch (Exception e) {
if (e instanceof NotFoundException) {
LOG.warn("The metadata file doesn't exist any more. Continue to drop the table.", e);
lastMetadata = null;
} else {
throw e;
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.iceberg.SortOrderParser;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.Transaction;
import org.apache.iceberg.UpdateSchema;
Expand All @@ -62,6 +63,7 @@
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
Expand Down Expand Up @@ -443,6 +445,7 @@ public void testDropNamespace() throws TException {
() -> {
catalog.dropNamespace(namespace);
});
final String s = catalog.newTableOps(identifier).current().metadataFileLocation();
Assert.assertTrue(catalog.dropTable(identifier, true));
Assert.assertTrue(
"Should fail to drop namespace if it is not empty", catalog.dropNamespace(namespace));
Expand All @@ -458,6 +461,38 @@ public void testDropNamespace() throws TException {
});
}

@Test
public void testDropTable() throws TException {
Namespace namespace = Namespace.of("dbname_drop");
TableIdentifier identifier = TableIdentifier.of(namespace, "table");
Schema tableSchema =
new Schema(Types.StructType.of(required(1, "id", Types.LongType.get())).fields());
catalog.createNamespace(namespace, meta);
catalog.createTable(identifier, tableSchema);
TableOperations ops = catalog.newTableOps(identifier);

Assert.assertTrue(catalog.dropTable(identifier, true));
AssertHelpers.assertThrows(
"Should fail to load table after dropping it",
NoSuchTableException.class,
() -> catalog.loadTable(identifier)
);

// delete corrupted table
catalog.createTable(identifier, tableSchema);
String metadataFileLocation = catalog.newTableOps(identifier).current().metadataFileLocation();
ops.io().deleteFile(metadataFileLocation);
Assert.assertTrue(catalog.dropTable(identifier, true));
AssertHelpers.assertThrows(
"Should fail to load table after dropping it",
NoSuchTableException.class,
() -> catalog.loadTable(identifier)
);

// delete table that does not exist
Assert.assertFalse(catalog.dropTable(identifier, true));
}

@Test
public void testTableName() {
Schema schema =
Expand Down