Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor addOperatorsIfNecessary to make code clearer
  • Loading branch information
JoshRosen committed Jul 14, 2015
commit e86649489158eeb30ce09f10a78663f0a438a4ae
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,25 @@ private[sql] case class EnsureRequirements(sqlContext: SQLContext) extends Rule[
partitioning: Partitioning,
rowOrdering: Seq[SortOrder],
child: SparkPlan): SparkPlan = {
val needSort = rowOrdering.nonEmpty && child.outputOrdering != rowOrdering
val needsShuffle = child.outputPartitioning != partitioning

val withShuffle = if (needsShuffle) {
Exchange(partitioning, child)
} else {
child
def addShuffleIfNecessary(child: SparkPlan): SparkPlan = {
if (child.outputPartitioning != partitioning) {
Exchange(partitioning, child)
} else {
child
}
}

val withSort = if (needSort) {
sqlContext.planner.BasicOperators.getSortOperator(
rowOrdering, global = false, withShuffle)
} else {
withShuffle
def addSortIfNecessary(child: SparkPlan): SparkPlan = {
if (rowOrdering.nonEmpty && child.outputOrdering != rowOrdering) {
sqlContext.planner.BasicOperators.getSortOperator(
rowOrdering, global = false, child)
} else {
child
}
}

withSort
addSortIfNecessary(addShuffleIfNecessary(child))
}

if (meetsRequirements && compatible && !needsAnySort) {
Expand Down