apache/iceberg · error · NoSuchNamespaceException

NoSuchNamespaceException(namespace)

Error message

NoSuchNamespaceException(namespace)

What it means

SupportsFunctions.listFunctions() returns function identifiers for a namespace; if the namespace neither exists nor contains functions, it throws NoSuchNamespaceException(namespace). The catalog adapter signals that the given multi-part namespace (database/schema path) is unknown to the underlying catalog.

Source

Thrown at spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SupportsFunctions.java:49

  default boolean isFunctionNamespace(String[] namespace) {
    return namespace.length == 0;
  }

  default boolean isExistingNamespace(String[] namespace) {
    return namespace.length == 0;
  }

  @Override
  default Identifier[] listFunctions(String[] namespace) throws NoSuchNamespaceException {
    if (isFunctionNamespace(namespace)) {
      return SparkFunctions.list().stream()
          .map(name -> Identifier.of(namespace, name))
          .toArray(Identifier[]::new);
    } else if (isExistingNamespace(namespace)) {
      return new Identifier[0];
    }

    throw new NoSuchNamespaceException(namespace);
  }

  @Override
  default UnboundFunction loadFunction(Identifier ident) throws NoSuchFunctionException {
    String[] namespace = ident.namespace();
    String name = ident.name();

    if (isFunctionNamespace(namespace)) {
      UnboundFunction func = SparkFunctions.load(name);
      if (func != null) {
        return func;
      }
    }

    throw new NoSuchFunctionException(
        String.format("Cannot load function: %s.%s", name(), ident), Option.empty());
  }
}

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Verify the namespace exists with catalog.namespaceExists(Identifier.of(namespace)) or SHOW NAMESPACES before listing functions
  2. Correct the namespace spelling/parts in the identifier or SQL statement
  3. Catch NoSuchNamespaceException and surface a user-friendly 'unknown namespace' message

Example fix

// before
Identifier[] fns = catalog.listFunctions(Identifier.of(new String[]{"mydb"}));
// after
Identifier ns = Identifier.of(new String[]{"mydb"});
if (catalog.namespaceExists(ns)) {
  Identifier[] fns = catalog.listFunctions(ns);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!catalog.namespaceExists(Identifier.of(namespace))) {
  throw new IllegalArgumentException("Namespace does not exist: " + String.join(".", namespace));
}

Type guard

boolean namespaceExists = false;
try { catalog.listNamespaces(Identifier.of(Arrays.copyOf(namespace, namespace.length - 1))).contains(namespace[namespace.length - 1]); namespaceExists = true; } catch (NoSuchNamespaceException ignored) {}

Try / catch

try {
  return catalog.listFunctions(Identifier.of(namespace));
} catch (NoSuchNamespaceException e) {
  throw new IllegalArgumentException("Unknown namespace: " + String.join(".", namespace), e);
}

Prevention

When it happens

Trigger: Calling listFunctions(Identifier) with a namespace array that does not match any existing namespace in the catalog — e.g. listFunctions(Identifier.of(new String[]{"no_such_db"}, "*")) or a mistyped schema name in SQL SHOW FUNCTIONS IN db.

Common situations: Typos in schema/database names in Spark SQL; querying functions under a namespace in a catalog where it was dropped or never created; cross-catalog confusion (namespace exists in another catalog).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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