Skip to content

Commit

Permalink
Implement dropNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
MarigWeizhi committed Dec 10, 2024
1 parent 2298331 commit 1c0e574
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class SparkUnifiedCatalogBase implements TableCatalog, SupportsNamespaces
TableFormat.MIXED_ICEBERG, "org.apache.amoro.spark.MixedFormatSparkCatalog",
TableFormat.PAIMON, "org.apache.paimon.spark.SparkCatalog");

private UnifiedCatalog unifiedCatalog;
protected UnifiedCatalog unifiedCatalog;
private String name;
private final Map<TableFormat, SparkTableFormat> tableFormats = Maps.newConcurrentMap();
private final Map<TableFormat, TableCatalog> tableCatalogs = Maps.newConcurrentMap();
Expand Down Expand Up @@ -128,7 +128,7 @@ public String name() {
return name;
}

private String namespaceToDatabase(String[] namespace) {
protected String namespaceToDatabase(String[] namespace) {
Preconditions.checkArgument(namespace.length == 1, "only support namespace with 1 level.");
return namespace[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.amoro.spark;

import org.apache.amoro.TableFormat;
import org.apache.amoro.TableIDWithFormat;
import org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException;
import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
Expand All @@ -31,6 +32,8 @@
import org.apache.spark.sql.connector.catalog.functions.UnboundFunction;
import org.apache.spark.sql.connector.iceberg.catalog.ProcedureCatalog;

import java.util.List;

public class SparkUnifiedCatalog extends SparkUnifiedCatalogBase
implements TableCatalog, SupportsNamespaces, ProcedureCatalog, FunctionCatalog {

Expand Down Expand Up @@ -86,7 +89,20 @@ public UnboundFunction loadFunction(Identifier ident) throws NoSuchFunctionExcep
@Override
public boolean dropNamespace(String[] namespace, boolean cascade)
throws NoSuchNamespaceException, NonEmptyNamespaceException {
return false;
String database = namespaceToDatabase(namespace);
if (!unifiedCatalog.databaseExists(database)) {
throw new NoSuchNamespaceException(namespace);
}
List<TableIDWithFormat> tables = unifiedCatalog.listTables(database);
if (!tables.isEmpty() && !cascade) {
throw new NonEmptyNamespaceException(namespace);
}

for (TableIDWithFormat id : tables) {
unifiedCatalog.dropTable(database, id.getIdentifier().getTableName(), true);
}
unifiedCatalog.dropDatabase(database);
return !unifiedCatalog.databaseExists(database);
}

/**
Expand Down

0 comments on commit 1c0e574

Please sign in to comment.