Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/6454#discussion_r31267929
--- Diff: core/src/main/scala/org/apache/spark/rdd/CartesianRDD.scala ---
@@ -72,8 +74,21 @@ class CartesianRDD[T: ClassTag, U: ClassTag](
override def compute(split: Partition, context: TaskContext):
Iterator[(T, U)] = {
val currSplit = split.asInstanceOf[CartesianPartition]
+
+ val key = RDDBlockId(rdd2.id, currSplit.s2.index)
+ val updatedBlocks = new ArrayBuffer[(BlockId, BlockStatus)]
+ def cachedValues(): Iterator[U] = {
+ SparkEnv.get.blockManager.memoryStore.unrollSafely(key,
+ rdd2.iterator(currSplit.s2, context), updatedBlocks) match {
+ case Left(arr) =>
+ arr.iterator.asInstanceOf[Iterator[U]]
+ case Right(it) =>
+ it.asInstanceOf[Iterator[U]]
+ }
+ }
+
for (x <- rdd1.iterator(currSplit.s1, context);
- y <- rdd2.iterator(currSplit.s2, context)) yield (x, y)
+ y <- new InterruptibleIterator(context, cachedValues())) yield
(x, y)
--- End diff --
I'm confused how this actually makes things any faster. It seems like even
if you do unroll `rdd2.iterator` into an array, you just get an iterator and
you don't hold on to the array. Doesn't this still lead to `rdd2.iterator`
getting called for every element in `rdd1.iterator`? I'd think you would need
to do something like:
```
val arrayValues: Option[Array[U]] = {
SparkEnv.get.blockManager.memoryStore.unrollSafely(key,
rdd2.iterator(currSplit.s2, context), updatedBlocks) match {
case Left(arr) => Some(arr)
case Right(it) => None
}
}
def getRdd2Values(): Iterator[U] = arrayValues.getOrElse {
rdd2.iterator(currSplit.s2, context) }
```
---
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]