Repository navigation
[Server] Answer three Iceberg REST details the way the spec describes them - #1801
Conversation
|
Please rebase. The conflict was caused by #1696. |
303ffbe to
613cb5e
Compare
|
Rebased onto
On 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 |
613cb5e to
9a712d0
Compare
|
This PR has some overlap with your other PR #1797. Will wait til that one is merged first. |
9a712d0 to
c537559
Compare
|
Rebased onto |
c537559 to
339e351
Compare
|
Rebased onto |
| @Nullable | ||
| private static String unreadableBodyReason(Throwable cause) { | ||
| for (Throwable current = cause; current != null; current = current.getCause()) { | ||
| if (current instanceof JsonParseException) { |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
339e351 to
c519142
Compare
|
@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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
c519142 to
1788fa1
Compare
- 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]>
…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]>
…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]>
PR Checklist
docsis updatedDescription of changes
Fixes #1800.
Three independent deviations on the Iceberg REST endpoints, each small:
Listing under a parent namespace.
listNamespacesreturned an empty list for anyparent,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 nocontent. It now answers 204, which also drops the six-byte
200 OKbody Armeria described on aresponse 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 Icebergsurface'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:
GET /namespaces?parent=noSuchSchema{"namespaces":[]}Schema not found: unity.noSuchSchemaGET /namespaces?parent=default{"namespaces":[]}HEAD .../tables/marksheet_uniformcontent-length: 6POST .../metricswith an empty bodycom.fasterxml.jackson...Malformed request body: no contentThree tests cover these: the new
testListNamespacesUnderAParentandtestReportMetricsRejectsAnUnreadableBodyWithoutLeakingTheParser, and the tableExists assertion intestTable, which now expects 204 and an empty body. All three fail onmainand pass with thischange; the remainder of
IcebergRestCatalogTest,SdkSchemaCRUDTest, andSdkReportMetricsTestpass unchanged.
A
parentnaming a multi-level namespace still answers 400 rather than 404: that path is thenamespace-separator handling in #182, which this PR leaves alone.