转换JavaRDD <arraylist <t>&gt;到JavaRDD <t>

时间:2015-11-02 22:43:56

标签: java apache-spark

是否有使用Apache-Spark的Java API将JavaRDD<ArrayList<T>>转换为JavaRDD<T>的直接方式?

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

我想将JavaRDD<ArrayList<Record>>转换为JavaRDD<Record>

1 个答案:

答案 0 :(得分:2)

您可以简单地flatMap

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