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

    https://github.com/apache/spark/pull/8511#discussion_r38269159
  
    --- Diff: 
core/src/main/scala/org/apache/spark/rdd/MapPartitionsWithPreparationRDD.scala 
---
    @@ -38,12 +38,25 @@ private[spark] class MapPartitionsWithPreparationRDD[U: 
ClassTag, T: ClassTag, M
     
       override def getPartitions: Array[Partition] = firstParent[T].partitions
     
    +  private[this] var preparedArgument: Option[M] = None
    +
    +  def prepare(): Unit = {
    +    // This could be called multiple times
    +    if (preparedArgument.isEmpty) {
    +      preparedArgument = Some(preparePartition())
    +    }
    +  }
    +
       /**
        * Prepare a partition before computing it from its parent.
        */
       override def compute(partition: Partition, context: TaskContext): 
Iterator[U] = {
    -    val preparedArgument = preparePartition()
    +    prepare()
    +    // The same RDD could be called multiple times in one task, each call 
of compute() should
    +    // have separate prepared argument.
    +    val prepared = preparedArgument.get
    +    preparedArgument = None
    --- End diff --
    
    Is the idea here that if someone explicitly called `prepare()` before, then 
the `compute` should not `prepare` again? When will `compute` be called 
multiple times in the same task?


---
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]

Reply via email to