aokolnychyi commented on a change in pull request #2116:
URL: https://github.com/apache/iceberg/pull/2116#discussion_r560563077
##########
File path:
spark3-extensions/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteMergeInto.scala
##########
@@ -58,53 +61,138 @@ case class RewriteMergeInto(conf: SQLConf) extends
Rule[LogicalPlan] with Rewrit
override def apply(plan: LogicalPlan): LogicalPlan = {
plan resolveOperators {
+ case MergeIntoTable(target: DataSourceV2Relation, source: LogicalPlan,
cond, matchedActions, notMatchedActions)
+ if matchedActions.isEmpty =>
+
+ val mergeBuilder = target.table.asMergeable.newMergeBuilder("merge",
newWriteInfo(target.schema))
+ val targetTableScan = buildSimpleScanPlan(target.table, target.output,
mergeBuilder, cond)
+
+ // when there are no matched actions, use a left anti join to remove
any matching rows and rewrite to use
+ // append instead of replace. only unmatched source rows are passed to
the merge and actions are all inserts.
+ val joinPlan = Join(source, targetTableScan, LeftAnti, Some(cond),
JoinHint.NONE)
+
+ val mergeParams = MergeIntoParams(
Review comment:
My assumption was that there may be only one WHEN NOT MATCHED clause
which is not true starting from Spark 3.1.0. If we have only one, though, we
can just use a projection. I guess CASE ... WHEN approach can work even in a
generic case. Let's do it later.
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]