cloud-fan commented on code in PR #52866:
URL: https://github.com/apache/spark/pull/52866#discussion_r2521786045


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala:
##########
@@ -893,16 +893,46 @@ case class MergeIntoTable(
   }
 
   lazy val needSchemaEvolution: Boolean =
+    evaluateSchemaEvolution && changesForSchemaEvolution.nonEmpty
+
+  lazy val evaluateSchemaEvolution: Boolean =
     schemaEvolutionEnabled &&
-      MergeIntoTable.schemaChanges(targetTable.schema, 
sourceTable.schema).nonEmpty
+      canEvaluateSchemaEvolution
 
-  private def schemaEvolutionEnabled: Boolean = withSchemaEvolution && {
+  lazy val schemaEvolutionEnabled: Boolean = withSchemaEvolution && {
     EliminateSubqueryAliases(targetTable) match {
       case r: DataSourceV2Relation if r.autoSchemaEvolution() => true
       case _ => false
     }
   }
 
+  // Guard that assignments are either resolved or candidates for evolution 
before
+  // evaluating schema evolution. We need to use resolved assignment values to 
check
+  // candidates, see MergeIntoTable.sourceSchemaForSchemaEvolution for details.
+  lazy val canEvaluateSchemaEvolution: Boolean = {
+    if ((!targetTable.resolved) || (!sourceTable.resolved)) {
+      false
+    } else {
+      val actions = matchedActions ++ notMatchedActions
+      val assignments = actions.collect {
+        case a: UpdateAction => a.assignments
+        case a: InsertAction => a.assignments
+      }.flatten
+
+      val sourcePaths = MergeIntoTable.extractAllFieldPaths(sourceTable.schema)
+      assignments.forall { assignment =>
+        assignment.resolved ||
+          sourcePaths.exists { path => MergeIntoTable.isEqual(assignment, 
path) }

Review Comment:
   and the assignment value must be resolved.



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