Skip to content

Commit

Permalink
[apache#4370]feat(iceberg): support view interface for Iceberg REST s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
theoryxu committed Sep 19, 2024
1 parent 825fafa commit 6676adc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager;
import org.apache.gravitino.iceberg.service.IcebergRestUtils;
import org.apache.gravitino.iceberg.service.IcebergTableOpsManager;
import org.apache.gravitino.metrics.MetricNames;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.rest.RESTUtil;
Expand All @@ -48,15 +48,15 @@
@Produces(MediaType.APPLICATION_JSON)
public class IcebergViewOperations {

private IcebergTableOpsManager icebergTableOpsManager;
private IcebergCatalogWrapperManager icebergCatalogWrapperManager;

@SuppressWarnings("UnusedVariable")
@Context
private HttpServletRequest httpRequest;

@Inject
public IcebergViewOperations(IcebergTableOpsManager icebergTableOpsManager) {
this.icebergTableOpsManager = icebergTableOpsManager;
public IcebergViewOperations(IcebergCatalogWrapperManager icebergCatalogWrapperManager) {
this.icebergCatalogWrapperManager = icebergCatalogWrapperManager;
}

@GET
Expand All @@ -66,7 +66,7 @@ public IcebergViewOperations(IcebergTableOpsManager icebergTableOpsManager) {
public Response listView(
@PathParam("prefix") String prefix, @PathParam("namespace") String namespace) {
ListTablesResponse response =
icebergTableOpsManager.getOps(prefix).listView(RESTUtil.decodeNamespace(namespace));
icebergCatalogWrapperManager.getOps(prefix).listView(RESTUtil.decodeNamespace(namespace));
return IcebergRestUtils.ok(response);
}

Expand All @@ -79,7 +79,7 @@ public Response createView(
@PathParam("namespace") String namespace,
CreateViewRequest request) {
LoadViewResponse response =
icebergTableOpsManager
icebergCatalogWrapperManager
.getOps(prefix)
.createView(RESTUtil.decodeNamespace(namespace), request);
return IcebergRestUtils.ok(response);
Expand All @@ -95,7 +95,8 @@ public Response loadView(
@PathParam("namespace") String namespace,
@PathParam("view") String view) {
TableIdentifier viewIdentifier = TableIdentifier.of(RESTUtil.decodeNamespace(namespace), view);
LoadViewResponse response = icebergTableOpsManager.getOps(prefix).loadView(viewIdentifier);
LoadViewResponse response =
icebergCatalogWrapperManager.getOps(prefix).loadView(viewIdentifier);
return IcebergRestUtils.ok(response);
}

Expand All @@ -111,7 +112,7 @@ public Response replaceView(
UpdateTableRequest request) {
TableIdentifier viewIdentifier = TableIdentifier.of(RESTUtil.decodeNamespace(namespace), view);
LoadViewResponse response =
icebergTableOpsManager.getOps(prefix).updateView(viewIdentifier, request);
icebergCatalogWrapperManager.getOps(prefix).updateView(viewIdentifier, request);
return IcebergRestUtils.ok(response);
}

Expand All @@ -125,7 +126,7 @@ public Response dropView(
@PathParam("namespace") String namespace,
@PathParam("view") String view) {
TableIdentifier viewIdentifier = TableIdentifier.of(RESTUtil.decodeNamespace(namespace), view);
icebergTableOpsManager.getOps(prefix).dropView(viewIdentifier);
icebergCatalogWrapperManager.getOps(prefix).dropView(viewIdentifier);
return IcebergRestUtils.noContent();
}

Expand All @@ -139,7 +140,7 @@ public Response viewExists(
@PathParam("namespace") String namespace,
@PathParam("view") String view) {
TableIdentifier tableIdentifier = TableIdentifier.of(RESTUtil.decodeNamespace(namespace), view);
if (icebergTableOpsManager.getOps(prefix).existView(tableIdentifier)) {
if (icebergCatalogWrapperManager.getOps(prefix).existView(tableIdentifier)) {
return IcebergRestUtils.noContent();
} else {
return IcebergRestUtils.notExists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager;
import org.apache.gravitino.iceberg.service.IcebergRestUtils;
import org.apache.gravitino.iceberg.service.IcebergTableOpsManager;
import org.apache.gravitino.metrics.MetricNames;
import org.apache.iceberg.rest.requests.RenameTableRequest;

Expand All @@ -44,19 +44,19 @@ public class IcebergViewRenameOperations {
@Context
private HttpServletRequest httpRequest;

private IcebergTableOpsManager icebergTableOpsManager;
private IcebergCatalogWrapperManager icebergCatalogWrapperManager;

@Inject
public IcebergViewRenameOperations(IcebergTableOpsManager icebergTableOpsManager) {
this.icebergTableOpsManager = icebergTableOpsManager;
public IcebergViewRenameOperations(IcebergCatalogWrapperManager icebergCatalogWrapperManager) {
this.icebergCatalogWrapperManager = icebergCatalogWrapperManager;
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Timed(name = "rename-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)
@ResponseMetered(name = "rename-view", absolute = true)
public Response renameView(@PathParam("prefix") String prefix, RenameTableRequest request) {
icebergTableOpsManager.getOps(prefix).renameView(request);
icebergCatalogWrapperManager.getOps(prefix).renameView(request);
return IcebergRestUtils.noContent();
}
}

0 comments on commit 6676adc

Please sign in to comment.