roryqi commented on code in PR #9917:
URL: https://github.com/apache/gravitino/pull/9917#discussion_r2788823311


##########
core/src/main/java/org/apache/gravitino/catalog/ViewOperationDispatcher.java:
##########
@@ -68,13 +71,86 @@ public ViewOperationDispatcher(
   public View loadView(NameIdentifier ident) throws NoSuchViewException {
     LOG.info("Loading view: {}", ident);
 
-    return TreeLockUtils.doWithTreeLock(
-        ident,
-        LockType.READ,
-        () ->
-            doWithCatalog(
-                getCatalogIdentifier(ident),
-                c -> c.doWithViewOps(v -> v.loadView(ident)),
-                NoSuchViewException.class));
+    // First load with READ lock to check if view is already imported
+    EntityCombinedView entityCombinedView =
+        TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> 
internalLoadView(ident));
+
+    if (!entityCombinedView.imported()) {
+      // Load the schema to make sure the schema is imported.
+      SchemaDispatcher schemaDispatcher = 
GravitinoEnv.getInstance().schemaDispatcher();
+      NameIdentifier schemaIdent = 
NameIdentifier.of(ident.namespace().levels());
+      schemaDispatcher.loadSchema(schemaIdent);
+
+      // Import the view.

Review Comment:
   loadSchema will call the method `importSchema`. So we don't need call the 
method `importView` explictly.



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