Skip to content

Iceberg REST catalog: metadata tables (.snapshots, .files, .history) fail with "Schema not found" #1983

Closed

Description

@lisancao

Describe the bug

Querying an Iceberg metadata table through the Iceberg REST catalog fails. From Spark:

SELECT snapshot_id, operation FROM uc.bronze.orders.snapshots;
-- org.apache.iceberg.exceptions.NoSuchNamespaceException: Schema not found: iceberg.bronze.orders

The same happens for .files, .history, .manifests and the rest. The base table loads fine.

Iceberg's REST client resolves a metadata table by retrying a failed loadTable: it first asks for namespace bronze<0x1F>orders, table snapshots, and when that comes back as NoSuchTableException it loads bronze.orders and returns its snapshots table (RESTSessionCatalog.loadTable). Unity Catalog answers the first request with NoSuchNamespaceException, because the schema lookup fails before the table lookup, so the client never retries. The REST spec answers loadTable (and the other routes addressed to one table) with NoSuchTableException.

With authorization on, the request fails the same way, earlier: resolving the request's securables looks the table up before the handler runs.

To Reproduce

  1. Unity Catalog v0.7.0, a catalog with a storage root, and an Iceberg table created through the REST catalog (CREATE TABLE uc.bronze.orders ... USING iceberg, one INSERT).
  2. Spark 4.1.0 with iceberg-spark-runtime-4.1_2.13:1.12.0, catalog uc of type=rest pointed at /api/2.1/unity-catalog/iceberg.
  3. SELECT * FROM uc.bronze.orders.snapshots.

Or directly:

curl -s "http://localhost:8080/api/2.1/unity-catalog/iceberg/v1/catalogs/uc/namespaces/bronze%1Forders/tables/snapshots"
# {"error":{"message":"Schema not found: uc.bronze.orders","type":"NoSuchNamespaceException","code":404}}

Expected behavior

404 with type NoSuchTableException, so the client loads bronze.orders and returns its snapshots table. Namespace routes (and listing/creating tables in a namespace) should keep answering NoSuchNamespaceException for a missing namespace.

System

  • Unity Catalog v0.7.0 (built from the tag; also on main at 45c6397)
  • Spark 4.1.0, Iceberg 1.12.0, Linux

Additional context

The same answer makes the Iceberg client's dropTable on a missing namespace throw instead of returning false. A fix with tests is ready (PR to follow).

