Merge pull request #351 from stephenh/values
Add PairRDDFunctions.keys and values.
This commit is contained in:
commit
b1663752c6
|
@ -615,6 +615,16 @@ class PairRDDFunctions[K: ClassManifest, V: ClassManifest](
|
||||||
writer.cleanup()
|
writer.cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an RDD with the keys of each tuple.
|
||||||
|
*/
|
||||||
|
def keys: RDD[K] = self.map(_._1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an RDD with the values of each tuple.
|
||||||
|
*/
|
||||||
|
def values: RDD[V] = self.map(_._2)
|
||||||
|
|
||||||
private[spark] def getKeyClass() = implicitly[ClassManifest[K]].erasure
|
private[spark] def getKeyClass() = implicitly[ClassManifest[K]].erasure
|
||||||
|
|
||||||
private[spark] def getValueClass() = implicitly[ClassManifest[V]].erasure
|
private[spark] def getValueClass() = implicitly[ClassManifest[V]].erasure
|
||||||
|
|
|
@ -216,6 +216,13 @@ class ShuffleSuite extends FunSuite with ShouldMatchers with BeforeAndAfter {
|
||||||
// Test that a shuffle on the file works, because this used to be a bug
|
// Test that a shuffle on the file works, because this used to be a bug
|
||||||
assert(file.map(line => (line, 1)).reduceByKey(_ + _).collect().toList === Nil)
|
assert(file.map(line => (line, 1)).reduceByKey(_ + _).collect().toList === Nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("keys and values") {
|
||||||
|
sc = new SparkContext("local", "test")
|
||||||
|
val rdd = sc.parallelize(Array((1, "a"), (2, "b")))
|
||||||
|
assert(rdd.keys.collect().toList === List(1, 2))
|
||||||
|
assert(rdd.values.collect().toList === List("a", "b"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ShuffleSuite {
|
object ShuffleSuite {
|
||||||
|
|
Loading…
Reference in a new issue