rdblue commented on a change in pull request #2141:
URL: https://github.com/apache/iceberg/pull/2141#discussion_r563952297
##########
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:
This is here and not in `prepareQuery` because we don't want to assume
that a global ordering always requires an extra round-robin repartition? If so,
it would be good to move the comment above `newChildPlan` and make it a bit
more clear why this extra step is happening.
----------------------------------------------------------------
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]