@Test public void testCreateNamespace() throws Exception { Configuration conf = new Configuration(); String warehousePath = temp.newFolder().getAbsolutePath(); HadoopCatalog catalog = new HadoopCatalog(conf, warehousePath); TableIdentifier tbl1 = TableIdentifier.of("db", "ns1", "ns2", "metadata"); TableIdentifier tbl2 = TableIdentifier.of("db", "ns2", "ns3", "tbl2"); Lists.newArrayList(tbl1, tbl2).forEach(t -> catalog.createNamespace(t.namespace(), meta) ); String metaLocation1 = warehousePath + "/" + "db/ns1/ns2"; FileSystem fs1 = Util.getFs(new Path(metaLocation1), conf); Assert.assertTrue(fs1.isDirectory(new Path(metaLocation1))); String metaLocation2 = warehousePath + "/" + "db/ns2/ns3"; FileSystem fs2 = Util.getFs(new Path(metaLocation2), conf); Assert.assertTrue(fs2.isDirectory(new Path(metaLocation2))); AssertHelpers.assertThrows("Should fail to create when namespace already exist: " + tbl1.namespace(), org.apache.iceberg.exceptions.AlreadyExistsException.class, "Namespace already exists: " + tbl1.namespace(), () -> { catalog.createNamespace(tbl1.namespace()); }); }
@Override public void createNamespace(Namespace namespace, Map<String, String> meta) { Preconditions.checkArgument( !namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace); if (!meta.isEmpty()) { throw new UnsupportedOperationException("Cannot create namespace " + namespace + ": metadata is not supported"); } Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (isNamespace(nsPath)) { throw new AlreadyExistsException("Namespace already exists: %s", namespace); } try { fs.mkdirs(nsPath); } catch (IOException e) { throw new RuntimeIOException(e, "Create namespace failed: %s", namespace); } }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public void createNamespace(Namespace namespace, Map<String, String> meta) { Preconditions.checkArgument( !namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace); if (!meta.isEmpty()) { throw new UnsupportedOperationException("Cannot create namespace " + namespace + ": metadata is not supported"); } Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (isNamespace(nsPath)) { throw new AlreadyExistsException("Namespace already exists: %s", namespace); } try { fs.mkdirs(nsPath); } catch (IOException e) { throw new RuntimeIOException(e, "Create namespace failed: %s", namespace); } } }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public void createNamespace(Namespace namespace, Map<String, String> meta) { Preconditions.checkArgument( !namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace); if (!meta.isEmpty()) { throw new UnsupportedOperationException("Cannot create namespace " + namespace + ": metadata is not supported"); } Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (isNamespace(nsPath)) { throw new AlreadyExistsException("Namespace already exists: %s", namespace); } try { fs.mkdirs(nsPath); } catch (IOException e) { throw new RuntimeIOException(e, "Create namespace 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 void createNamespace(Namespace namespace, Map<String, String> meta) { Preconditions.checkArgument( !namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace); if (!meta.isEmpty()) { throw new UnsupportedOperationException("Cannot create namespace " + namespace + ": metadata is not supported"); } Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (isNamespace(nsPath)) { throw new AlreadyExistsException("Namespace already exists: %s", namespace); } try { fs.mkdirs(nsPath); } catch (IOException e) { throw new RuntimeIOException(e, "Create namespace 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 void createNamespace(Namespace namespace, Map<String, String> meta) { Preconditions.checkArgument( !namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace); if (!meta.isEmpty()) { throw new UnsupportedOperationException("Cannot create namespace " + namespace + ": metadata is not supported"); } Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); if (isNamespace(nsPath)) { throw new AlreadyExistsException("Namespace already exists: %s", namespace); } try { fs.mkdirs(nsPath); } catch (IOException e) { throw new RuntimeIOException(e, "Create namespace 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();  }