Skip to content

Commit 4649af4

Browse files
committed
inline.
1 parent 5453ad4 commit 4649af4

File tree

1 file changed

+13
-21
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer

1 file changed

+13
-21
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -567,32 +567,24 @@ object CollapseProject extends Rule[LogicalPlan] {
567567
object CollapseRepartition extends Rule[LogicalPlan] {
568568
def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
569569
// Case 1: When a Repartition has a child of Repartition or RepartitionByExpression,
570-
// we can collapse it with the child based on the type of shuffle and the specified number
571-
// of partitions.
572-
case r @ Repartition(_, _, child: RepartitionOperation) =>
573-
collapseRepartition(r, child)
574-
// Case 2: When a RepartitionByExpression has a child of Repartition or RepartitionByExpression
575-
// we can remove the child.
576-
case r @ RepartitionByExpression(_, child: RepartitionOperation, _) =>
577-
r.copy(child = child.child)
578-
}
579-
580-
/**
581-
* Collapses the [[Repartition]] with its child [[RepartitionOperation]], if possible.
582-
* - Case 1 the top [[Repartition]] does not enable shuffle (i.e., coalesce API):
583-
* If the last numPartitions is bigger, returns the child node; otherwise, keep unchanged.
584-
* - Case 2 the top [[Repartition]] enables shuffle (i.e., repartition API):
585-
* returns the child node with the last numPartitions.
586-
*/
587-
private def collapseRepartition(r: Repartition, child: RepartitionOperation): LogicalPlan = {
588-
(r.shuffle, child.shuffle) match {
570+
// 1) When the top node does not enable the shuffle (i.e., coalesce API), but the child
571+
// enables the shuffle. Returns the child node if the last numPartitions is bigger;
572+
// otherwise, keep unchanged.
573+
// 2) In the other cases, returns the child node with the last numPartitions.
574+
case r @ Repartition(_, _, child: RepartitionOperation) => (r.shuffle, child.shuffle) match {
589575
case (false, true) =>
590576
if (r.numPartitions >= child.numPartitions) child else r
591577
case _ => child match {
592-
case child: Repartition => child.copy(numPartitions = r.numPartitions, shuffle = r.shuffle)
593-
case child: RepartitionByExpression => child.copy(numPartitions = r.numPartitions)
578+
case child: Repartition =>
579+
child.copy(numPartitions = r.numPartitions, shuffle = r.shuffle)
580+
case child: RepartitionByExpression =>
581+
child.copy(numPartitions = r.numPartitions)
594582
}
595583
}
584+
// Case 2: When a RepartitionByExpression has a child of Repartition or RepartitionByExpression
585+
// we can remove the child.
586+
case r @ RepartitionByExpression(_, child: RepartitionOperation, _) =>
587+
r.copy(child = child.child)
596588
}
597589
}
598590

0 commit comments

Comments
 (0)