ryan-johnson-databricks commented on code in PR #40732:
URL: https://github.com/apache/spark/pull/40732#discussion_r1165864149


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveDefaultColumns.scala:
##########
@@ -551,24 +552,23 @@ case class ResolveDefaultColumns(resolveRelations: 
Rule[LogicalPlan]) extends Ru
    * Returns the schema for the target table of a DML command, looking into 
the catalog if needed.
    */
   private def getSchemaForTargetTable(table: LogicalPlan): Option[StructType] 
= {
-    table.foreach {
+    val resolved = table match {
+      case r: UnresolvedRelation if !r.skipSchemaResolution && !r.isStreaming 
=>
+        resolveRelation(r)
+      case other =>
+        other
+    }
+    var result: Option[StructType] = None
+    resolved.foreach {

Review Comment:
   This is a strange idiom... var + foreach... why not just return the result 
of `collectFirst` instead?
   ```scala
   resolved.collectFirst { 
     case r: UnresolvedCatalogRelation => r.tableMeta.schema
     case d: DataSourceV2Relation => 
CatalogV2Util.v2ColumnsToStructType(d.table.columns())
     case v: View if v.isTempViewStoringAnalyzedPlan => v.schema
   }
   ```
   (I'm assuming here that there's only one match in practice; otherwise it's 
undefined behavior which one we visit first/last)
   



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to