GitHub user davies opened a pull request:
https://github.com/apache/spark/pull/2092
[SPARK-2871] [PySpark] add zipWithIndex() and zipWithUniqueId()
RDD.zipWithIndex()
Zips this RDD with its element indices.
The ordering is first based on the partition index and then the
ordering of items within each partition. So the first item in
the first partition gets index 0, and the last item in the last
partition receives the largest index.
This method needs to trigger a spark job when this RDD contains
more than one partitions.
>>> sc.parallelize(range(4), 2).zipWithIndex().collect()
[(0, 0), (1, 1), (2, 2), (3, 3)]
RDD.zipWithUniqueId()
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
L{zipWithIndex}
>>> sc.parallelize(range(4), 2).zipWithUniqueId().collect()
[(0, 0), (2, 1), (1, 2), (3, 3)]
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/davies/spark zipWith
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/2092.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #2092
----
commit 0d2a128da7f24214e6714a93f7402aaea93075f2
Author: Davies Liu <[email protected]>
Date: 2014-08-22T04:42:00Z
add zipWithIndex() and zipWithUniqueId()
----
---
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]