@Test public void testDropNamespace() throws TException { Namespace namespace = Namespace.of("dbname_drop"); TableIdentifier identifier = TableIdentifier.of(namespace, "table"); Schema schema = new Schema(Types.StructType.of( required(1, "id", Types.LongType.get())).fields()); catalog.createNamespace(namespace, meta); catalog.createTable(identifier, schema); Map<String, String> nameMata = catalog.loadNamespaceMetadata(namespace); Assert.assertTrue(nameMata.get("owner").equals("apache")); Assert.assertTrue(nameMata.get("group").equals("iceberg")); AssertHelpers.assertThrows("Should fail to drop namespace is not empty" + namespace, NamespaceNotEmptyException.class, "Namespace dbname_drop is not empty. One or more tables exist.", () -> { catalog.dropNamespace(namespace); }); Assert.assertTrue(catalog.dropTable(identifier, true)); Assert.assertTrue("Should fail to drop namespace if it is not empty", catalog.dropNamespace(namespace)); Assert.assertFalse("Should fail to drop when namespace doesn't exist", catalog.dropNamespace(Namespace.of("db.ns1"))); AssertHelpers.assertThrows("Should fail to drop namespace exist" + namespace, NoSuchNamespaceException.class, "Namespace does not exist: ", () -> { catalog.loadNamespaceMetadata(namespace); }); }
@Override public boolean dropNamespace(Namespace namespace) { if (!isValidateNamespace(namespace)) { return false; } try { clients.run(client -> { client.dropDatabase(namespace.level(0), false , false , false ); return null; }); return true; } catch (InvalidOperationException e) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty. One or more tables exist.", e); } catch (NoSuchObjectException e) { return false; } catch (TException e) { throw new RuntimeException("Failed to drop namespace " + namespace + " in Hive MataStore", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted in call to drop dropDatabase(name) " + namespace + " in Hive MataStore", e); } }
HiveCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { if (!isValidateNamespace(namespace)) { return false; } try { clients.run(client -> { client.dropDatabase(namespace.level(0), false , false , false ); return null; }); return true; } catch (InvalidOperationException e) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty. One or more tables exist.", e); } catch (NoSuchObjectException e) { return false; } catch (TException e) { throw new RuntimeException("Failed to drop namespace " + namespace + " in Hive MataStore", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted in call to drop dropDatabase(name) " + namespace + " in Hive MataStore", e); } } }
HiveCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { if (!isValidateNamespace(namespace)) { return false; } try { clients.run(client -> { client.dropDatabase(namespace.level(0), false , false , false ); return null; }); return true; } catch (InvalidOperationException e) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty. One or more tables exist.", e); } catch (NoSuchObjectException e) { return false; } catch (TException e) { throw new RuntimeException("Failed to drop namespace " + namespace + " in Hive MataStore", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted in call to drop dropDatabase(name) " + namespace + " in Hive MataStore", e); } } HiveCatalog(Configuration conf);  HiveCatalog(String name, String uri, int clientPoolSize, Configuration conf); }
HiveCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { if (!isValidateNamespace(namespace)) { return false; } try { clients.run(client -> { client.dropDatabase(namespace.level(0), false , false , false ); return null; }); return true; } catch (InvalidOperationException e) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty. One or more tables exist.", e); } catch (NoSuchObjectException e) { return false; } catch (TException e) { throw new RuntimeException("Failed to drop namespace " + namespace + " in Hive MataStore", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted in call to drop dropDatabase(name) " + namespace + " in Hive MataStore", e); } } HiveCatalog(Configuration conf);  HiveCatalog(String name, String uri, int clientPoolSize, Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier originalTo); @Override void createNamespace(Namespace namespace, Map<String, String> meta); @Override List<Namespace> listNamespaces(Namespace namespace); @Override boolean dropNamespace(Namespace namespace); @Override boolean setProperties(Namespace namespace,  Map<String, String> properties); @Override boolean removeProperties(Namespace namespace,  Set<String> properties); @Override Map<String, String> loadNamespaceMetadata(Namespace namespace); @Override TableOperations newTableOps(TableIdentifier tableIdentifier); @Override void close(); }
HiveCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { if (!isValidateNamespace(namespace)) { return false; } try { clients.run(client -> { client.dropDatabase(namespace.level(0), false , false , false ); return null; }); return true; } catch (InvalidOperationException e) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty. One or more tables exist.", e); } catch (NoSuchObjectException e) { return false; } catch (TException e) { throw new RuntimeException("Failed to drop namespace " + namespace + " in Hive MataStore", e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException( "Interrupted in call to drop dropDatabase(name) " + namespace + " in Hive MataStore", e); } } HiveCatalog(Configuration conf);  HiveCatalog(String name, String uri, int clientPoolSize, Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier originalTo); @Override void createNamespace(Namespace namespace, Map<String, String> meta); @Override List<Namespace> listNamespaces(Namespace namespace); @Override boolean dropNamespace(Namespace namespace); @Override boolean setProperties(Namespace namespace,  Map<String, String> properties); @Override boolean removeProperties(Namespace namespace,  Set<String> properties); @Override Map<String, String> loadNamespaceMetadata(Namespace namespace); @Override TableOperations newTableOps(TableIdentifier tableIdentifier); @Override void close();  }