Skip to content

Commit

Permalink
[apache#5611] Improvement(iceberg): support schema exists interface f…
Browse files Browse the repository at this point in the history
…or Iceberg REST server (apache#5616)

### What changes were proposed in this pull request?

schema exists interface for Iceberg REST server

### Why are the changes needed?

Close: apache#5611

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Unit test
  • Loading branch information
orenccl authored Nov 20, 2024
1 parent 306c0e8 commit d8a6ff8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public GetNamespaceResponse loadNamespace(Namespace namespace) {
return CatalogHandlers.loadNamespace(asNamespaceCatalog, namespace);
}

public boolean existNamespace(Namespace namespace) {
validateNamespace(Optional.of(namespace));
return asNamespaceCatalog.namespaceExists(namespace);
}

public ListNamespacesResponse listNamespace(Namespace parent) {
validateNamespace(Optional.empty());
return CatalogHandlers.listNamespaces(asNamespaceCatalog, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -95,6 +96,24 @@ public Response loadNamespace(
return IcebergRestUtils.ok(getNamespaceResponse);
}

@HEAD
@Path("{namespace}")
@Produces(MediaType.APPLICATION_JSON)
@Timed(name = "namespace-exists." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
@ResponseMetered(name = "namespace-exists", absolute = true)
public Response namespaceExists(
@PathParam("prefix") String prefix, @PathParam("namespace") String namespace) {
boolean exists =
icebergCatalogWrapperManager
.getOps(prefix)
.existNamespace(RESTUtil.decodeNamespace(namespace));
if (exists) {
return IcebergRestUtils.noContent();
} else {
return IcebergRestUtils.notExists();
}
}

@DELETE
@Path("{namespace}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ private Response doLoadNamespace(String name) {
return getNamespaceClientBuilder(Optional.of(name)).get();
}

private Response doNamespaceExists(String name) {
return getNamespaceClientBuilder(Optional.of(name)).head();
}

private Response doDropNamespace(String name) {
return getNamespaceClientBuilder(Optional.of(name)).delete();
}
Expand Down Expand Up @@ -121,6 +125,11 @@ private void verifyDropNamespaceFail(int status, String name) {
Assertions.assertEquals(status, response.getStatus());
}

private void verifyNamespaceExistsStatusCode(int status, String name) {
Response response = doNamespaceExists(name);
Assertions.assertEquals(status, response.getStatus());
}

protected void verifyCreateNamespaceSucc(String... name) {
Response response = doCreateNamespace(name);
Assertions.assertEquals(Status.OK.getStatusCode(), response.getStatus());
Expand Down Expand Up @@ -167,6 +176,13 @@ void testLoadNamespace() {
verifyLoadNamespaceFail(404, "load_foo2");
}

@Test
void testNamespaceExists() {
verifyNamespaceExistsStatusCode(404, "exists_foo1");
verifyCreateNamespaceSucc("exists_foo1");
verifyNamespaceExistsStatusCode(204, "exists_foo1");
}

@Test
void testDropNamespace() {
verifyCreateNamespaceSucc("drop_foo1");
Expand Down

0 comments on commit d8a6ff8

Please sign in to comment.