标签:1.5 size ons lis style tab tor lse contains
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();
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
scala mapPartitionsWithIndex函数的使用
标签:1.5 size ons lis style tab tor lse contains
原文地址:https://www.cnblogs.com/chengjun/p/8954515.html