scala mapPartitionsWithIndex函数的使用

丈夫志四海,万里犹比邻。这篇文章主要讲述scala mapPartitionsWithIndex函数的使用相关的知识,希望能为你提供帮助。
var rdd1=sc.makeRDD(Array((1,"A"),(2,"B"),(3,"C"),(4,"D")),2)
rdd1.partitions.size
res20:int=2
rdd1.mapPartitionsWithIndex{
(partIdx,iter)=> {
  var part_map=scala.collection.mutable.Map[string,List[(Int,String)]]()
  while(iter.hasNext)
{
  var part_name="part_"+partIdx;
  var elem=iter.next();
【scala mapPartitionsWithIndex函数的使用】  if(part_map.contains(part_name)){
  var elems=part_map(part_name)
elems::=elem
part_map(part_name)=elems
} else{
  part_map(part_name)=List[(Int,String)]{elem}
}
}
part_map.iterator
}}.collect
 

    推荐阅读