rdblue commented on a change in pull request #2116:
URL: https://github.com/apache/iceberg/pull/2116#discussion_r560498600
##########
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)
Review comment:
`JoinHint.NONE` is no hint, so Spark will use logic (e.g., CBO) other
than the hint to decide whether to use a broadcast or sort-merge join.
In general, we don't want to do too much in Iceberg. Iceberg should provide
stats for CBO and join logic in Spark, and the optimizations should be in
Spark. There may be cases in the future where Spark is lagging, like bucketed
joins, but ideally we will keep the logic in Spark.
----------------------------------------------------------------
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]