码迷,mamicode.com
首页 > 其他好文 > 详细

Spark Streaming Transformations

时间:2017-04-28 13:37:05      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:orm   point   参数   方法参数   组成   park   test   task   更新   

map(func):对DStream中的所有的元素进行func转换生成新的DStream

flatMap(func):和map方法类似,先对DStream中的元素进行func运算,然后压平,就是说,如果有一个元素是集合或者数组,那么会被拆成一个一个的元素

filter(func):对DStream中的元素进行func运算,把返回true的元素组成一个新的DStream

repartition(numPartitions): DStream重分区

union(otherStream):合并两个DStream

count(): 返回DStream中RDD中的元素的个数

reduce(func):聚合DStream中RDD的元素

countByValue():统计值出现的次数

reduceByKey(func, [numTasks]):对相同key的value进行func操作

join(otherStream, [numTasks]):相同key进行连接,(K, V) join (K, W) -> (K, (V, W))

cogroup(otherStream, [numTasks]):相同key进行右边的转换 (K, V) cogroup (K, W) (K, Seq[V], Seq[W])

transform(func): 对DStream中的RDD做func操作返回另外一个RDD

wordCounts.transform(rdd =>{
    rdd.filter(_._1 == "hello")
    rdd
})

updateStateByKey(func):根据key更新以前操作的结果,这个方法可以做累计操作,使用该方法要设置检查点目录,updateStateByKey方法参数需要指定类型

sc.setCheckpointDir("D://checkpoints/")
// 设置日志级别 sc.setLogLevel("ERROR") val ds1 = wordCounts.updateStateByKey[Int]((x:Seq[Int], y:Option[Int]) => { val newValue = x.sum + y.getOrElse(0) Some(newValue) })

  

Spark Streaming Transformations

标签:orm   point   参数   方法参数   组成   park   test   task   更新   

原文地址:http://www.cnblogs.com/heml/p/6780811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!