bharos commented on code in PR #9787: URL: https://github.com/apache/gravitino/pull/9787#discussion_r2719487259
########## iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewHookDispatcher.java: ########## @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.iceberg.service.dispatcher; + +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.catalog.ViewDispatcher; +import org.apache.gravitino.iceberg.common.utils.IcebergIdentifierUtils; +import org.apache.gravitino.listener.api.event.IcebergRequestContext; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.rest.requests.CreateViewRequest; +import org.apache.iceberg.rest.requests.RenameTableRequest; +import org.apache.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.ListTablesResponse; +import org.apache.iceberg.rest.responses.LoadViewResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@code IcebergViewHookDispatcher} is a decorator for {@link IcebergViewOperationDispatcher} that + * imports views into Gravitino's metadata catalog when they are created or accessed via Iceberg + * REST. + * + * <p>This is the key integration point between Iceberg REST views and Gravitino's view management + * system. When a view is created or loaded through Iceberg REST, this dispatcher ensures that + * Gravitino is aware of the view by calling {@link ViewDispatcher#loadView}. + */ +public class IcebergViewHookDispatcher implements IcebergViewOperationDispatcher { + + private static final Logger LOG = LoggerFactory.getLogger(IcebergViewHookDispatcher.class); + + private final IcebergViewOperationDispatcher dispatcher; + private final String metalake; + + public IcebergViewHookDispatcher(IcebergViewOperationDispatcher dispatcher, String metalake) { + this.dispatcher = dispatcher; + this.metalake = metalake; + } + + @Override + public LoadViewResponse createView( + IcebergRequestContext context, Namespace namespace, CreateViewRequest createViewRequest) { + // First, create the view in the underlying catalog + LoadViewResponse response = dispatcher.createView(context, namespace, createViewRequest); + + // Then import it into Gravitino so Gravitino is aware of the view + importView(context.catalogName(), namespace, createViewRequest.name()); + + // Set view ownership + IcebergOwnershipUtils.setViewOwner( + metalake, + context.catalogName(), + namespace, + createViewRequest.name(), + context.userName(), + GravitinoEnv.getInstance().ownerDispatcher()); + + return response; + } + + @Override + public LoadViewResponse loadView(IcebergRequestContext context, TableIdentifier viewIdentifier) { + LoadViewResponse response = dispatcher.loadView(context, viewIdentifier); + + // Import on load as well to ensure Gravitino knows about views that may have been + // created outside of this REST server instance + importView(context.catalogName(), viewIdentifier.namespace(), viewIdentifier.name()); Review Comment: Do you mean we call importView() during createView, so we don't need to do it during loadView() ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
