apache/iceberg · error · NoSuchNamespaceException

Namespace does not exist: %s

Error message

Namespace does not exist: %s

What it means

HadoopCatalog.listTables(namespace) resolves the namespace to a directory under the warehouse location; if that directory does not exist on the filesystem it throws NoSuchNamespaceException. This is the catalog's way of reporting that the namespace (database) has never been created or was removed.

Source

Thrown at core/src/main/java/org/apache/iceberg/hadoop/HadoopCatalog.java:200

        LOG.warn("Unable to list directory {}", path, e);
        return false;
      } else {
        throw new UncheckedIOException(e);
      }
    }
  }

  @Override
  public List<TableIdentifier> listTables(Namespace namespace) {
    Preconditions.checkArgument(
        namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace);

    Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels()));
    Set<TableIdentifier> tblIdents = Sets.newHashSet();

    try {
      if (!isDirectory(nsPath)) {
        throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
      }
      RemoteIterator<FileStatus> it = fs.listStatusIterator(nsPath);
      while (it.hasNext()) {
        FileStatus status = it.next();
        if (!status.isDirectory()) {
          // Ignore the path which is not a directory.
          continue;
        }

        Path path = status.getPath();
        if (isTableDir(path)) {
          TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName());
          tblIdents.add(tblIdent);
        }
      }
    } catch (IOException ioe) {
      throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace);
    }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Verify the namespace exists: catalog.listNamespaces() or create it with catalog.createNamespace(namespace) if missing.
  2. Check for typos and case mismatches in the namespace levels.
  3. Confirm warehouseLocation in the HadoopCatalog configuration still points to the original warehouse root.
  4. If the namespace was deleted, recreate it before listing tables.

Example fix

// before
List<TableIdentifier> tables = catalog.listTables(TableIdentifier.of("db")); // NoSuchNamespaceException
// after
if (!catalog.namespaceExists(TableIdentifier.of("db"))) {
  catalog.createNamespace(TableIdentifier.of("db"));
}
List<TableIdentifier> tables = catalog.listTables(TableIdentifier.of("db"));
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = catalog.listNamespaces().stream()
    .anyMatch(ns -> ns.equals(namespace));
if (!exists) catalog.createNamespace(namespace);

Try / catch

try {
  return catalog.listTables(namespace);
} catch (NoSuchNamespaceException e) {
  LOG.warn("namespace {} not found under current warehouseLocation", namespace);
  throw e;
}

Prevention

When it happens

Trigger: Calling listTables on a namespace whose directory is absent under warehouseLocation — typo'd namespace levels, namespace never created via createNamespace, or a moved/reconfigured warehouseLocation.

Common situations: warehouseLocation changed in catalog config so existing namespaces resolve to new paths; case-sensitivity mismatches (HDFS/S3 paths are case-sensitive); namespace deleted by another job; typo in namespace string.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/8d852830b8ba6ba1. Report an issue: GitHub.