rekbun commented on code in PR #60256:
URL: https://github.com/apache/spark/pull/60256#discussion_r4566318753
##########
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 {
+
partitions.flatMap(parent.preferredLocations).groupBy(identity).view.mapValues(_.size)
Review Comment:
Done in 4d1dbdf. The vote now reads each partition's hosts with
`parent.context.getPreferredLocs(parent, i)`, as `DefaultPartitionCoalescer`
does, so over a scan's mapped RDD it sees the scan's locations. Your case is
the test "groups over a mapped parent prefer the hosts of its lineage": group
(0, 1, 2) on h2, h1, h1 prefers h1. I replaced the test that pinned the old
fallback, and the same test now checks that a group names no host when nothing
in its lineage has one. Since the vote now reaches scans, I kept the title, and
the description says what changes over 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]