diff options
author | witgo <witgo@qq.com> | 2014-04-29 11:30:47 -0700 |
---|---|---|
committer | Reynold Xin <rxin@apache.org> | 2014-04-29 11:30:47 -0700 |
commit | 7d1505841069c6ecc3fa7e4896db535f18e4ce84 (patch) | |
tree | 7d28c5f3e8db400d508072953ec92334fb5a23ba /core/src/test | |
parent | 8db0f7e28f5f0330a3344705ff48d8e7b97c383f (diff) | |
download | spark-7d1505841069c6ecc3fa7e4896db535f18e4ce84.tar.gz spark-7d1505841069c6ecc3fa7e4896db535f18e4ce84.tar.bz2 spark-7d1505841069c6ecc3fa7e4896db535f18e4ce84.zip |
SPARK-1509: add zipWithIndex zipWithUniqueId methods to java api
Author: witgo <witgo@qq.com>
Closes #423 from witgo/zipWithIndex and squashes the following commits:
039ec04 [witgo] Merge branch 'master' of https://github.com/apache/spark into zipWithIndex
24d74c9 [witgo] review commit
763a5e4 [witgo] Merge branch 'master' of https://github.com/apache/spark into zipWithIndex
59747d1 [witgo] review commit
7bf4d06 [witgo] Merge branch 'master' of https://github.com/apache/spark into zipWithIndex
daa8f84 [witgo] review commit
4070613 [witgo] Merge branch 'master' of https://github.com/apache/spark into zipWithIndex
18e6c97 [witgo] java api zipWithIndex test
11e2e7f [witgo] add zipWithIndex zipWithUniqueId methods to java api
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/java/org/apache/spark/JavaAPISuite.java | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/core/src/test/java/org/apache/spark/JavaAPISuite.java b/core/src/test/java/org/apache/spark/JavaAPISuite.java index 76c6f5af82..c3e03cea91 100644 --- a/core/src/test/java/org/apache/spark/JavaAPISuite.java +++ b/core/src/test/java/org/apache/spark/JavaAPISuite.java @@ -182,13 +182,30 @@ public class JavaAPISuite implements Serializable { Assert.assertEquals(2, foreachCalls); } - @Test - public void toLocalIterator() { - List<Integer> correct = Arrays.asList(1, 2, 3, 4); - JavaRDD<Integer> rdd = sc.parallelize(correct); - List<Integer> result = Lists.newArrayList(rdd.toLocalIterator()); - Assert.assertTrue(correct.equals(result)); - } + @Test + public void toLocalIterator() { + List<Integer> correct = Arrays.asList(1, 2, 3, 4); + JavaRDD<Integer> rdd = sc.parallelize(correct); + List<Integer> result = Lists.newArrayList(rdd.toLocalIterator()); + Assert.assertTrue(correct.equals(result)); + } + + @Test + public void zipWithUniqueId() { + List<Integer> dataArray = Arrays.asList(1, 2, 3, 4); + JavaPairRDD<Integer, Long> zip = sc.parallelize(dataArray).zipWithUniqueId(); + JavaRDD<Long> indexes = zip.values(); + Assert.assertTrue(new HashSet<Long>(indexes.collect()).size() == 4); + } + + @Test + public void zipWithIndex() { + List<Integer> dataArray = Arrays.asList(1, 2, 3, 4); + JavaPairRDD<Integer, Long> zip = sc.parallelize(dataArray).zipWithIndex(); + JavaRDD<Long> indexes = zip.values(); + List<Long> correctIndexes = Arrays.asList(0L, 1L, 2L, 3L); + Assert.assertTrue(indexes.collect().equals(correctIndexes)); + } @SuppressWarnings("unchecked") @Test |