-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spark 3.4: Multiple shuffle partitions per file in compaction (#7897)
- Loading branch information
1 parent
f5bb0c0
commit d98e7a1
Showing
7 changed files
with
242 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...spark/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/OrderAwareCoalesce.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.catalyst.plans.logical | ||
|
||
import org.apache.spark.rdd.PartitionCoalescer | ||
import org.apache.spark.rdd.PartitionGroup | ||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.sql.catalyst.expressions.Attribute | ||
|
||
// this node doesn't extend RepartitionOperation on purpose to keep this logic isolated | ||
// and ignore it in optimizer rules such as CollapseRepartition | ||
case class OrderAwareCoalesce( | ||
numPartitions: Int, | ||
coalescer: PartitionCoalescer, | ||
child: LogicalPlan) extends OrderPreservingUnaryNode { | ||
|
||
override def output: Seq[Attribute] = child.output | ||
|
||
override protected def withNewChildInternal(newChild: LogicalPlan): LogicalPlan = { | ||
copy(child = newChild) | ||
} | ||
} | ||
|
||
class OrderAwareCoalescer(val groupSize: Int) extends PartitionCoalescer with Serializable { | ||
|
||
override def coalesce(maxPartitions: Int, parent: RDD[_]): Array[PartitionGroup] = { | ||
val partitionBins = parent.partitions.grouped(groupSize) | ||
partitionBins.map { partitions => | ||
val group = new PartitionGroup() | ||
group.partitions ++= partitions | ||
group | ||
}.toArray | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
spark/v3.4/spark/src/main/scala/org/apache/spark/sql/execution/OrderAwareCoalesceExec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.execution | ||
|
||
import org.apache.spark.rdd.PartitionCoalescer | ||
import org.apache.spark.rdd.RDD | ||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.expressions.Attribute | ||
import org.apache.spark.sql.catalyst.expressions.SortOrder | ||
import org.apache.spark.sql.catalyst.plans.physical.Partitioning | ||
import org.apache.spark.sql.catalyst.plans.physical.SinglePartition | ||
import org.apache.spark.sql.catalyst.plans.physical.UnknownPartitioning | ||
|
||
case class OrderAwareCoalesceExec( | ||
numPartitions: Int, | ||
coalescer: PartitionCoalescer, | ||
child: SparkPlan) extends UnaryExecNode { | ||
|
||
override def output: Seq[Attribute] = child.output | ||
|
||
override def outputOrdering: Seq[SortOrder] = child.outputOrdering | ||
|
||
override def outputPartitioning: Partitioning = { | ||
if (numPartitions == 1) SinglePartition else UnknownPartitioning(numPartitions) | ||
} | ||
|
||
protected override def doExecute(): RDD[InternalRow] = { | ||
val result = child.execute() | ||
if (numPartitions == 1 && result.getNumPartitions < 1) { | ||
// make sure we don't output an RDD with 0 partitions, | ||
// when claiming that we have a `SinglePartition` | ||
// see CoalesceExec in Spark | ||
new CoalesceExec.EmptyRDDWithPartitions(sparkContext, numPartitions) | ||
} else { | ||
result.coalesce(numPartitions, shuffle = false, Some(coalescer)) | ||
} | ||
} | ||
|
||
override protected def withNewChildInternal(newChild: SparkPlan): SparkPlan = { | ||
copy(child = newChild) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters