Skip to content

[Server] Answer three Iceberg REST details the way the spec describes them - #1801

Merged
yili-db merged 3 commits into
unitycatalog:mainfrom
moomindani:fix/iceberg-rest-spec-details
Sep 14, 2026
Merged

yili-db merged 3 commits into
unitycatalog:mainfrom
moomindani:fix/iceberg-rest-spec-details

Conversation

@moomindani

@moomindani moomindani commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

  • 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.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Fixes #1800.

Three independent deviations on the Iceberg REST endpoints, each small:

  • Listing under a parent namespace. listNamespaces returned an empty list for any parent,
    including one naming a namespace that does not exist, so a client could not tell an empty namespace
    from a missing one. The parent is now resolved before answering. Unity Catalog still has no nested
    namespaces, so a parent that exists keeps answering an empty list; one that does not exist answers
    404, as the spec requires.

  • tableExists status. HEAD .../tables/{table} answered 200, where the spec says 204 with no
    content. It now answers 204, which also drops the six-byte 200 OK body Armeria described on a
    response that must not carry one. Iceberg's own client accepts either, so this changes nothing for
    it; it does stop a stricter client from seeing a body on a HEAD.

  • Unreadable request body. The message quoted the Jackson exception: its class, the Java types
    the body was being mapped onto, and the reader's position in the body; and the error type was the
    converter's IllegalArgumentException, which no Iceberg client knows. A wrapper around the Iceberg
    surface's request converter now answers one of three messages, typed BadRequestException:
    Malformed request body: no content, ... not valid JSON, or ... not the structure this endpoint accepts.

    Recognizing the failure at the converter rather than in the exception handler keeps it to request
    bodies: the same Jackson failures are raised when the server reads JSON of its own, such as a
    table's metadata file, and one of those would otherwise have been answered as a malformed request
    body. The wrapper is on the Iceberg arm alone, since wrapping the shared converter would also
    change what the Delta surface says about an unreadable body, which its clients read today; a
    follow-up for the other dialects is planned.

Verified against a running server:

request before after
GET /namespaces?parent=noSuchSchema 200, {"namespaces":[]} 404, Schema not found: unity.noSuchSchema
GET /namespaces?parent=default 200, {"namespaces":[]} unchanged
HEAD .../tables/marksheet_uniform 200, content-length: 6 204, no content
POST .../metrics with an empty body 400, message names com.fasterxml.jackson... 400, Malformed request body: no content

Three tests cover these: the new testListNamespacesUnderAParent and
testReportMetricsRejectsAnUnreadableBodyWithoutLeakingTheParser, and the tableExists assertion in
testTable, which now expects 204 and an empty body. All three fail on main and pass with this
change; the remainder of IcebergRestCatalogTest, SdkSchemaCRUDTest, and SdkReportMetricsTest
pass unchanged.

A parent naming a multi-level namespace still answers 400 rather than 404: that path is the
namespace-separator handling in #182, which this PR leaves alone.

@yili-db

yili-db commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Please rebase. The conflict was caused by #1696.

@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from 303ffbe to 613cb5e Compare September 5, 2026 12:50
@moomindani

moomindani commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto 58d5c7b (main), and reviewed again on top of that rebase. All three deviations are still present there, and each is still fixed by the same small change; what moved is the code around them.

  • listNamespaces: main now returns an empty list whenever parent is set. The parent is resolved first, via schemaRepository.getSchema rather than the schemaService HTTP call I used before, so a parent that does not exist is a 404 and a parent that does keeps answering an empty list.

  • tableExists: rebased onto Implement native Iceberg REST catalog write endpoints #1696's getIcebergTableState lookup, returning 204 instead of 200. This also updates the HEAD assertion Implement native Iceberg REST catalog write endpoints #1696 added in testIcebergTableWriteLifecycle, which expects 200 today.

  • The unreadable-body case needed more than the rebase. My original change sanitized the message but left the type alone, and the message still quoted the reader. On 58d5c7b with this branch as it first stood, POST .../namespaces with {"namespace": ["x"], "properties": 5} answered:

    {"error":{"message":"Malformed request body: Cannot deserialize value of type `java.util.LinkedHashMap<java.lang.String,java.lang.String>` from Integer value (token `JsonToken.VALUE_NUMBER_INT`)","type":"IllegalArgumentException","code":400}}

    The type is the request converter's, which no Iceberg client knows, and the message still names the Java types the body was being mapped onto. It now answers:

    {"error":{"message":"Malformed request body: not the structure this endpoint accepts","type":"BadRequestException","code":400}}

    and a body that is not JSON answers not valid JSON. The reader's failure is kept as the cause of the Iceberg exception, so the server's own logs still have the reason. The detection is narrowed to the two Jackson failures that mean "this body cannot be read" (JsonParseException, MismatchedInputException); it previously matched any JsonProcessingException anywhere in the cause chain, which would have reported a failure to write a response as a bad request.

