Github user mengxr commented on the pull request:
https://github.com/apache/spark/pull/3291#issuecomment-63270709
One way to do this lazily is via shuffle:
~~~scala
val identityPartitioner = new Partitioner {
override def numPartitions: Int = p
override def getPartition(key: Any): Int = key.asInstanceOf[Int]
}
val startIndices = PartitionPruningRDD.create(this, _ < p - 1) //
skip the last partition
.mapPartitionsWithIndex { (split, iter) =>
val size = Utils.getIteratorSize(iter)
Iterator.range(split + 1, p).map { i =>
(i, size)
}
}.reduceByKey(identityPartitioner, _ + _)
.values
this.zipPartitions(startIndices) { (iter, startIndexIter) =>
val startIndex = if (startIndexIter.hasNext) startIndexIter.next()
else 0L
iter.zipWithIndex.map { case (item, localIndex) =>
(item, startIndex + localIndex)
}
}
~~~
But I think this is more expensive.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]