Copilot commented on code in PR #11028: URL: https://github.com/apache/gravitino/pull/11028#discussion_r3217331439
########## core/src/main/java/org/apache/gravitino/listener/api/info/ViewInfo.java: ########## @@ -0,0 +1,126 @@ +/* + * 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.listener.api.info; + +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.gravitino.Audit; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.rel.Column; +import org.apache.gravitino.rel.Representation; +import org.apache.gravitino.rel.View; + +/** + * ViewInfo exposes view information for event listeners; it is read-only. Most fields are shallow + * copies internally, not deep copies, for performance. + */ +@DeveloperApi +public final class ViewInfo { + private final String name; + private final Column[] columns; + @Nullable private final String comment; + private final Representation[] representations; + @Nullable private final String defaultCatalog; + @Nullable private final String defaultSchema; + private final Map<String, String> properties; + @Nullable private final Audit auditInfo; + + /** Constructs a ViewInfo from a {@link View}. */ + public ViewInfo(View view) { + this( + view.name(), + view.columns(), + view.comment(), + view.representations(), + view.defaultCatalog(), + view.defaultSchema(), + view.properties(), + view.auditInfo()); + } + + /** + * Constructs ViewInfo with the given fields. + * + * @param name View name + * @param columns Output columns + * @param comment Optional comment + * @param representations View representations (at least one in a valid create request) + * @param defaultCatalog Optional default catalog for the definition + * @param defaultSchema Optional default schema for the definition + * @param properties View properties; copied defensively + * @param auditInfo Optional audit information + */ + public ViewInfo( + String name, + Column[] columns, + @Nullable String comment, + Representation[] representations, + @Nullable String defaultCatalog, + @Nullable String defaultSchema, + Map<String, String> properties, + @Nullable Audit auditInfo) { + this.name = name; + this.columns = columns == null ? new Column[0] : columns.clone(); + this.comment = comment; + this.representations = + representations == null ? new Representation[0] : representations.clone(); + this.defaultCatalog = defaultCatalog; + this.defaultSchema = defaultSchema; + this.properties = properties == null ? ImmutableMap.of() : ImmutableMap.copyOf(properties); + this.auditInfo = auditInfo; + } + + public String name() { + return name; + } + + public Column[] columns() { + return columns; + } + + @Nullable + public String comment() { + return comment; + } + + public Representation[] representations() { + return representations; + } + + @Nullable + public String defaultCatalog() { + return defaultCatalog; + } + + @Nullable + public String defaultSchema() { + return defaultSchema; + } + + public Map<String, String> properties() { + return properties; + } + Review Comment: `ViewInfo` is part of the public listener Developer API, but its public accessor methods are missing Javadoc. Other *Info classes in the same package (e.g., `TopicInfo`, `TableInfo`) document each getter, and keeping that consistency helps plugin authors and avoids potential doc-check failures. Consider adding brief Javadoc to the `name()/columns()/comment()/representations()/defaultCatalog()/defaultSchema()/properties()/auditInfo()` accessors. ########## core/src/main/java/org/apache/gravitino/listener/api/event/LoadViewEvent.java: ########## @@ -0,0 +1,44 @@ +/* + * 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.listener.api.event; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.listener.api.info.ViewInfo; + +/** Successful load-view event. */ +@DeveloperApi +public final class LoadViewEvent extends ViewEvent { + private final ViewInfo loadedViewInfo; + + public LoadViewEvent(String user, NameIdentifier identifier, ViewInfo loadedViewInfo) { + super(user, identifier); + this.loadedViewInfo = loadedViewInfo; + } + Review Comment: The new view event classes are annotated as `@DeveloperApi`, but their public accessor methods (e.g., `loadedViewInfo()` here) don’t have Javadoc, unlike the existing table/topic event classes in this package (for example `LoadTableEvent.loadedTableInfo()`). Please add short Javadoc to these accessors across the new view event types for consistency and API usability. ########## core/src/main/java/org/apache/gravitino/hook/ViewHookDispatcher.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.hook; + +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.gravitino.Entity; +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.authorization.AuthorizationUtils; +import org.apache.gravitino.authorization.Owner; +import org.apache.gravitino.authorization.OwnerDispatcher; +import org.apache.gravitino.catalog.CapabilityHelpers; +import org.apache.gravitino.catalog.ViewDispatcher; +import org.apache.gravitino.connector.capability.Capability; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchViewException; +import org.apache.gravitino.exceptions.ViewAlreadyExistsException; +import org.apache.gravitino.rel.Column; +import org.apache.gravitino.rel.Representation; +import org.apache.gravitino.rel.View; +import org.apache.gravitino.rel.ViewChange; +import org.apache.gravitino.utils.NameIdentifierUtil; +import org.apache.gravitino.utils.PrincipalUtils; + +/** + * Decorates {@link ViewDispatcher} with ownership and authorization hooks, matching {@link + * TableHookDispatcher}. + */ +public class ViewHookDispatcher implements ViewDispatcher { + private final ViewDispatcher dispatcher; + + public ViewHookDispatcher(ViewDispatcher dispatcher) { + this.dispatcher = dispatcher; + } + + @Override + public NameIdentifier[] listViews(Namespace namespace) throws NoSuchSchemaException { + return dispatcher.listViews(namespace); + } + + @Override + public View loadView(NameIdentifier ident) throws NoSuchViewException { + return dispatcher.loadView(ident); + } + + @Override + public boolean viewExists(NameIdentifier ident) { + return dispatcher.viewExists(ident); + } + + @Override + public View createView( + NameIdentifier ident, + @Nullable String comment, + Column[] columns, + Representation[] representations, + @Nullable String defaultCatalog, + @Nullable String defaultSchema, + Map<String, String> properties) + throws NoSuchSchemaException, ViewAlreadyExistsException { + View view = + dispatcher.createView( + ident, comment, columns, representations, defaultCatalog, defaultSchema, properties); + OwnerDispatcher ownerManager = GravitinoEnv.getInstance().ownerDispatcher(); + if (ownerManager != null) { + NameIdentifier normalizedIdent = + CapabilityHelpers.applyCapabilities( + ident, Capability.Scope.VIEW, GravitinoEnv.getInstance().catalogManager()); + ownerManager.setOwner( + normalizedIdent.namespace().level(0), + NameIdentifierUtil.toMetadataObject(normalizedIdent, Entity.EntityType.VIEW), + PrincipalUtils.getCurrentUserName(), + Owner.Type.USER); + } + return view; + } + + @Override + public View alterView(NameIdentifier ident, ViewChange... changes) + throws NoSuchViewException, IllegalArgumentException { + ViewChange.RenameView lastRename = null; + List<String> locations = null; + for (ViewChange change : changes) { + if (change instanceof ViewChange.RenameView) { + lastRename = (ViewChange.RenameView) change; + } + } + if (lastRename != null) { + locations = AuthorizationUtils.getMetadataObjectLocation(ident, Entity.EntityType.VIEW); + } + View altered = dispatcher.alterView(ident, changes); + if (lastRename != null) { + AuthorizationUtils.authorizationPluginRenamePrivileges( + ident, Entity.EntityType.VIEW, lastRename.getNewName(), locations); + } + return altered; + } + + @Override + public boolean dropView(NameIdentifier ident) { + List<String> locations = + AuthorizationUtils.getMetadataObjectLocation(ident, Entity.EntityType.VIEW); + boolean dropped = dispatcher.dropView(ident); + AuthorizationUtils.authorizationPluginRemovePrivileges( + ident, Entity.EntityType.VIEW, locations); Review Comment: `AuthorizationUtils.getMetadataObjectLocation(...)` does not currently support `EntityType.VIEW` and will log a warning + return an empty list via the catch-all path. Because this call happens on every `dropView`, it can generate persistent warn noise even when drops succeed. Consider skipping the location lookup for views (or updating `AuthorizationUtils` to handle VIEW explicitly) so normal view drops don’t produce warnings. ########## core/src/main/java/org/apache/gravitino/hook/ViewHookDispatcher.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.hook; + +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; +import org.apache.gravitino.Entity; +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.authorization.AuthorizationUtils; +import org.apache.gravitino.authorization.Owner; +import org.apache.gravitino.authorization.OwnerDispatcher; +import org.apache.gravitino.catalog.CapabilityHelpers; +import org.apache.gravitino.catalog.ViewDispatcher; +import org.apache.gravitino.connector.capability.Capability; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchViewException; +import org.apache.gravitino.exceptions.ViewAlreadyExistsException; +import org.apache.gravitino.rel.Column; +import org.apache.gravitino.rel.Representation; +import org.apache.gravitino.rel.View; +import org.apache.gravitino.rel.ViewChange; +import org.apache.gravitino.utils.NameIdentifierUtil; +import org.apache.gravitino.utils.PrincipalUtils; + +/** + * Decorates {@link ViewDispatcher} with ownership and authorization hooks, matching {@link + * TableHookDispatcher}. + */ +public class ViewHookDispatcher implements ViewDispatcher { + private final ViewDispatcher dispatcher; + + public ViewHookDispatcher(ViewDispatcher dispatcher) { + this.dispatcher = dispatcher; + } + + @Override + public NameIdentifier[] listViews(Namespace namespace) throws NoSuchSchemaException { + return dispatcher.listViews(namespace); + } + + @Override + public View loadView(NameIdentifier ident) throws NoSuchViewException { + return dispatcher.loadView(ident); + } + + @Override + public boolean viewExists(NameIdentifier ident) { + return dispatcher.viewExists(ident); + } + + @Override + public View createView( + NameIdentifier ident, + @Nullable String comment, + Column[] columns, + Representation[] representations, + @Nullable String defaultCatalog, + @Nullable String defaultSchema, + Map<String, String> properties) + throws NoSuchSchemaException, ViewAlreadyExistsException { + View view = + dispatcher.createView( + ident, comment, columns, representations, defaultCatalog, defaultSchema, properties); + OwnerDispatcher ownerManager = GravitinoEnv.getInstance().ownerDispatcher(); + if (ownerManager != null) { + NameIdentifier normalizedIdent = + CapabilityHelpers.applyCapabilities( + ident, Capability.Scope.VIEW, GravitinoEnv.getInstance().catalogManager()); + ownerManager.setOwner( + normalizedIdent.namespace().level(0), + NameIdentifierUtil.toMetadataObject(normalizedIdent, Entity.EntityType.VIEW), + PrincipalUtils.getCurrentUserName(), + Owner.Type.USER); + } + return view; + } + + @Override + public View alterView(NameIdentifier ident, ViewChange... changes) + throws NoSuchViewException, IllegalArgumentException { + ViewChange.RenameView lastRename = null; + List<String> locations = null; + for (ViewChange change : changes) { + if (change instanceof ViewChange.RenameView) { + lastRename = (ViewChange.RenameView) change; + } + } + if (lastRename != null) { + locations = AuthorizationUtils.getMetadataObjectLocation(ident, Entity.EntityType.VIEW); + } + View altered = dispatcher.alterView(ident, changes); + if (lastRename != null) { + AuthorizationUtils.authorizationPluginRenamePrivileges( + ident, Entity.EntityType.VIEW, lastRename.getNewName(), locations); + } Review Comment: `AuthorizationUtils.getMetadataObjectLocation(...)` currently has no `VIEW` case and will fall into the default branch, throwing/logging a warning and returning an empty list. Calling it here means every view rename will emit a noisy warn log even in normal operation. Consider either adding explicit `VIEW` handling in `AuthorizationUtils.getMetadataObjectLocation` (return empty without warning) or avoiding this call for views and passing an empty list/null to the privilege-rename helper. -- 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]
