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

    https://github.com/apache/spark/pull/2194#discussion_r17016536
  
    --- Diff: core/src/test/java/org/apache/spark/JavaAPISuite.java ---
    @@ -708,6 +708,104 @@ public void mapPartitions() {
       }
     
       @Test
    +  public void mapPartitionsWithContext() {
    +    JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 2, 3, 4), 2);
    +    JavaRDD<String> partitionSumsWithContext = 
rdd.mapPartitionsWithContext(
    +      new Function2<TaskContext, Iterator<Integer>, Iterator<String>>() {
    +        @Override
    +        public Iterator<String> call(TaskContext context,
    +          Iterator<Integer> iter) throws Exception {
    +
    +          int sum = 0;
    +          while (iter.hasNext()) {
    +            sum += iter.next();
    +          }
    +          return Collections.singletonList(sum + "-partition-" + 
context.partitionId()).iterator();
    +        }
    +      }, false);
    +    Assert.assertEquals("[3-partition-0, 7-partition-1]",
    +            partitionSumsWithContext.collect().toString());
    +  }
    +
    +  @Test
    +  public void mapPartitionsToPair() {
    +    JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 2, 3, 4), 2);
    +    JavaPairRDD<Integer, String> pairRdd = rdd.mapPartitionsToPair(
    +      new PairFlatMapFunction<Iterator<Integer>, Integer, String>() {
    +        @Override
    +        public Iterable<Tuple2<Integer, String>> call(Iterator<Integer> 
iter) throws Exception {
    +          int sum = 0;
    +          while (iter.hasNext()) {
    +            sum += iter.next();
    +          }
    +          return Collections.singletonList(new Tuple2<Integer, 
String>(sum, "a"));
    +        }
    +      }
    +    );
    +
    +    Assert.assertEquals("[(3,a), (7,a)]", pairRdd.collect().toString());
    +  }
    +
    +  @Test
    +  public void mapPartitionsToPairWithContext() {
    +    JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 2, 3, 4), 2);
    +    JavaPairRDD<Integer, String> pairRdd = 
rdd.mapPartitionsToPairWithContext(
    +      new PairFlatMapFunction2<TaskContext, Iterator<Integer>, Integer, 
String>() {
    +        @Override
    +        public Iterable<Tuple2<Integer, String>> call(TaskContext context, 
Iterator<Integer> iter)
    +          throws Exception {
    +
    +          int sum = 0;
    +          while (iter.hasNext()) {
    +            sum += iter.next();
    +          }
    +          return Collections.singletonList(
    +                   new Tuple2<Integer, String>(sum, "partition-" + 
context.partitionId()));
    +        }
    +      }, false);
    +
    +    Assert.assertEquals("[(3,partition-0), (7,partition-1)]", 
pairRdd.collect().toString());
    +  }
    +
    +  @Test
    +  public void mapPartitionsToDouble() {
    --- End diff --
    
    remove this once you remove the api above


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

Reply via email to