Skip to content

Commit e866494

Browse files
committed
Refactor addOperatorsIfNecessary to make code clearer
1 parent 2e467da commit e866494

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,25 @@ private[sql] case class EnsureRequirements(sqlContext: SQLContext) extends Rule[
271271
partitioning: Partitioning,
272272
rowOrdering: Seq[SortOrder],
273273
child: SparkPlan): SparkPlan = {
274-
val needSort = rowOrdering.nonEmpty && child.outputOrdering != rowOrdering
275-
val needsShuffle = child.outputPartitioning != partitioning
276274

277-
val withShuffle = if (needsShuffle) {
278-
Exchange(partitioning, child)
279-
} else {
280-
child
275+
def addShuffleIfNecessary(child: SparkPlan): SparkPlan = {
276+
if (child.outputPartitioning != partitioning) {
277+
Exchange(partitioning, child)
278+
} else {
279+
child
280+
}
281281
}
282282

283-
val withSort = if (needSort) {
284-
sqlContext.planner.BasicOperators.getSortOperator(
285-
rowOrdering, global = false, withShuffle)
286-
} else {
287-
withShuffle
283+
def addSortIfNecessary(child: SparkPlan): SparkPlan = {
284+
if (rowOrdering.nonEmpty && child.outputOrdering != rowOrdering) {
285+
sqlContext.planner.BasicOperators.getSortOperator(
286+
rowOrdering, global = false, child)
287+
} else {
288+
child
289+
}
288290
}
289291

290-
withSort
292+
addSortIfNecessary(addShuffleIfNecessary(child))
291293
}
292294

293295
if (meetsRequirements && compatible && !needsAnySort) {

0 commit comments

Comments
 (0)