Repository navigation
[Server] Implement the Iceberg renameTable endpoint - #1849
Conversation
| // Only tables this API serves can be renamed through it; anything else is not a table it has. | ||
| TableRepository.IcebergTableState state = | ||
| tableRepository.getIcebergTableState(catalog, namespace, request.source().name()); | ||
| if (state.metadataLocation() == null) { |
There was a problem hiding this comment.
dropTable has this:
TableRepository.IcebergTableState state =
tableRepository.getIcebergTableState(catalog, namespace, table);
if (state.dataSourceFormat() != DataSourceFormat.ICEBERG) {
throw new BadRequestException(
"Table %s was not created through the Iceberg REST catalog; drop it through the Unity"
+ " Catalog API instead.",
fullName);
}
UniForm tables are supposedly readonly via IRC endpoints.
There was a problem hiding this comment.
Fixed. renameTable makes the same check dropTable makes and answers 400, with a message naming the rename rather than the drop: a UniForm table is a Delta table these endpoints read, so renaming it here would rename the Delta table under its own API.
That also changed where the test belongs, which lines up with your other comment: the rename now runs against the native table testIcebergTableWriteLifecycle creates, and the read-only case joins the commit and drop rejections testTable already makes against a UniForm table.
| @AuthorizeResourceKey(METASTORE) | ||
| public HttpResponse renameTable(@Param("catalog") String catalog, RenameTableRequest request) { | ||
| serverProperties.checkIcebergTableEnabled(); | ||
| Namespace source = request.source().namespace(); |
There was a problem hiding this comment.
request is not validated.
A malformed request with null source/destination would throw NPE and 500, instead of 400.
There was a problem hiding this comment.
Fixed -- request.validate() before anything reads it, so a body missing either identifier is the 400 it should be instead of the 500 the NPE produced. RegisterTableRequest in #1851 was already validated this way; the rest of the write endpoints take no body or validate it, so this was the only one.
| } | ||
|
|
||
| @Test | ||
| public void testRenameTable() throws Exception { |
There was a problem hiding this comment.
Better fold this test into testIcebergTableWriteLifecycle and between some steps in that test.
There was a problem hiding this comment.
Done. The rename runs in testIcebergTableWriteLifecycle between the commit and the drop -- against the native table that test creates, which is also what the read-only check above requires -- and renames back at the end so the drop still finds the table. The 404, 409, cross-namespace and malformed-request cases go with it. Without the endpoint they fail with 404 where 204 is expected.
The rename endpoint was not implemented, so an engine's ALTER TABLE ... RENAME TO against this catalog was answered by Armeria before any service was reached, with a 404 for a path it does not serve. The repository has renamed tables all along -- TableRepository.renameTable, which already refuses a name that is taken -- it was only missing from the Iceberg REST surface. Serve it, and advertise V1_RENAME_TABLE with the other write endpoints. A table this API does not expose is not renameable through it, so the table is resolved the way loadTable resolves it first; a name that is taken is the spec's 409, which is what the repository already raises. A rename whose destination is a different namespace is refused as unimplemented rather than half-applied: Unity Catalog has no way to move a table between schemas, and the status says so to a client instead of describing the request as malformed. Signed-off-by: Noritaka Sekiyama <[email protected]>
…ts request Review follow-up, two real fixes and a test move. A UniForm table is a Delta table these endpoints read, so renaming one here would rename the Delta table under its own API. renameTable now makes the same check dropTable makes and answers 400, with a message naming the rename rather than the drop. RenameTableRequest was used without validating it, so a body missing either identifier reached request.source() as null and came back as a 500. Calling validate() first turns that into the 400 it should be. The cases move out of a test of their own: the rename itself goes into testIcebergTableWriteLifecycle between the commit and the drop, against the native table that test creates and renaming back so the drop still finds it, and the read-only case joins the commit and drop rejections testTable already makes against a UniForm table. Without the endpoint they fail with 404 where 204 and 400 are expected. Signed-off-by: Noritaka Sekiyama <[email protected]>
90bb893 to
b7d1655
Compare
|
Rebased onto |
- Resolve add/add conflict in `IcebergRestCatalogTest.java`:
- keep the PR's `renameRequest` helpers
- keep main's `testLoadTableSnapshotsParameter` and `loadedSnapshotIds`
- `renameTable` and main's `loadTable` `snapshots` change coexist; `server/Test/compile` is clean.
Co-authored-by: Isaac <[email protected]>
Signed-off-by: Yi Li <[email protected]>
PR Checklist
docsis updatedDescription of changes
Part of #1846.
The rename endpoint had no route, so an engine's
ALTER TABLE ... RENAME TOwas answered with a 404for a path this server does not serve. Unity Catalog has renamed tables all along, through
TableRepository.renameTable, which already refuses a name that is taken; the operation was onlymissing from the Iceberg REST surface.
This serves it and advertises
V1_RENAME_TABLEwith the other write endpoints.loadTableresolves it, so a table this API does not expose cannot berenamed through it.
to move a table between schemas, and that status tells a client the catalog does not do it, rather
than describing a well-formed request as malformed. The spec lists 406 for an unsupported rename;
say so if you would rather have that.
For users:
ALTER TABLE ... RENAME TOworks from any Iceberg client, within a namespace.testRenameTablepins the 204 and that the table is listed and loadable under its new name, the 404for a table that is not there, the 409 for a name that is taken, and the 501 for a cross-namespace
rename. It fails on an unfixed tree and passes with the fix; the full
server/testsuite shows nofailure attributable to this change.