This is an automated email from the ASF dual-hosted git repository.
pvary pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new ff85472601 Hive: Preserve tables and views on mismatched drops (#18691)
ff85472601 is described below
commit ff854726011fd35d90cdb1390754e28e6ea84b67
Author: Daksh Dave <[email protected]>
AuthorDate: Thu Nov 19 03:10:18 2026 -0800
Hive: Preserve tables and views on mismatched drops (#18691)
---
.../org/apache/iceberg/view/ViewCatalogTests.java | 39 ++++++++++++++++++++++
.../java/org/apache/iceberg/hive/HiveCatalog.java | 4 +--
.../iceberg/nessie/TestNessieViewCatalog.java | 18 ++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
index 00926ca73c..ebb8675e36 100644
--- a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
@@ -93,6 +93,45 @@ public abstract class ViewCatalogTests<C extends ViewCatalog
& SupportsNamespace
return false;
}
+ @ParameterizedTest(name = "purge = {0}")
+ @ValueSource(booleans = {false, true})
+ public void dropTableThatAlreadyExistsAsView(boolean purge) {
+ assumeThat(tableCatalog()).as("Only valid for catalogs that support
tables").isNotNull();
+
+ TableIdentifier identifier = TableIdentifier.of("ns", "view");
+ if (requiresNamespaceCreate()) {
+ catalog().createNamespace(identifier.namespace());
+ }
+
+ View view =
+ catalog()
+ .buildView(identifier)
+ .withSchema(SCHEMA)
+ .withDefaultNamespace(identifier.namespace())
+ .withQuery("hive", "select * from ns.tbl")
+ .create();
+
+ assertThat(tableCatalog().dropTable(identifier, purge)).isFalse();
+ assertThat(catalog().viewExists(identifier)).isTrue();
+ assertThat(catalog().loadView(identifier).uuid()).isEqualTo(view.uuid());
+ }
+
+ @Test
+ public void dropViewThatAlreadyExistsAsTable() {
+ assumeThat(tableCatalog()).as("Only valid for catalogs that support
tables").isNotNull();
+
+ TableIdentifier identifier = TableIdentifier.of("ns", "table");
+ if (requiresNamespaceCreate()) {
+ catalog().createNamespace(identifier.namespace());
+ }
+
+ Table table = tableCatalog().buildTable(identifier, SCHEMA).create();
+
+ assertThat(catalog().dropView(identifier)).isFalse();
+ assertThat(tableCatalog().tableExists(identifier)).isTrue();
+
assertThat(tableCatalog().loadTable(identifier).uuid()).isEqualTo(table.uuid());
+ }
+
@Test
public void loadViewWithNonExistingNamespace() {
TableIdentifier ident = TableIdentifier.of("non-existing", "view");
diff --git
a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
index 287b35082b..ead02a12c9 100644
--- a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
+++ b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java
@@ -241,7 +241,7 @@ public class HiveCatalog extends BaseMetastoreViewCatalog
@Override
public boolean dropTable(TableIdentifier identifier, boolean purge) {
- if (!isValidIdentifier(identifier)) {
+ if (!isValidIdentifier(identifier) || viewExists(identifier)) {
return false;
}
@@ -321,7 +321,7 @@ public class HiveCatalog extends BaseMetastoreViewCatalog
LOG.info("Dropped view: {}", identifier);
return true;
- } catch (NoSuchObjectException e) {
+ } catch (NoSuchViewException | NoSuchObjectException e) {
LOG.info("Skipping drop, view does not exist: {}", identifier, e);
return false;
} catch (TException e) {
diff --git
a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
index dc3d5dc0ed..3ed3442013 100644
--- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
+++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieViewCatalog.java
@@ -35,10 +35,13 @@ import org.apache.iceberg.view.ViewCatalogTests;
import org.apache.iceberg.view.ViewMetadata;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.ext.NessieApiVersion;
import org.projectnessie.client.ext.NessieApiVersions;
@@ -101,6 +104,21 @@ public class TestNessieViewCatalog extends
ViewCatalogTests<NessieCatalog> {
}
}
+ @Override
+ @Disabled("Pending https://github.com/apache/iceberg/pull/18912")
+ @ParameterizedTest(name = "purge = {0}")
+ @ValueSource(booleans = {false, true})
+ public void dropTableThatAlreadyExistsAsView(boolean purge) {
+ super.dropTableThatAlreadyExistsAsView(purge);
+ }
+
+ @Override
+ @Disabled("Pending https://github.com/apache/iceberg/pull/18912")
+ @Test
+ public void dropViewThatAlreadyExistsAsTable() {
+ super.dropViewThatAlreadyExistsAsTable();
+ }
+
private void resetData() throws NessieConflictException,
NessieNotFoundException {
Branch defaultBranch = api.getDefaultBranch();
for (Reference r : api.getAllReferences().get().getReferences()) {