rdblue commented on a change in pull request #25747: [SPARK-29039][SQL] 
centralize the catalog and table lookup logic
URL: https://github.com/apache/spark/pull/25747#discussion_r324401265
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ##########
 @@ -742,15 +751,49 @@ class Analyzer(
       case _ => plan
     }
 
+    private def tryResolveV2Relation(u: UnresolvedRelation): 
Option[DataSourceV2Relation] = {
+      import org.apache.spark.sql.catalog.v2.CatalogV2Implicits._
+      import org.apache.spark.sql.catalog.v2.utils.CatalogV2Util._
+
+      u.multipartIdentifier match {
+        // temporary views take precedence over catalog table names
+        case AsTemporaryViewIdentifier(ident) if 
catalog.isTemporaryTable(ident) =>
+          None
+
+        case nameParts =>
+          assert(nameParts.nonEmpty)
+          val CatalogAndRestNameParts(maybeCatalog, restNameParts) = nameParts
+          if (restNameParts.isEmpty) {
+            None
+          } else {
+            loadV2Table(
+              maybeCatalog.getOrElse(catalogManager.v2SessionCatalog),
+              restNameParts.toIdentifier
+            ).map(DataSourceV2Relation.create)
+          }
+      }
+    }
+
     def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
-      case i @ InsertIntoTable(u @ 
UnresolvedRelation(AsTableIdentifier(ident)), _, child, _, _)
-          if child.resolved =>
-        EliminateSubqueryAliases(lookupTableFromCatalog(ident, u)) match {
-          case v: View =>
-            u.failAnalysis(s"Inserting into a view is not allowed. View: 
${v.desc.identifier}.")
-          case other => i.copy(table = other)
+      case i @ InsertIntoStatement(u: UnresolvedRelation, _, _, _, _) if 
i.query.resolved =>
+        tryResolveV2Relation(u).map(v2Relation => i.copy(table = 
v2Relation)).getOrElse {
+          if (u.multipartIdentifier.length <= 2) {
+            val ident = u.multipartIdentifier match {
 
 Review comment:
   This should get the identifier value from an extractor instead.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to