@Test public void testDropNamespace() throws IOException { Configuration conf = new Configuration(); String warehousePath = temp.newFolder().getAbsolutePath(); HadoopCatalog catalog = new HadoopCatalog(conf, warehousePath); Namespace namespace1 = Namespace.of("db"); Namespace namespace2 = Namespace.of("db", "ns1"); TableIdentifier tbl1 = TableIdentifier.of(namespace1, "tbl1"); TableIdentifier tbl2 = TableIdentifier.of(namespace2, "tbl1"); Lists.newArrayList(tbl1, tbl2).forEach(t -> catalog.createTable(t, SCHEMA, PartitionSpec.unpartitioned()) ); AssertHelpers.assertThrows("Should fail to drop namespace is not empty " + namespace1, NamespaceNotEmptyException.class, "Namespace " + namespace1 + " is not empty.", () -> { catalog.dropNamespace(Namespace.of("db")); }); Assert.assertFalse("Should fail to drop namespace doesn't exist", catalog.dropNamespace(Namespace.of("db2"))); Assert.assertTrue(catalog.dropTable(tbl1)); Assert.assertTrue(catalog.dropTable(tbl2)); Assert.assertTrue(catalog.dropNamespace(namespace2)); Assert.assertTrue(catalog.dropNamespace(namespace1)); String metaLocation = warehousePath + "/" + "db"; FileSystem fs = Util.getFs(new Path(metaLocation), conf); Assert.assertFalse(fs.isDirectory(new Path(metaLocation))); }
@Override public boolean dropNamespace(Namespace namespace) { Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (!isNamespace(nsPath) || namespace.isEmpty()) { return false; } try { if (fs.listStatusIterator(nsPath).hasNext()) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty."); } return fs.delete(nsPath, false ); } catch (IOException e) { throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace); } }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (!isNamespace(nsPath) || namespace.isEmpty()) { return false; } try { if (fs.listStatusIterator(nsPath).hasNext()) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty."); } return fs.delete(nsPath, false ); } catch (IOException e) { throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace); } } }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (!isNamespace(nsPath) || namespace.isEmpty()) { return false; } try { if (fs.listStatusIterator(nsPath).hasNext()) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty."); } return fs.delete(nsPath, false ); } catch (IOException e) { throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace); } } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (!isNamespace(nsPath) || namespace.isEmpty()) { return false; } try { if (fs.listStatusIterator(nsPath).hasNext()) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty."); } return fs.delete(nsPath, false ); } catch (IOException e) { throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace); } } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override Table createTable(
      TableIdentifier identifier, Schema schema, PartitionSpec spec, String location, Map<String, String> properties); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier to); @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 void close(); }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public boolean dropNamespace(Namespace namespace) { Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (!isNamespace(nsPath) || namespace.isEmpty()) { return false; } try { if (fs.listStatusIterator(nsPath).hasNext()) { throw new NamespaceNotEmptyException("Namespace " + namespace + " is not empty."); } return fs.delete(nsPath, false ); } catch (IOException e) { throw new RuntimeIOException(e, "Namespace delete failed: %s", namespace); } } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override Table createTable(
      TableIdentifier identifier, Schema schema, PartitionSpec spec, String location, Map<String, String> properties); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier to); @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 void close();  }