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

    https://github.com/apache/spark/pull/1791#discussion_r15916811
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -1684,11 +1812,57 @@ def zip(self, other):
             >>> x.zip(y).collect()
             [(0, 1000), (1, 1001), (2, 1002), (3, 1003), (4, 1004)]
             """
    +        if self.getNumPartitions() != other.getNumPartitions():
    +            raise ValueError("the number of partitions dose not match"
    +                             " with each other")
    +
             pairRDD = self._jrdd.zip(other._jrdd)
             deserializer = PairDeserializer(self._jrdd_deserializer,
                                             other._jrdd_deserializer)
             return RDD(pairRDD, self.ctx, deserializer)
     
    +    def zipPartitions(self, other, f, preservesPartitioning=False):
    +        """
    +        Zip this RDD's partitions with one (or more) RDD(s) and return a
    +        new RDD by applying a function to the zipped partitions.
    +
    +        Not implemented.
    +        """
    +        raise NotImplementedError
    +
    +    def zipWithIndex(self):
    +        """
    +        Zips this RDD with its element indices.
    +
    +        >>> sc.parallelize(range(4), 2).zipWithIndex().collect()
    +        [(0, 0), (1, 1), (2, 2), (3, 3)]
    +        """
    +        nums = self.glom().map(lambda it: sum(1 for i in it)).collect()
    +        starts = [0]
    +        for i in range(len(nums) - 1):
    +            starts.append(starts[-1] + nums[i])
    +
    +        def func(k, it):
    +            for i, v in enumerate(it):
    +                yield starts[k] + i, v
    +
    +        return self.mapPartitionsWithIndex(func)
    +
    +    def zipWithUniqueId(self):
    +        """
    +        Zips this RDD with generated unique Long ids.
    --- End diff --
    
    Same case here: this should be similarly descriptive to the Scala docs:
    
    ```scala
     /**
       * Zips this RDD with generated unique Long ids. Items in the kth 
partition will get ids k, n+k,
       * 2*n+k, ..., where n is the number of partitions. So there may exist 
gaps, but this method
       * won't trigger a spark job, which is different from 
[[org.apache.spark.rdd.RDD#zipWithIndex]].
       */
      def zipWithUniqueId(): RDD[(T, Long)] = {
    ```


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