Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ import org.apache.spark.{HashPartitioner, Partitioner, RangePartitioner, SparkEn

/**
* :: DeveloperApi ::
* Performs a shuffle that will result in the desired `newPartitioning`. Optionally sorts each
* resulting partition based on expressions from the partition key. It is invalid to construct an
* exchange operator with a `newOrdering` that cannot be calculated using the partitioning key.
* Performs a shuffle that will result in the desired `newPartitioning`.
*/
@DeveloperApi
case class Exchange(
newPartitioning: Partitioning,
newOrdering: Seq[SortOrder],
child: SparkPlan)
extends UnaryNode {
case class Exchange(newPartitioning: Partitioning, child: SparkPlan) extends UnaryNode {

override def outputPartitioning: Partitioning = newPartitioning

override def outputOrdering: Seq[SortOrder] = newOrdering

override def output: Seq[Attribute] = child.output

/**
Expand Down Expand Up @@ -279,23 +271,24 @@ 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, Nil, 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
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
case logical.OneRowRelation =>
execution.PhysicalRDD(Nil, singleRowRdd) :: Nil
case logical.RepartitionByExpression(expressions, child) =>
execution.Exchange(
HashPartitioning(expressions, numPartitions), Nil, planLater(child)) :: Nil
execution.Exchange(HashPartitioning(expressions, numPartitions), planLater(child)) :: Nil
case e @ EvaluatePython(udf, child, _) =>
BatchPythonEvaluation(udf, e.output, planLater(child)) :: Nil
case LogicalRDD(output, rdd) => PhysicalRDD(output, rdd) :: Nil
Expand Down