dpaani commented on code in PR #7228:
URL: https://github.com/apache/iceberg/pull/7228#discussion_r1162008555


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java:
##########
@@ -134,28 +135,34 @@ public Identifier[] listTables(String[] namespace) throws 
NoSuchNamespaceExcepti
 
   @Override
   public Table loadTable(Identifier ident) throws NoSuchTableException {
-    try {
-      return icebergCatalog.loadTable(ident);
-    } catch (NoSuchTableException e) {
-      return getSessionCatalog().loadTable(ident);
-    }
+    return loadTableInternal(ident, null, null);
   }
 
   @Override
   public Table loadTable(Identifier ident, String version) throws 
NoSuchTableException {
-    try {
-      return icebergCatalog.loadTable(ident, version);
-    } catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
-      return getSessionCatalog().loadTable(ident, version);
-    }
+    return loadTableInternal(ident, version, null);
   }
 
   @Override
   public Table loadTable(Identifier ident, long timestamp) throws 
NoSuchTableException {
+    return loadTableInternal(ident, null, timestamp);
+  }
+
+  private Table loadTableInternal(Identifier ident, String version, Long 
timestamp)
+      throws NoSuchTableException {
     try {
-      return icebergCatalog.loadTable(ident, timestamp);
+      return loadTable(icebergCatalog, ident, version, timestamp);
     } catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
-      return getSessionCatalog().loadTable(ident, timestamp);
+      return loadTable(getSessionCatalog(), ident, version, timestamp);
+    } catch (org.apache.iceberg.exceptions.NotFoundException e) {
+      if (loadCatalogTableWhenMetadataNotFoundEnabled()) {

Review Comment:
   hi @aokolnychyi @RussellSpitzer I tried to move this logic to tableExists 
method, but it looks like that also wont work.  Spark calls loadTable when it 
tries to convert Unresolvedrelation to resolved table in 
   
   
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala#L1151
   
   ```
         case u @ UnresolvedTableOrView(identifier, cmd, allowTempView) =>
           lookupTableOrView(identifier).map {
             case v: ResolvedView if v.isTemp && !allowTempView =>
               throw 
QueryCompilationErrors.expectTableOrPermanentViewNotTempViewError(
                 identifier.quoted, cmd, u)
             case other => other
           }.getOrElse(u)
   
       private def lookupTableOrView(identifier: Seq[String]): 
Option[LogicalPlan] = {
         lookupTempView(identifier).map { _ =>
           ResolvedView(identifier.asIdentifier, isTemp = true)
         }.orElse {
           expandIdentifier(identifier) match {
             case CatalogAndIdentifier(catalog, ident) =>
               **CatalogV2Util.loadTable(catalog, ident)**.map {
                 case v1Table: V1Table if 
CatalogV2Util.isSessionCatalog(catalog) &&
                   v1Table.v1Table.tableType == CatalogTableType.VIEW =>
                   ResolvedView(ident, isTemp = false)
                 case table =>
                   ResolvedTable.create(catalog.asTableCatalog, ident, table)
               }
             case _ => None
           }
         }
       }
   ```
   
   Could you please advise what else I can try here. TIA
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to