Spark Streaming DSstream 的updateByKey用法
来源:互联网 发布:iphone6蜂窝数据4g设置 编辑:程序博客网 时间:2024/05/22 12:32
package org.lm.spark.streamingimport org.apache.spark.streaming.{Seconds, StreamingContext}import org.apache.spark.{SparkConf, SparkContext}object StatefulWordCountOnLine { def main(args: Array[String]): Unit = {
//定义updateByKey使用到的函数 val updateFunc=(values:Seq[Int],state:Option[Int])=>{ val currentCount=values.foldLeft(0)(_+_) val previousCount=state.getOrElse(0) Some(currentCount+previousCount) } val conf=new SparkConf().setAppName("Stateful Word Count On Line").setMaster("spark://192.168.189.128:7077") val sc=new SparkContext(conf) val ssc=new StreamingContext(sc,Seconds(5))
//定义持久化存储位置,很重要,必须定义 ssc.checkpoint("hdfs://192.168.189.128:9000/user/input/StatefulWordCount/log") val lines=ssc.socketTextStream("192.168.189.129",9999) val words=lines.flatMap(_.split(" ")) val pairs=words.map(word=>(word,1))
//调用updateStateByKey方法,参数传入前面定义的updateFunc函数 val statefulDStream=pairs.updateStateByKey[Int](updateFunc) statefulDStream.print() ssc.start() ssc.awaitTermination() }}
阅读全文
0 0
- Spark Streaming DSstream 的updateByKey用法
- spark streaming updateStateByKey 用法
- spark streaming updateStateByKey 用法
- spark streaming updateStateByKey 用法
- spark streaming updateStateByKey 用法
- UpdateByKey
- Spark Streaming的WindowedDStream
- Spark Streaming的窗口操作
- Spark Streaming 的 UpdateStateByKey操作
- Spark Streaming 的一些问题
- 自定义Spark Streaming的Receivers
- Spark Streaming的窗口操作
- 学习 Spark Streaming 的重要性
- Spark-Streaming checkpoint的原理
- Spark Streaming的入门介绍
- spark-streaming系列------- 1. spark-streaming的Job调度 上
- spark-streaming系列------- 2. spark-streaming的Job调度 下
- spark流数据处理:Spark Streaming的使用
- 自定义安全过滤
- jdbc.properties备忘录
- haskell学习笔记(5)-函数与递归
- Js写购物车全选全不选计算单价总价代码
- 欧拉角
- Spark Streaming DSstream 的updateByKey用法
- 【Scala】基础_for
- 交叉编译openblas到hisi3159v101
- 缺失数据处理
- Android照片墙应用实现,再多的图片也不怕崩溃
- bfs和dfs
- Redis
- 实体类序列化JSON时,过滤掉为空的字段的方法
- Java进击之路——成为JAVA大神你必须完成的30个目标(包括核心思想,核心类库,核心技术等)