On 58d5c7b four tests in IcebergRestCatalogTest fail (testListNamespacesUnderAParent, testReportMetricsRejectsAnUnreadableBodyWithoutLeakingTheParser, and the two carrying HEAD assertions, testTable and testIcebergTableWriteLifecycle); with the fix the class is green (11/11), and the full server/test suite shows no failure attributable to this change.

The tests pin more than they did: the unreadable-body test asserts the type and code and that the message contains neither the parser's classes, nor java.util., nor [Source:, over three bodies (empty, invalid JSON, wrong shape); the parent test also covers an empty parent, which is not a parent, so the listing is the whole one, and a catalog that does not exist.

@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from 613cb5e to 9a712d0 Compare September 5, 2026 19:30
@yili-db

yili-db commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

This PR has some overlap with your other PR #1797. Will wait til that one is merged first.

@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from 9a712d0 to c537559 Compare September 10, 2026 00:56
@moomindani

Copy link
Copy Markdown
Contributor Author

Rebased onto 4ee2b248. Still waiting on #1797, as you asked.

@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from c537559 to 339e351 Compare September 11, 2026 01:30
@moomindani

Copy link
Copy Markdown
Contributor Author

Rebased onto 81663d1f, now that #1797 is in.

@Nullable
private static String unreadableBodyReason(Throwable cause) {
for (Throwable current = cause; current != null; current = current.getCause()) {
if (current instanceof JsonParseException) {

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.

These two exceptions could also be thrown by server when reading other json strings like metadata. It's not necessarily request body.
It can be done inside ArmeriaServerBuilder.java to add a wrapper that catches the body parsing error and convert them into an explicit BaseException:

  public final class MalformedBodyRejectingConverter implements RequestConverterFunction {

    private final RequestConverterFunction delegate;

    public MalformedBodyRejectingConverter(RequestConverterFunction delegate) {
      this.delegate = Objects.requireNonNull(delegate);
    }

    @Override
    public Object convertRequest(
        ServiceRequestContext ctx,
        AggregatedHttpRequest request,
        Class<?> expectedResultType,
        @Nullable ParameterizedType expectedParameterizedResultType)
        throws Exception {
      try {
        return delegate.convertRequest(
            ctx, request, expectedResultType, expectedParameterizedResultType);
      } catch (IllegalArgumentException | JsonProcessingException e) {
        // Armeria's Jackson converter rethrows an unreadable body as IllegalArgumentException with
        // the Jackson failure as its cause; a converter that throws that failure directly is caught
        // by the JsonProcessingException arm. Everything else, including Armeria's
        // FallthroughException signal, is never caught and propagates untouched.
        Throwable reason = e instanceof JsonProcessingException ? e : e.getCause();
        if (reason instanceof JsonParseException) {
          throw new BaseException(
              ErrorCode.INVALID_ARGUMENT, "Malformed request body: not valid JSON");
        }
        if (reason instanceof MismatchedInputException) {
          throw new BaseException(
              ErrorCode.INVALID_ARGUMENT,
              "Malformed request body: not the structure this endpoint accepts");
        }
        throw e;
      }
    }
  }

  private RequestConverterFunction bodyConverter(ObjectMapper mapper) {
    RequestConverterFunction jackson =
        new MalformedBodyRejectingConverter(new JacksonRequestConverterFunction(mapper));
    return authorizationEnabled ? new AuthorizationGateConverter(jackson, mapper) : jackson;
  }

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.

Moved, thank you -- this was a real false positive: the same Jackson failures come from the server reading JSON of its own, and a corrupt table metadata file would have been answered as "Malformed request body". The converter is the right place because only a body it could not read reaches it.

One deviation from your snippet: the wrapper is on the ICEBERG arm of register rather than inside bodyConverter. Wrapping the shared converter also changes what the Delta surface says about an unreadable body, and RawCreateTableTest.rawHttpRejectsMalformedColumnRequests pins that message today (it asserts Jackson's own "Cannot construct instance of DeltaStructField ..."). Widening it there looks right to me, but it changes released behaviour on another surface, so I left it out of this PR rather than editing that test.

Also rebased onto eb52af2e; the branch predated #1848.

@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from 339e351 to c519142 Compare September 14, 2026 01:39
@yili-db

yili-db commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

@moomindani Please update the PR message as now the content of PR has changed.

switch (protocol) {
case AUTH, UC, SCIM -> bodyConverter(ucMapper);
case ICEBERG -> bodyConverter(icebergMapper);
// Only the Iceberg surface rejects an unreadable body in its own words; the other

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.

Actually I think this wrapper is also needed by other dialect. It's just not done in this PR and that's OK since this PR is focusing on IRC.
Can you please tune this comment like this:

  // The Jackson converter leaks its own error text (exception class, mapped types, source
  // position) on any surface. Only on the Iceberg surface is an unreadable body rewritten into
  // a clean message, since its REST spec fixes the error contract clients parse; the other
  // dialects still surface the raw converter message.

Later I can do a follow up for other dialect.

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, comment replaced with your wording.

Agreed on the follow-up. While pinning the messages in the test I found one that was wrong for the caller: an empty body raises MismatchedInputException too ("No content to map due to end-of-input"), so it was answered "not the structure this endpoint accepts", which sends someone who sent nothing to look at their schema. It now says Malformed request body: no content, and the test asserts each of the three messages exactly rather than just the prefix.

Also rebased onto 4e8e52e0 and updated the PR description.

… them

- Listing namespaces under a parent that does not exist answered 200 with an empty list, which a
  client cannot tell apart from a namespace that exists and has no children. The parent is now
  resolved before answering; Unity Catalog still has no nested namespaces, so a parent that does
  exist keeps answering an empty list.
- tableExists answered 200 where the spec says 204, and Armeria described a six-byte "200 OK" body
  on a HEAD response, which must not carry one.
- A body the request converter cannot read was reported by quoting the JSON reader: the message
  named the Java types the body was being mapped onto and the reader's place in it, and the error
  type was the converter's IllegalArgumentException, which is not a name any Iceberg client knows.
  Such a request is now answered as an Iceberg BadRequestException saying whether the body was not
  JSON or not the structure the endpoint takes, with the reader's failure kept underneath for the
  server's own logs. Only the two Jackson failures that mean "this body cannot be read" are treated
  this way, so a failure to write a response is not reported as a bad request.

Signed-off-by: Noritaka Sekiyama <[email protected]>
Review follow-up. Recognizing Jackson's parse failures in the Iceberg exception
handler caught them wherever they came from, including the server reading JSON of
its own such as a table's metadata file, which has nothing to do with the request
body. Wrap the Iceberg surface's request converter instead, so only a body the
converter could not read is answered that way.

The wrapper is on the Iceberg arm alone. Wrapping the shared body converter would
also change what the Delta surface says about a body it cannot read, which its
clients already read and RawCreateTableTest pins; that is a separate decision.

Signed-off-by: Noritaka Sekiyama <[email protected]>
@moomindani
moomindani force-pushed the fix/iceberg-rest-spec-details branch from c519142 to 1788fa1 Compare September 14, 2026 14:34
- Resolve conflict in `IcebergRestCatalogTest`, keeping both sides' new tests:
  - this PR's `testListNamespacesUnderAParent` and `testReportMetricsRejectsAnUnreadableBodyWithoutLeakingTheParser`
  - main's `testLoadTableWhoseMetadataCannotBeRead` (unitycatalog#1845)

Signed-off-by: Yi Li <[email protected]>
@yili-db
yili-db merged commit e36e9ca into unitycatalog:main Sep 14, 2026
16 checks passed
yili-db pushed a commit that referenced this pull request Sep 21, 2026
…geRequested (#1890)

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [x] 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 (nothing in `docs/` describes this parameter)

**Description of changes**

`pyiceberg` cannot drop an Iceberg table through Unity Catalog today.
Both of its entry points fail with a 400:

```
>>> catalog.drop_table(("my_schema", "t"))    # sends purgeRequested=False
pyiceberg.exceptions.BadRequestError: BadRequestException: Can't convert 'False' to type 'Boolean'.
>>> catalog.purge_table(("my_schema", "t"))   # sends purgeRequested=True
pyiceberg.exceptions.BadRequestError: BadRequestException: Can't convert 'True' to type 'Boolean'.
```

pyiceberg hands a Python `bool` straight to `requests`
(`params={"purgeRequested": purge_requested}` in
`pyiceberg/catalog/rest/__init__.py`), and `requests` renders it `True`
/ `False`. Armeria converts a `Boolean` parameter through a fixed table
of `true|TRUE|1` and `false|FALSE|0` (`StringUtil.stringToBoolean`), so
neither spelling converts, and `AnnotatedValueResolver` is in an
`internal` package, so the conversion is not pluggable. The Iceberg REST
spec types this parameter `boolean` with `default: false`, so a
capitalized spelling is a valid request and dropping the table is the
correct answer.

This is the second of the two interop checks #1696 named as open when
the native Iceberg write endpoints landed; the first (HEAD stalling) was
fixed in #1801.

**Technical changes**

- `IcebergRestCatalogService.dropTable` binds `purgeRequested` as a
`String` and validates it, reading `true` and `false` without regard to
case.
- The spellings Armeria already accepted, `1` and `0` included, keep
working, so the accepted set only grows. A value that is not a boolean
at all is still a 400, now with a message that names the offending value
(`Invalid purgeRequested: yes. It must be true or false.`) instead of
Armeria's `Can't convert 'yes' to type 'Boolean'.`
- The value itself stays unused: purging is not implemented, and
`dropTable` removes the table either way, as before.

**Two choices worth a reviewer's opinion**

- The helper validates rather than parses. Returning an
`Optional<Boolean>` no caller reads would be new surface with nothing
behind it, so the value is dropped after the check; when purge is
implemented this becomes a parse.
- Only the Iceberg endpoint is fixed here. Ten `Optional<Boolean>` query
parameters on the native surface (`force` on the catalog, schema,
function, model, credential and external-location deletes, plus
`include_browse`, `omit_properties`, `omit_columns`) reject `True` the
same way -- measured on a local server. That is the native API's own
contract rather than an Iceberg interop bug, and this repo's generated
Python client is unaffected because it lowercases booleans, so I left it
out and will file it separately.

**Tests**

- `testDropTableAcceptsCapitalizedPurgeRequested` walks `true, false,
True, False, TRUE, FALSE, tRuE, 1, 0` and the empty value against a
fresh table each, and asserts the table is gone afterwards.
- `testDropTableRejectsNonBooleanPurgeRequested` asserts `yes`, `purge`
and `2` are a 400 with the exact message **and that the table is still
there** -- a destructive endpoint must not act on input it refused.

Verified both directions: with the service file from `main` both new
tests fail (`expected: 204 but was: 400` for `True`, and Armeria's
message for `yes`); with the change all 19 tests in the class pass.

```
sbt "server/testOnly io.unitycatalog.server.service.IcebergRestCatalogTest"
```

End-to-end against a local server with pyiceberg 0.12.0: `drop_table`
and `purge_table` both fail with the 400 above on `main` and both
succeed on this branch, with the table gone from `list_tables`
afterwards.

**Backward compatibility**: the set of accepted values grows and nothing
that worked stops working. The only change for an existing caller is the
message text on a non-boolean value (same 400).

Signed-off-by: Noritaka Sekiyama <[email protected]>
newfront pushed a commit to newfront/unitycatalog that referenced this pull request Sep 24, 2026
…geRequested (unitycatalog#1890)

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [x] 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 (nothing in `docs/` describes this parameter)

**Description of changes**

`pyiceberg` cannot drop an Iceberg table through Unity Catalog today.
Both of its entry points fail with a 400:

```
>>> catalog.drop_table(("my_schema", "t"))    # sends purgeRequested=False
pyiceberg.exceptions.BadRequestError: BadRequestException: Can't convert 'False' to type 'Boolean'.
>>> catalog.purge_table(("my_schema", "t"))   # sends purgeRequested=True
pyiceberg.exceptions.BadRequestError: BadRequestException: Can't convert 'True' to type 'Boolean'.
```

pyiceberg hands a Python `bool` straight to `requests`
(`params={"purgeRequested": purge_requested}` in
`pyiceberg/catalog/rest/__init__.py`), and `requests` renders it `True`
/ `False`. Armeria converts a `Boolean` parameter through a fixed table
of `true|TRUE|1` and `false|FALSE|0` (`StringUtil.stringToBoolean`), so
neither spelling converts, and `AnnotatedValueResolver` is in an
`internal` package, so the conversion is not pluggable. The Iceberg REST
spec types this parameter `boolean` with `default: false`, so a
capitalized spelling is a valid request and dropping the table is the
correct answer.

This is the second of the two interop checks unitycatalog#1696 named as open when
the native Iceberg write endpoints landed; the first (HEAD stalling) was
fixed in unitycatalog#1801.

**Technical changes**

- `IcebergRestCatalogService.dropTable` binds `purgeRequested` as a
`String` and validates it, reading `true` and `false` without regard to
case.
- The spellings Armeria already accepted, `1` and `0` included, keep
working, so the accepted set only grows. A value that is not a boolean
at all is still a 400, now with a message that names the offending value
(`Invalid purgeRequested: yes. It must be true or false.`) instead of
Armeria's `Can't convert 'yes' to type 'Boolean'.`
- The value itself stays unused: purging is not implemented, and
`dropTable` removes the table either way, as before.

**Two choices worth a reviewer's opinion**

- The helper validates rather than parses. Returning an
`Optional<Boolean>` no caller reads would be new surface with nothing
behind it, so the value is dropped after the check; when purge is
implemented this becomes a parse.
- Only the Iceberg endpoint is fixed here. Ten `Optional<Boolean>` query
parameters on the native surface (`force` on the catalog, schema,
function, model, credential and external-location deletes, plus
`include_browse`, `omit_properties`, `omit_columns`) reject `True` the
same way -- measured on a local server. That is the native API's own
contract rather than an Iceberg interop bug, and this repo's generated
Python client is unaffected because it lowercases booleans, so I left it
out and will file it separately.

**Tests**

- `testDropTableAcceptsCapitalizedPurgeRequested` walks `true, false,
True, False, TRUE, FALSE, tRuE, 1, 0` and the empty value against a
fresh table each, and asserts the table is gone afterwards.
- `testDropTableRejectsNonBooleanPurgeRequested` asserts `yes`, `purge`
and `2` are a 400 with the exact message **and that the table is still
there** -- a destructive endpoint must not act on input it refused.

Verified both directions: with the service file from `main` both new
tests fail (`expected: 204 but was: 400` for `True`, and Armeria's
message for `yes`); with the change all 19 tests in the class pass.

```
sbt "server/testOnly io.unitycatalog.server.service.IcebergRestCatalogTest"
```

End-to-end against a local server with pyiceberg 0.12.0: `drop_table`
and `purge_table` both fail with the 400 above on `main` and both
succeed on this branch, with the table gone from `list_tables`
afterwards.

**Backward compatibility**: the set of accepted values grows and nothing
that worked stops working. The only change for an existing caller is the
message text on a non-boolean value (same 400).

Signed-off-by: Noritaka Sekiyama <[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.

Three Iceberg REST responses deviate from the spec: parent listing, tableExists status, unreadable body

2 participants