Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NotFoundException;
import org.apache.iceberg.hadoop.Configurable;
import org.apache.iceberg.io.CloseableGroup;
import org.apache.iceberg.io.FileIO;
Expand Down Expand Up @@ -183,7 +184,17 @@ public List<TableIdentifier> listTables(Namespace namespace) {
public boolean dropTable(TableIdentifier identifier, boolean purge) {
try {
TableOperations ops = newTableOps(identifier);
TableMetadata lastMetadata = ops.current();
TableMetadata lastMetadata = null;
if (purge) {
try {
lastMetadata = ops.current();
} catch (NotFoundException e) {
LOG.warn(
"Failed to load table metadata for table: {}, continuing drop without purge",
identifier,
e);
}
}

client.delete(toTableReference(identifier));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -244,6 +245,29 @@ public void createTableCommitSucceeds() throws Exception {
assertThat(loadedTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
}

@Test
public void dropTableWithoutPurgeDoesNotLoadMetadata() {
catalog.dropTable(IDENTIFIER, false);

// A plain drop must not trigger a tables.get on BigQuery, since the metadata is only needed for
// purge.
verify(client, never()).load(TABLE_REFERENCE);
verify(client, times(1)).delete(TABLE_REFERENCE);
}

@Test
public void dropTableWithPurgeLoadsMetadata() throws Exception {
Table createdTable = createTestTable();
reset(client);
when(client.load(TABLE_REFERENCE)).thenReturn(createdTable);

catalog.dropTable(IDENTIFIER, true);

// Purge needs the current metadata to delete the table's data files, so it must load it.
verify(client, times(1)).load(TABLE_REFERENCE);
verify(client, times(1)).delete(TABLE_REFERENCE);
}

/** Creates a test table to have Iceberg metadata files in place. */
private Table createTestTable() throws Exception {
when(client.load(TABLE_REFERENCE))
Expand Down