Github user tgravescs commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11327#discussion_r57363138
  
    --- Diff: core/src/main/scala/org/apache/spark/rdd/CoalescedRDD.scala ---
    @@ -324,6 +319,40 @@ private class PartitionCoalescer(maxPartitions: Int, 
prev: RDD[_], balanceSlack:
             }
           }
         } else {
    +      // It is possible to have unionRDD where one rdd has preferred 
locations and another rdd
    +      // that doesn't. To make sure we end up with the requested number of 
partitions,
    +      // make sure to put a partitions in every group.
    +
    +      if (groupArr.size > initialHash.size) {
    +        // we don't have a partition assigned to every group yet so first 
try to fill them
    +        // with the partitions with preferred locations
    +        var tries = 0
    +        val rotIt = new LocationIterator(prev)
    +        while (tries < prev.partitions.length && initialHash.size < 
groupArr.size) {
    +          // if the number of partitions with preferred locations is less 
then
    +          // number of total partitions this might loop over some more 
then once but we need to
    +          // handle both cases and its not easy to get # of partitions 
with preferred locs
    +          var (nxt_replica, nxt_part) = rotIt.next()
    +          if (!initialHash.contains(nxt_part)) {
    +            groupArr.find(pg => pg.size == 0).map(firstEmpty => {
    +              firstEmpty.arr += nxt_part
    +              initialHash += nxt_part
    +            })
    +          }
    +          tries += 1
    +        }
    +      }
    +      // we have went through all with preferred locations now just make 
sure one
    +      // partition per group
    +      val numEmptyPartitionGroups = groupArr.length - getPartitions.length
    --- End diff --
    
    i split it this way because one is called setupGroups and the throwballs 
one is put stuff in the groups. I see the fact we put stuff in them in 
setupgroup as an optimization rather then a necessity. 
    
    Do you see a benefit to do it there vs here? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to