简体   繁体   中英

Convert an JavaRDD<ArrayList<T>> to JavaRDD<T>

Is there a direct way of converting JavaRDD<ArrayList<T>> to JavaRDD<T> using the Apache-Spark's Java API?

JavaPairRDD<NullWritable, ArrayList<Record>> baseRDD = sc.newAPIHadoopFile(args[2], InputFormat2.class, NullWritable.class,ArrayList.class, conf);  
JavaRDD<ArrayList<Record>> mapLines1 = baseRDD.values();

I want to convert the JavaRDD<ArrayList<Record>> to JavaRDD<Record> .

You can simply flatMap :

rdd.flatMap(new FlatMapFunction<ArrayList<Record>, Record>() {
  @Override
  public Iterable<Record> call(ArrayList<Record> records) {
    return records;
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM