Skip to content

[Server] Report a missing namespace as a missing table on table routes of the Iceberg REST catalog - #1984

Merged
yili-db merged 4 commits into
unitycatalog:mainfrom
lisancao:fix/irc-loadtable-missing-namespace
Oct 23, 2026
Merged

yili-db merged 4 commits into
unitycatalog:mainfrom
lisancao:fix/irc-loadtable-missing-namespace

Conversation

@lisancao

@lisancao lisancao commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

Description of changes

Iceberg metadata tables (db.orders.snapshots, .files, .history, ...) can't be queried through the Iceberg REST catalog today. Iceberg's client resolves one by retrying a failed loadTable for namespace db<0x1F>orders, table snapshots, but only when that first answer is NoSuchTableException. Unity Catalog answers NoSuchNamespaceException, since the schema lookup fails first, so in Spark the query fails with "Schema not found: .db.orders".

The REST spec answers the routes addressed to one table with NoSuchTableException. This change makes the Iceberg routes' exception handler report SCHEMA_NOT_FOUND as TABLE_NOT_FOUND on the routes that bind a {table} path parameter (load, exists, drop, commit, credentials, metrics), with the message Table does not exist: <namespace>.<table> and the original exception as the cause. It's decided in the handler rather than in each service method because, with authorization on, the schema lookup fails while resolving securables, before the method runs. Namespace routes and listing or creating tables keep reporting a missing namespace as one. A staged-create commit (POST .../tables/{table} with assert-create) into a missing schema also gets the table-level 404; Iceberg's client stages through createTable first, so it doesn't reach that path in practice.

User-facing: metadata tables work from Spark (verified end to end against a SeaweedFS-backed stack: .snapshots, .files and .history all return rows), and the Iceberg client's dropTable on a missing namespace returns false instead of throwing. In the Spark connector, DROP TABLE cat.a.b.c on a missing namespace now reports TABLE_OR_VIEW_NOT_FOUND instead of "Schema not found"; BaseTableReadWriteTest is updated to that.

Tests:

  • IcebergRestCatalogTest.testTableRoutesReportAMissingNamespaceAsAMissingTable: load, credentials, drop, commit and metrics on a metadata-table identifier answer NoSuchTableException (load also checks the message); listTables and createTable on the missing namespace still answer NoSuchNamespaceException; Iceberg's own RESTCatalog loads schema.table.snapshots as a SnapshotsTable. The table-route probes fail on the merge base.
  • SdkIcebergRestCatalogAccessControlTest: the same probe with authorization on, checking the error type.
  • Run: server/test (765 passed, 2 skipped), and the Spark connector's *TableReadWriteTest on Spark 4.0.0 and 4.1.0 with Delta 4.3.1 (100 passed, 6 skipped each), plus javafmtCheckAll.

This PR was written with help from Claude (Anthropic); I reviewed the change and ran the tests.

Fixes #1983

…s of the Iceberg REST catalog

Iceberg's REST client resolves metadata tables by retrying a failed loadTable: when
`db.orders.snapshots` comes back as NoSuchTableException, it loads `db.orders` and
returns its `snapshots` table. Unity Catalog answered that first request (namespace
`db<0x1F>orders`, table `snapshots`) with NoSuchNamespaceException, because the
schema lookup fails before the table lookup. The client does not retry on that type,
so every metadata table (`.snapshots`, `.files`, `.history`, `.manifests`, ...) failed
in Spark with "Schema not found: <catalog>.db.orders". The same answer made the
client's dropTable throw instead of returning false.

The REST spec answers these routes with NoSuchTableException. The exception handler
for the Iceberg routes now reports SCHEMA_NOT_FOUND as TABLE_NOT_FOUND on routes
addressed to one table (load, exists, drop, commit, credentials, metrics). It is
decided from the route rather than in each handler because, with authorization on,
the schema lookup fails while resolving securables, before the handler runs.
Namespace routes and table listing/creation keep reporting NoSuchNamespaceException.

Tests: IcebergRestCatalogTest covers each table route and loads a real
SnapshotsTable through Iceberg's RESTCatalog; the access-control test covers the
authorization-on path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: lisancao <[email protected]>
private IcebergRestExceptionHandler() {}

/** A route addressed to one table: load, exists, drop, commit, its credentials and metrics. */
private static final Pattern TABLE_ROUTE =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lisancao Thank you very much for addressing this issue.

Why use a regex over the path at all? It's a second copy of the route definitions in IcebergRestCatalogService, and it can drift: when a new table route lands (e.g. scan planning), nothing forces anyone to update this pattern, and the bug quietly comes back on just that route.

Armeria already knows which route matched. Path params are bound at routing, before UnityAccessDecorator or the method runs (the decorator already reads them via ctx.pathParam(...)). Every route this pattern matches has a {table} path param, and no other route does (rename takes the table from the body, views use {view}). So this expresses the same rule, "the request names a table", without duplicating the routes:

if (exception.getErrorCode() == ErrorCode.SCHEMA_NOT_FOUND && ctx.pathParam("table") != null) {

That lets you drop TABLE_ROUTE, its Javadoc, and the Pattern import. Converting the error here in the Iceberg handler, rather than where SCHEMA_NOT_FOUND is thrown, still makes sense to me, since the native REST surface should keep reporting a missing schema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the second copy of the routes was the weak part. It now checks ctx.pathParam("table") != null, which is exactly the set of routes addressed to one table (load, exists, drop, commit, credentials, metrics). Rename reads its tables from the body and views bind view, so those are unchanged, and a new table route is covered without touching this class. In 1f2697b.

"Table does not exist: " + table,
new NoSuchTableException("Table does not exist: %s", table));
}
return createErrorResponse(exception);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After replacing the exception with NoSuchTableException, can you call:

return super.handleException(...);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it ends with return super.handleException(ctx, req, exception) now. In 1f2697b.

@yili-db

yili-db commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@lisancao Please also check the failures in CI. Some tests need to be updated.

@timothyw553 timothyw553 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR @lisancao i left some comments.

Comment on lines +197 to +200
assertIcebergApiException(
() -> admin.loadTable(CAT, SCHEMA + "%1F" + "tbl_sel", "snapshots"),
404,
"Table does not exist");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the helper checks the HTTP status, response code, and message. it does not check error.type, which is the field this fix depends on

you can add like this

     assertIcebergApiException(
         () -> admin.loadTable(CAT, SCHEMA + "%1F" + "tbl_sel", "snapshots"),
         404,
+        NoSuchTableException.class,
         "Table does not exist");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an assertIcebergApiException(executable, status, Class, message) overload in TestUtils that checks error.type() against the simple name, and this assertion now expects NoSuchTableException. In 1f2697b.

wrapException(
ErrorCode.TABLE_NOT_FOUND,
"Table does not exist: " + table,
new NoSuchTableException("Table does not exist: %s", table));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the missing-namespace explaantion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept. The message is now Table does not exist: ns.tbl (Schema not found: ...) and the original exception is the cause of the NoSuchTableException, so the response still says which namespace was missing. In 1f2697b.

Review follow-up. The handler matched the request path against a regex
that duplicated the route table in IcebergRestCatalogService; it now
checks whether the route bound a `table` path parameter, which is exactly
the set of routes addressed to one table (load, exists, drop, commit,
credentials, metrics). Rename reads its tables from the body and views
bind `view`, so they are unchanged, and a new table route is covered
without touching this class.

The rewrapped error keeps the original "Schema not found" message in
parentheses and carries the original exception as its cause, and the
handler ends with super.handleException so the base error path is the
only one.

Tests: the access-control assertion now also checks the Iceberg error
type is NoSuchTableException, through a new assertIcebergApiException
overload in TestUtils. The connector's `DROP TABLE cat.a.b.c` assertion
expected "Schema not found"; with this change Iceberg's client turns the
NoSuchTableException into dropTable returning false and Spark reports
TABLE_OR_VIEW_NOT_FOUND, so the assertion expects that.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: lisancao <[email protected]>
@lisancao

Copy link
Copy Markdown
Contributor Author

On CI: the connector failure was the DROP TABLE cat.a.b.c assertion in BaseTableReadWriteTest, which expected "Schema not found". That is the behaviour this PR changes: a missing namespace on a table route is now a NoSuchTableException, Iceberg's client turns that into dropTable returning false, and Spark reports TABLE_OR_VIEW_NOT_FOUND. 1f2697b updates the assertion to that. Locally the server Iceberg suites and ExternalTableReadWriteTest pass with the change.

@yili-db

yili-db commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Thanks for the quick turnaround, this is looking really good! Switching to ctx.pathParam("table") is much cleaner than the regex, keeping the original exception as the cause is a nice touch, and the end-to-end SnapshotsTable check through Iceberg's own RESTCatalog is a great regression test. I'm close to LGTM; the inline comments are mostly small.

On the description: it still says the rule is "decided from the route" and lists only server/testOnly *Iceberg* *ExceptionHandler*. Can you mention the Spark DROP TABLE a.b.c expectation change in BaseTableReadWriteTest and that the Spark suite was run? Optionally, one sentence noting that a staged-create commit (POST .../tables/{table} with assert-create) into a missing schema also gets the table-level 404 would keep the "creating tables keeps reporting a missing namespace" line accurate. In practice Iceberg's client stages through createTable first, so I don't think it needs code.

The failing [Non Blocking] Spark tests (Spark 4.3.0-SNAPSHOT, ...) job is unrelated: sbt fails to load the build definition before any test runs, and it fails the same way on main.

.isFalse();
// The namespace routes themselves still report a missing namespace as one.
assertErrorType(
() -> icebergClient.loadNamespace(TestUtils.CATALOG_NAME, nestedNamespace),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] loadNamespace has no /tables/ in its path, so no version of this change could break it. The routes that really need protecting are the namespace-addressed ones closest to the rule: can we assert listTables and createTable on nestedNamespace still answer NoSuchNamespaceException? And since the description lists commit and metrics, maybe add updateTable and reportMetrics probes expecting NoSuchTableException too. Then the test pins both sides of the rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped the loadNamespace probe for listTables and createTable on the missing namespace, which still answer NoSuchNamespaceException, and added updateTable and reportMetrics probes expecting NoSuchTableException. Each table-route probe fails on the merge base. In 3596d96.

() -> icebergClient.dropTable(TestUtils.CATALOG_NAME, nestedNamespace, "snapshots"),
404,
NoSuchTableException.class);
assertThat(icebergClient.tableExists(TestUtils.CATALOG_NAME, nestedNamespace, "snapshots"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] nit: HEAD has no body and the client returns false on any 404, so this passes with or without the change. Fine to keep as a smoke check, just noting it doesn't prove the error type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped it. Since the client returns false on any 404, it couldn't tell the two errors apart. In 3596d96.

BaseException exception = toBaseException(cause);
if (exception.getErrorCode() == ErrorCode.SCHEMA_NOT_FOUND && ctx.pathParam("table") != null) {
String table = ctx.pathParam("namespace") + "." + ctx.pathParam("table");
String message = "Table does not exist: " + table + " (" + exception.getErrorMessage() + ")";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] nit: the message now reads Table does not exist: schema\u001Ftbl.snapshots (Schema not found: uc_testcatalog.schema\u001Ftbl), so the namespace shows up twice and with the raw 0x1F separator (it ends up in Spark error text). Since the original exception is preserved as the cause now, could this be just "Table does not exist: " + table, with the namespace rendered using . in place of the separator? That matches what Iceberg's own catalogs say.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now Table does not exist: <namespace>.<table>, with the separator rendered as . the same way the URL transcoder does, matching the service's other NoSuchTableException messages. The loadTable probe asserts the text. In b2ec1c5.

@timothyw553 this drops the (Schema not found: ...) suffix I kept after your earlier comment. The identifier still shows what was looked up, and the original exception is still the cause on the server.

message,
new NoSuchTableException(exception, "%s", message));
}
return super.handleException(ctx, req, exception);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] nit: super.handleException runs toBaseException again on an exception that's already normalized. Harmless today, but return createErrorResponse(exception); says exactly what's meant and doesn't depend on the mapping staying idempotent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it returns createErrorResponse(exception) now. In b2ec1c5.

Comment on lines +52 to +53
* reporting a missing namespace as one. Reading the parameter rather than matching the path means
* a new table route is covered without touching this class.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] nit: this sentence describes how the review went more than the code, and the Javadoc is now three paragraphs. Maybe drop it and keep the why (the client only retries as a metadata table on NoSuchTableException; authz resolves securables before the method runs) plus the list of routes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to the route list and the why: the client's metadata-table retry, and authorization resolving securables first. In b2ec1c5.

The message now reads "Table does not exist: <namespace>.<table>", with the
namespace separator rendered as "." like the service's own NoSuchTableException
messages; the original exception stays the cause. The response is built with
createErrorResponse, since the exception is already normalized.

Signed-off-by: lisancao <[email protected]>
Commit and metrics probes expect NoSuchTableException; listTables and
createTable on the missing namespace still expect NoSuchNamespaceException.
The loadTable probe checks the message. The HEAD probe is dropped: the client
returns false on any 404, so it passed with or without the change.

Signed-off-by: lisancao <[email protected]>
@yili-db

