aokolnychyi commented on a change in pull request #2141:
URL: https://github.com/apache/iceberg/pull/2141#discussion_r563979984
##########
File path:
spark3-extensions/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteMergeInto.scala
##########
@@ -233,47 +215,23 @@ case class RewriteMergeInto(spark: SparkSession) extends
Rule[LogicalPlan] with
!(actions.size == 1 && hasUnconditionalDelete(actions.headOption))
}
- def buildWritePlan(
- childPlan: LogicalPlan,
- table: Table): LogicalPlan = {
- val defaultDistributionMode = table match {
- case iceberg: SparkTable if !iceberg.table.sortOrder.isUnsorted =>
- TableProperties.WRITE_DISTRIBUTION_MODE_RANGE
- case _ =>
- TableProperties.WRITE_DISTRIBUTION_MODE_DEFAULT
- }
-
+ private def buildWritePlan(childPlan: LogicalPlan, table: Table):
LogicalPlan = {
table match {
- case iceTable: SparkTable =>
- val numShufflePartitions = spark.sessionState.conf.numShufflePartitions
- val table = iceTable.table()
- val distributionMode: String = table.properties
- .getOrDefault(TableProperties.WRITE_DISTRIBUTION_MODE,
defaultDistributionMode)
- val order = toCatalyst(toOrderedDistribution(table.spec(),
table.sortOrder(), true), childPlan)
- DistributionMode.fromName(distributionMode) match {
- case DistributionMode.NONE =>
- Sort(buildSortOrder(order), global = false, childPlan)
- case DistributionMode.HASH =>
- val clustering = toCatalyst(toClusteredDistribution(table.spec()),
childPlan)
- val hashPartitioned = RepartitionByExpression(clustering,
childPlan, numShufflePartitions)
- Sort(buildSortOrder(order), global = false, hashPartitioned)
- case DistributionMode.RANGE =>
- val roundRobin = Repartition(numShufflePartitions, shuffle = true,
childPlan)
- Sort(buildSortOrder(order), global = true, roundRobin)
+ case iceberg: SparkTable =>
+ val distribution = Spark3Util.buildRequiredDistribution(iceberg.table)
+ val ordering = Spark3Util.buildRequiredOrdering(distribution,
iceberg.table)
+ val newChildPlan = distribution match {
+ case _: OrderedDistribution =>
+ // insert a round robin partitioning to avoid executing the join
twice
+ val numShufflePartitions = conf.numShufflePartitions
+ Repartition(numShufflePartitions, shuffle = true, childPlan)
Review comment:
Yes, we don't want to add a round-robin repartition during inserts, for
example. I'll add more info.
----------------------------------------------------------------
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]