rekbun commented on code in PR #60256:
URL: https://github.com/apache/spark/pull/60256#discussion_r4566320759
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/GroupPartitionsExec.scala:
##########
@@ -866,27 +868,29 @@ private[sql] object GroupPartitionsExec {
* required for storage-partitioned operations.
*
* @param groupedPartitions Sequence where each element is a sequence of input
partition
- * indices that should be grouped together
+ * indices that should be grouped together. Only the
driver reads it,
+ * so it is not serialized into tasks.
*/
class GroupedPartitionCoalescer(
- val groupedPartitions: Seq[Seq[Int]]
+ @transient val groupedPartitions: Seq[Seq[Int]]
) extends PartitionCoalescer with Serializable {
override def coalesce(maxPartitions: Int, parent: RDD[_]):
Array[PartitionGroup] = {
+ require(groupedPartitions.size == maxPartitions,
s"GroupedPartitionCoalescer has " +
+ s"${groupedPartitions.size} groups but was asked for $maxPartitions
partitions")
+ val assigned = mutable.Map.empty[String, Int].withDefaultValue(0)
groupedPartitions.map { partitionIndices =>
- val partitions = new ArrayBuffer[Partition](partitionIndices.size)
- val preferredLocations = new ArrayBuffer[String](partitionIndices.size)
- partitionIndices.foreach { partitionIndex =>
- val partition = parent.partitions(partitionIndex)
- partitions += partition
- preferredLocations ++= parent.preferredLocations(partition)
+ val partitions = partitionIndices.map(parent.partitions(_))
+ // A group of one partition names no location, so the scheduler uses all
of that
+ // partition's locations. Otherwise prefer the location that the largest
number of the
+ // group's partitions report, and spread ties across groups rather than
sending them all to
+ // one location.
+ val preferredLocation = if (partitions.size == 1) None else {
Review Comment:
I took the first way: a group of one votes like any other group, so it names
a host, and the tie-spreading picks it. Your zipped case is the test "a group
of one partition keeps a location when zipped", which expects h1 and h3. The
description now says that over a scan, a group of one prefers one of its
input's hosts, where before the scheduler could use any of them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]