lasdf1234 commented on code in PR #11828:
URL: https://github.com/apache/gravitino/pull/11828#discussion_r3510877051


##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewHookDispatcher.java:
##########
@@ -173,6 +203,62 @@ public void renameView(IcebergRequestContext context, 
RenameTableRequest renameV
     bestEffortReconcileViewEntity(context, renameViewRequest.destination());
   }
 
+  /**
+   * Import a view into Gravitino's metadata catalog for the register-view 
operation.
+   *
+   * <p>Unlike {@link #importView}, this method is NOT best-effort: if the 
import fails, the
+   * exception propagates to the caller. Registration's purpose is to register 
the entity in
+   * Gravitino, so a silent failure would mislead callers into thinking the 
entity is registered.
+   *
+   * @param catalogName The name of the Gravitino catalog.
+   * @param namespace The Iceberg namespace containing the view.
+   * @param viewName The name of the view.
+   */
+  private void importViewForRegister(String catalogName, Namespace namespace, 
String viewName) {
+    ViewDispatcher viewDispatcher = 
GravitinoEnv.getInstance().internalViewDispatcher();
+    if (viewDispatcher != null) {
+      viewDispatcher.loadView(
+          IcebergIdentifierUtils.toGravitinoTableIdentifier(
+              metalake,
+              catalogName,
+              TableIdentifier.of(namespace, viewName),
+              HierarchicalSchemaUtil.schemaSeparator()));
+      LOG.info(
+          "Successfully imported view into Gravitino: {}.{}.{}.{}",
+          metalake,
+          catalogName,
+          namespace,
+          viewName);
+    }
+  }
+
+  /**
+   * Checks whether the view entity is already tracked in Gravitino's 
EntityStore.
+   *
+   * @param catalogName The name of the Gravitino catalog.
+   * @param namespace The Iceberg namespace containing the view.
+   * @param viewName The name of the view.
+   * @return {@code true} if the view entity exists in the store, {@code 
false} otherwise.
+   */
+  private boolean hasViewEntityInStore(String catalogName, Namespace 
namespace, String viewName) {
+    EntityStore store = GravitinoEnv.getInstance().entityStore();
+    if (store == null) {
+      return false;
+    }
+    NameIdentifier viewIdent =
+        IcebergIdentifierUtils.toGravitinoTableIdentifier(
+            metalake,
+            catalogName,
+            TableIdentifier.of(namespace, viewName),
+            HierarchicalSchemaUtil.schemaSeparator());
+    try {
+      return store.exists(viewIdent, Entity.EntityType.VIEW);
+    } catch (IOException e) {
+      LOG.warn("Failed to check view entity existence: {}", viewIdent, e);
+      return false;
+    }

Review Comment:
   <img width="1678" height="748" alt="Image" 
src="https://github.com/user-attachments/assets/f825f1f1-868a-425d-a258-ba5a663c6ec6";
 />
   Could you throw RuntimeException?



-- 
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]

Reply via email to