This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new d8a6ff815 [#5611] Improvement(iceberg): support schema exists
interface for Iceberg REST server (#5616)
d8a6ff815 is described below
commit d8a6ff8152f327801da15f338c8c5bf182e2b863
Author: JUN <[email protected]>
AuthorDate: Wed Nov 20 14:08:08 2024 +0800
[#5611] Improvement(iceberg): support schema exists interface for Iceberg
REST server (#5616)
### What changes were proposed in this pull request?
schema exists interface for Iceberg REST server
### Why are the changes needed?
Close: #5611
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Unit test
---
.../iceberg/common/ops/IcebergCatalogWrapper.java | 5 +++++
.../service/rest/IcebergNamespaceOperations.java | 19 +++++++++++++++++++
.../service/rest/TestIcebergNamespaceOperations.java | 16 ++++++++++++++++
3 files changed, 40 insertions(+)
diff --git
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
index f1d3b178e..de265ed34 100644
---
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
+++
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java
@@ -134,6 +134,11 @@ public class IcebergCatalogWrapper implements
AutoCloseable {
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);
diff --git
a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergNamespaceOperations.java
b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergNamespaceOperations.java
index 831a9b907..c4e3a3fe6 100644
---
a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergNamespaceOperations.java
+++
b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/rest/IcebergNamespaceOperations.java
@@ -26,6 +26,7 @@ import javax.ws.rs.Consumes;
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;
@@ -95,6 +96,24 @@ public class IcebergNamespaceOperations {
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)
diff --git
a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
index 6049a153e..59e94442d 100644
---
a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
+++
b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
@@ -93,6 +93,10 @@ public class TestIcebergNamespaceOperations extends
IcebergTestBase {
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();
}
@@ -121,6 +125,11 @@ public class TestIcebergNamespaceOperations extends
IcebergTestBase {
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());
@@ -167,6 +176,13 @@ public class TestIcebergNamespaceOperations extends
IcebergTestBase {
verifyLoadNamespaceFail(404, "load_foo2");
}
+ @Test
+ void testNamespaceExists() {
+ verifyNamespaceExistsStatusCode(404, "exists_foo1");
+ verifyCreateNamespaceSucc("exists_foo1");
+ verifyNamespaceExistsStatusCode(204, "exists_foo1");
+ }
+
@Test
void testDropNamespace() {
verifyCreateNamespaceSucc("drop_foo1");