yili-db commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db
yili-db merged commit d326d7e into unitycatalog:main Oct 23, 2026
17 of 18 checks passed
shba24 added a commit to shba24/unitycatalog that referenced this pull request Oct 25, 2026
IcebergRestExceptionHandler now overrides handleException (unitycatalog#1984), so it
skips the base method that logs each 5xx. Log it there too.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Shubham Bansal <[email protected]>
yili-db pushed a commit that referenced this pull request Oct 25, 2026
**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

A failed request left no trace in the server log, and the log lines one
request wrote could not be told apart from another's. With this change:

- Each log line written while serving a request has `request_id=<id>`,
the ID Armeria generates for that request, and every line names the host
(with the shipped log4j2 configs).
- Each 5xx is logged once at `ERROR` with its cause, where the error
response is built (UC, Iceberg, Delta, SCIM).
- Database errors keep their cause. A failed rollback or session close
is attached to the error instead of replacing it, and a replay signal
whose rollback fails returns 500. A custom isolation level is no longer
restored by hand: Hikari resets it when the connection returns to the
pool.
- A failed policy-refresh read is a `WARN`, because revokes from other
instances stop arriving until a read succeeds.
- Bootstrap creates the admin only when the lookup returns not-found.
Any other error fails startup.

**Compatibility:** the API is unchanged; no request or response header
is added. The default log line format gains the host name and
`request_id=`, so log parsers that match the old pattern need updating.
The Helm chart copies the log4j2 config template instead of running
`envsubst` on it, so a `${VAR}` in it is now a Log4j lookup. A 4xx whose
rollback also fails now returns that 4xx; before, it returned 500. A
transaction with a custom isolation level no longer checks out a second
connection after it commits, so a committed write can no longer come
back as a 500 when that checkout fails. Startup now fails if the admin
lookup fails with anything other than not-found, instead of treating it
as "no admin yet". A SCIM create-user that fails in the database now
reports `"status":"500"` in the SCIM error body instead of `"400"`; the
HTTP status stays 500. Log levels that alerts may match on change: the
token-exchange lookup failure moves from `ERROR` with a stack trace to
`WARN` without one, and the Casbin policy-refresh read failures move
from `DEBUG` to `WARN`.

<details><summary>📐 Design notes & details</summary>

- **Request ID:** the Armeria request context's own ID.
`RequestContextDataProvider`, a Log4j `ContextDataProvider`, exports
fields of the current Armeria request through Armeria's
`RequestContextExporter`, the same exporter Armeria's Logback
integration uses. Today it exports only `request_id`; another field is
one more `builtIn(...)` entry. The Armeria context follows the request
onto the blocking executor, where a per-thread MDC would not.
- **No header:** neither the Iceberg REST spec nor `api/all.yaml` /
`api/delta.yaml` defines a request-ID header, so this PR doesn't read
one from callers or return one. That would be new API surface, and it
can come later through the spec if wanted.
- **One place to log:** `BaseExceptionHandler.handleException` (and the
Iceberg handler's override of it, from #1984), using the status the
dialect actually answers with (Delta has its own), so each 5xx is logged
once, with only its cause: the request ID on the line identifies the
request. Token exchange still names the failed lookup (email or client
ID), now as a `WARN` without the stack trace, so the cause isn't logged
twice. A rollback or session-close failure behind a 4xx or a replay
signal, which the handler doesn't log, is a `WARN` from
`TransactionManager`.
- **SCIM:** it answers every error with HTTP 500 (unchanged here) and
logs by the SCIM error's own status, so a duplicate user isn't an
`ERROR`. `createScimUser` labelled database errors 400 since #974
wrapped them as `BaseException(INTERNAL)`; they now map to
`ServerErrorException` with the cause, so they are logged.
- **Armeria flags:** when a `com.linecorp.armeria.*` property is set,
Armeria logs during startup before its context storage exists. The
provider returns no fields for those lines instead of throwing, and
builds the exporter only once a request is served, as Armeria's own
appender does.
- **Not in this PR:** JSON or stdout logging, a setting for the
log-config path, a build check for catch blocks that drop the exception,
the SCIM 500 status, and `DeltaPropertyMapper` dropping its cause.
- **Tests:** an end-to-end test in `AuthServiceTest` makes the database
reject a SCIM user insert and checks the 500 status in the body;
`TransactionManagerTest` fails each point in turn (isolation set,
operation, commit, rollback, session close) and checks the thrown error,
its cause and the suppressed failures; its existing real-database test
checks that the level is back to the original after a transaction; two
bootstrap tests are in `UserRepositoryTest`;
`UnityCatalogServerTest.logLinesCarryTheRequestId` checks that Log4j
finds the provider and that it supplies the request ID inside a request
and nothing outside one. There are no log-output tests. `build/sbt test`
passed at b9cab14, except for one run of
`SdkModelCRUDTest.testModelCRUD`, a known same-millisecond timing flake
in model updates that this PR doesn't touch; it passes on rerun. The
later commits, and the rebase onto main at 4626de6, were checked with
the test classes they touch.

</details>

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants