Skip to content

Commit 642b0bb

Browse files
committed
Further expand comment / reasoning
1 parent 06aba0c commit 642b0bb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/Exchange.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,14 @@ private[sql] case class EnsureRequirements(sqlContext: SQLContext) extends Rule[
253253

254254
private def ensureDistributionAndOrdering(operator: SparkPlan): SparkPlan = {
255255

256-
// Precondition: joins' children have compatible partitionings.
257-
258256
def addShuffleIfNecessary(child: SparkPlan, requiredDistribution: Distribution): SparkPlan = {
257+
// A pre-condition of ensureDistributionAndOrdering is that joins' children have compatible
258+
// partitionings. Thus, we only need to check whether the output partitionings satisfy
259+
// the required distribution. In the case where the children are all compatible, then they
260+
// will either all satisfy the required distribution or will all fail to satisfy it:, since
261+
// (A.guarantees(B) && B.satisfies(C)) => A.satisfies(C).
262+
// Therefore, if all children are compatible then either all or none of them will shuffled to
263+
// ensure that the distribution requirements are met.
259264
if (child.outputPartitioning.satisfies(requiredDistribution)) {
260265
child
261266
} else {

0 commit comments

Comments
 (0)