Github user davies commented on a diff in the pull request: https://github.com/apache/spark/pull/11327#discussion_r57361560 --- 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 => { --- End diff -- This is also O(N*N)
--- 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