Spark相关变换函数

Spark-Rdd-Transform

  1. 函数相关注解
    返回指向新rdd的指针,在rdd之间创建依赖关系。每个rdd都有计算函数和指向父RDD的指针。

 map()                                   //对每个元素进行变换,应用变换函数
                                         //(T)=>V
 filter()                                //过滤器,(T)=>Boolean
 flatMap()                               //压扁,T => TraversableOnce[U]
 mapPartitions()                         //对每个分区进行应用变换,输入的Iterator,返回新的迭代器,可以对分区进行函数处理。
                                         //Iterator<T> => Iterator<U>
 mapPartitionsWithIndex(func)            //同上,(Int, Iterator<T>) => Iterator<U>
 sample(withReplacement, fraction, seed) //采样返回采样的RDD子集。
                                         //withReplacement 元素是否可以多次采样.
                                         //fraction : 期望采样数量.[0,1]
 union()                                 //类似于mysql union操作。
                                         //select * from persons where id < 10 
                                         //union select * from id persons where id > 29 ;
 intersection                            //交集,提取两个rdd中都含有的元素。
 distinct([numTasks]))                   //去重,去除重复的元素。
 groupByKey()                            //(K,V) => (K,Iterable<V>)
 reduceByKey(*)                          //按key聚合。 
 aggregateByKey(zeroValue)(seqOp, combOp, [numTasks])
                                         //按照key进行聚合
 key:String U:Int = 0//排序
 sortByKey                               //连接,(K,V).join(K,W) =>(K,(V,W)) 
 join(otherDataset, [numTasks])          //协分组
 cogroup                                 //(K,V).cogroup(K,W) =>(K,(Iterable<V>,Iterable<!-- <W> -->)) 
                                         //笛卡尔积,RR[T] RDD[U] => RDD[(T,U)]
 cartesian(otherDataset)                 //将rdd的元素传递给脚本或者命令,执行结果返回形成新的RDD
 pipe                                    //减少分区
 coalesce(numPartitions)                 //可增可减
 repartition                              
 repartitionAndSortWithinPartitions(partitioner)//再分区并在分区内进行排序

 

 

2.相关使用方法

1.map(func)

2.flatMap(func)

3.mapPartitions(func)

4.mapPartitionsWithIndex(func)

5.simple(withReplacement,fraction,seed)

6.union(ortherDataset)

7.intersection(otherDataset)

8.distinct([numTasks])

9.cartesian(otherDataset)

10.coalesce(numPartitions,shuffle)

11.repartition(numPartition)

12.glom()

13.randomSplit(weight:Array[Double],seed)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值