hililiwei commented on code in PR #5083:
URL: https://github.com/apache/iceberg/pull/5083#discussion_r919595365


##########
spark/v3.2/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteMergeIntoTable.scala:
##########
@@ -80,91 +82,136 @@ object RewriteMergeIntoTable extends 
RewriteRowLevelCommand {
   private final val ROW_ID_REF = FieldReference(ROW_ID)
 
   override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
-    case m @ MergeIntoIcebergTable(aliasedTable, source, cond, matchedActions, 
notMatchedActions, None)
+    case m @ MergeIntoIcebergTable(aliasedTable, _, _, matchedActions, 
notMatchedActions, None)
         if m.resolved && m.aligned && matchedActions.isEmpty && 
notMatchedActions.size == 1 =>
 
       EliminateSubqueryAliases(aliasedTable) match {
         case r: DataSourceV2Relation =>
-          // NOT MATCHED conditions may only refer to columns in source so 
they can be pushed down
-          val insertAction = notMatchedActions.head.asInstanceOf[InsertAction]
-          val filteredSource = insertAction.condition match {
-            case Some(insertCond) => Filter(insertCond, source)
-            case None => source
+          rewriteMergeIntoTableWithSingleNotMatchedAction(m, r)
+        case v: View =>
+          val relations = v.children.collect { case r: DataSourceV2Relation if 
r.table.isInstanceOf[SparkTable] =>
+            r
           }
-
-          // when there are no MATCHED actions, use a left anti join to remove 
any matching rows
-          // and switch to using a regular append instead of a row-level merge
-          // only unmatched source rows that match the condition are appended 
to the table
-          val joinPlan = Join(filteredSource, r, LeftAnti, Some(cond), 
JoinHint.NONE)
-
-          val outputExprs = insertAction.assignments.map(_.value)
-          val outputColNames = r.output.map(_.name)
-          val outputCols = outputExprs.zip(outputColNames).map { case (expr, 
name) =>
-            Alias(expr, name)()
+          val icebergTableView = relations.nonEmpty && relations.size == 1

Review Comment:
   So, is it enough to just use `relations.nonEmpty`?



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