Activity

  1. newfront commented on Oct 14, 2026

    @newfront
    Collaborator

    Thanks @lisancao.

  2. newfront commented on Oct 14, 2026

    @newfront
    Collaborator

    Additional Notes for this one.

    UC 0.7.0: Spark can't read Iceberg metadata tables (t.snapshots) through the Iceberg REST catalog

    Triage write-up, Oct 13, 2026. Found while building the UC 0.7 native Iceberg notebooks in open-lakehouse/unitycatalog-playground.

    Summary

    From Spark, SELECT * FROM unity.iceberg_spark.adoptions.snapshots fails against Unity Catalog 0.7.0 with:

    org.apache.iceberg.exceptions.NoSuchNamespaceException: Schema not found: unity.iceberg_spark.adoptions
    

    Iceberg's Java REST client resolves <table>.snapshots by first asking the catalog for a table named snapshots in a namespace called iceberg_spark.adoptions. It falls back to the metadata table only when the server answers NoSuchTableException. For a namespace that doesn't exist, UC's loadTable answers NoSuchNamespaceException instead, so the fallback never runs.

    The Iceberg REST spec lists NoSuchTableException as the only 404 for loadTable, and Iceberg's reference server deliberately returns it for exactly this case. UC is the one off-spec here. The fix is likely small and server-side.

    This affects more than metadata tables: branch and snapshot selectors in a table name, and the changelog procedure, fail the same way.

    Environment

    Component Version
    Unity Catalog server newfrontdocker/unitycatalog:v0.7.0 (sha256:cdacdc5e7624795e7b2a18ece0d7357c5a1ec640db17fccb4d0fb208dd0d335b, built 2026-10-13), unitycatalog-server-0.7.0.jar
    Spark 4.1.3 with iceberg-spark-runtime-4.1_2.13:1.11.0
    PyIceberg 0.12.0
    UC config server.authorization=disable, Postgres metadata store, RustFS (S3-compatible) storage

    The same behavior was seen on the earlier v0.7.0-SNAPSHOT image.

    Impact

    Tested from Spark against a managed Iceberg table (unity.iceberg_spark.adoptions):

    Feature Example UC 0.7.0
    Metadata tables SELECT * FROM t.snapshots Fails
    Metadata tables through the DataFrame API spark.table("...adoptions.snapshots"), spark.read.format("iceberg").load("...adoptions.snapshots") Fails
    Snapshot selector in the table name SELECT * FROM t.snapshot_id_<id> Fails
    Branch selector in the table name SELECT * FROM t.branch_main Fails
    Changelog procedure CALL unity.system.create_changelog_view(table => ...) Fails
    Time travel clause SELECT ... VERSION AS OF <id> Works
    Lineage procedure CALL unity.system.ancestors_of(...) Works
    Metadata columns _file, _partition, _spec_id Works
    PyIceberg table.inspect.snapshots(), .files(), .history(), ... Works
    • Metadata tables: only snapshots was tested through the catalog. All the others (history, files, manifests, partitions, refs, entries, all_*, ...) go through the same lookup, so they should fail the same way.
    • Branch writes: writing to a branch by name (INSERT INTO t.branch_<name>) uses the same lookup and is likely affected too, but wasn't tested.
    • PyIceberg: works because it loads the base table by its real name and builds metadata tables on the client, so the ambiguous lookup never reaches the server.
    • Other engines: Flink, Trino and others weren't tested. Any engine that uses Iceberg Java's RESTSessionCatalog gets the same fallback logic.

    Reproduce

    Using the playground: run just uc=local start, then run the Spark Iceberg notebook once to create unity.iceberg_spark.adoptions. Any Iceberg table in UC works the same way.

    1. The HTTP request the Iceberg client makes. Iceberg REST paths separate nested namespace levels with %1F.

    # Control: the table exists
    curl -s -o /dev/null -w "%{http_code}\n" \
      "http://localhost:8080/api/2.1/unity-catalog/iceberg/v1/catalogs/unity/namespaces/iceberg_spark/tables/adoptions"
    # 200
    
    # What Spark sends for unity.iceberg_spark.adoptions.snapshots
    curl -s "http://localhost:8080/api/2.1/unity-catalog/iceberg/v1/catalogs/unity/namespaces/iceberg_spark%1Fadoptions/tables/snapshots"
    # {"error":{"message":"Schema not found: unity.iceberg_spark.adoptions","type":"NoSuchNamespaceException","code":404}}

    Expected: a 404 with "type":"NoSuchTableException". Keeping the message text is fine.

    2. From Spark (Spark session with unity set up as an Iceberg REST SparkCatalog pointed at UC):

    spark.sql("SELECT * FROM unity.iceberg_spark.adoptions.snapshots").show()
    # org.apache.iceberg.exceptions.NoSuchNamespaceException: Schema not found: unity.iceberg_spark.adoptions

    Root cause

    Client side: Iceberg only falls back on NoSuchTableException

    A name like ns.table.snapshots is ambiguous: it could be a table named snapshots in nested namespace ns.table. Iceberg's REST client tries that first, and treats the last part as a metadata table only if the server says "no such table" (RESTSessionCatalog.java#L484):

    } catch (NoSuchTableException original) {
      metadataType = MetadataTableType.from(identifier.name());
      if (metadataType != null) {
        // attempt to load a metadata table using the identifier's namespace as the base table
        TableIdentifier baseIdent = TableIdentifier.of(identifier.namespace().levels());

    The client picks the exception from the error type in the response. A 404 typed NoSuchNamespaceException becomes a NoSuchNamespaceException, which isn't caught above (ErrorHandlers.java#L142-L162).

    Spark's SparkCatalog has a second fallback with the same check, for snapshot/branch selectors and the changelog table (SparkCatalog.java#L808-L821). That's why t.branch_main, t.snapshot_id_<id> and create_changelog_view break too.

    Spec and reference implementation: loadTable should answer NoSuchTableException

    • The REST spec gives loadTable exactly one 404: "Not Found - NoSuchTableException, table to load does not exist" (rest-catalog-open-api.yaml#L1011).

    • Iceberg's reference server handles this case explicitly (CatalogHandlers.java#L538-L541):

      } else if (table instanceof BaseMetadataTable) {
        // metadata tables are loaded on the client side, return NoSuchTableException for now
        throw new NoSuchTableException("Table does not exist: %s", ident.toString());
      }

    Server side: UC reports the missing schema as NoSuchNamespaceException

    The UC server source ships in the image under /home/unitycatalog/server/src/main/java/io/unitycatalog/server/. Paths below are relative to that directory.

    1. loadTable looks up the table. service/IcebergRestCatalogService.java:362-376 (and tableExists, :345-360) calls tableRepository.getIcebergTableState(catalog, namespace, table).

    2. The lookup fails on the schema first. That calls findTableOrThrow (persist/TableRepository.java:705-716), which resolves the schema before the table. For namespace iceberg_spark.adoptions it throws BaseException(SCHEMA_NOT_FOUND, "Schema not found: unity.iceberg_spark.adoptions").

    3. The handler maps that to NoSuchNamespaceException. exception/IcebergRestExceptionHandler.java:80-82 turns the error code into an Iceberg error type:

      case CATALOG_NOT_FOUND, SCHEMA_NOT_FOUND -> NoSuchNamespaceException.class;
      case TABLE_NOT_FOUND -> NoSuchTableException.class;

    This mapping is intentional. The Javadoc on errorType (:48-65) explains that a missing catalog or schema should show up at the client as a missing namespace, not a missing table. That's right for namespace-level endpoints, where the spec allows NoSuchNamespaceException. It's wrong for loadTable, where the spec doesn't, and where Iceberg clients rely on NoSuchTableException to resolve metadata tables and selectors.

    Proposed fix

    On loadTable (and tableExists), report a missing schema as NoSuchTableException. Keep the message so users still see "Schema not found". Leave the namespace endpoints (listTables, getNamespace, createTable, ...) as they are.

    An illustrative sketch for IcebergRestCatalogService.loadTable / tableExists:

    TableRepository.IcebergTableState state;
    try {
      state = tableRepository.getIcebergTableState(catalog, namespace, table);
    } catch (BaseException e) {
      if (e.getErrorCode() == ErrorCode.SCHEMA_NOT_FOUND) {
        // The REST spec answers loadTable with NoSuchTableException only. Iceberg clients rely on it
        // to resolve metadata tables (ns.table.snapshots) and Spark selectors (ns.table.branch_x).
        throw new NoSuchTableException("%s", e.getErrorMessage());
      }
      throw e;
    }

    The handler already maps an org.apache.iceberg.exceptions.NoSuchTableException to a 404 typed NoSuchTableException; that's what loadTable returns today for a missing table in an existing schema.

    Suggested regression tests:

    • GET .../namespaces/<existing_schema>%1F<existing_table>/tables/snapshots returns 404 with type=NoSuchTableException.
    • From Spark against UC: SELECT * FROM t.snapshots, SELECT * FROM t.branch_main and CALL system.create_changelog_view(...) all succeed.

    Open questions for the team

    1. Auth-enabled servers. With server.authorization=enable, the authorization layer resolves catalog.schema.table to IDs before the handler runs (auth/decorator/KeyMapper.java:147-156, via tableRepository.getTable). That path probably raises the same not-found error before loadTable's body runs, in which case a handler-only fix wouldn't cover it. Not tested: the playground runs with auth disabled.
    2. Is NoSuchNamespaceException from loadTable relied on anywhere? For example, UC tests or UC's own clients. If so, this change would need to update them.
    3. Same treatment for other table endpoints? The credentials endpoint (:411) and metrics endpoint (:867) use the same lookup. They aren't involved in metadata-table resolution, but consistency may be worth it.
    4. Existing upstream issue? I haven't checked whether there's already an issue or PR for this.

    Workarounds in use today

    • Lineage and time travel: the playground's Spark notebook uses CALL unity.system.ancestors_of(...), VERSION AS OF <snapshot_id>, and the _file / _partition / _spec_id metadata columns.
    • Metadata tables: the PyIceberg notebook uses table.inspect.*.

    ancestors_of doesn't replace snapshots. It only walks the current lineage, so after a CREATE OR REPLACE TABLE it returns 6 rows where snapshots returns 18.

    Spark-only escape hatch (not recommended). Loading by file path bypasses the catalog and works:

    spark.read.format("iceberg").load(f"{metadata_location}#snapshots")

    It needs hadoop-aws, s3:// mapped to S3A, and the table's metadata-location plus vended S3 credentials taken from UC's REST loadTable response. Spark doesn't expose either. The result is a fixed point-in-time view, and the credentials don't refresh. It works as a diagnostic: the metadata is fine, and only the name lookup is broken.

    When this is fixed upstream, remove the corresponding row in the playground's AGENTS.md ("Upstream 0.7.0 issues") and the note in notebooks/iceberg/unitycatalog-iceberg-spark.py, and add a Spark t.snapshots cell.

  3. added a commit that references this issue on Oct 23, 2026
    d326d7e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions