Github user mateiz commented on a diff in the pull request: https://github.com/apache/spark/pull/80#discussion_r10364898 --- Diff: python/pyspark/rdd.py --- @@ -319,6 +319,22 @@ def union(self, other): return RDD(self_copy._jrdd.union(other_copy._jrdd), self.ctx, self.ctx.serializer) + def intersection(self, other): + """ + Return the intersection of this RDD and another one. + + Note: The output will not contain any duplicate elements, even if the + input RDDs did. + + >>> rdd1 = sc.parallelize([1, 10, 2, 3, 4, 5]) + >>> rdd2 = sc.parallelize([1, 6, 2, 3, 7, 8]) + >>> rdd1.intersection(rdd2).collect() + [1, 2, 3] + """ + return self.map(lambda v: (v, None)).cogroup( + other.map(lambda v: (v, None))).filter( + lambda x: (len(x[1][0]) != 0) and (len(x[1][1]) != 0)).keys() --- End diff -- Probably slightly nicer to write this like this: ``` return self.map(lambda v: (v, None)) \ .cogroup(other.map(lambda v: (v, None))) \ .filter(lambda x: (len(x[1][0]) != 0) and (len(x[1][1]) != 0)) \ .keys() ``` Or put parens around the whole thing to avoid Python thinking lines ended (but we used the backslash style before). Other than that it looks good.
--- 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. ---