DStream窗口操作-countByWindow
作者:互联网
package org.hnsw import org.apache.spark.SparkConf import org.apache.spark.streaming.{Seconds, StreamingContext} object DStream_winCountby { def main(args: Array[String]): Unit = { //1、初始化Context上下文 val conf = new SparkConf().setAppName("jxq").setMaster("local[*]") val sc = new StreamingContext(conf, Seconds(1)) //2、指定采集服务器ip和端口 //设置切换 sc.checkpoint("out") //执行countByWindow前需要设置checkpoint val dStream = sc.socketTextStream("192.168.3.66",8888) //3、业务逻辑 //窗口类rdd数据的数量 val dStream_win = dStream.countByWindow(Seconds(5), Seconds(2)) //指定窗口大小 和 滑动频率 必须是批处理时间的整数倍 dStream_win.print() //4、启动stream sc.start() //5、挂起stream sc.awaitTermination() } }
标签:dStream,窗口,val,Seconds,sc,org,DStream,countByWindow 来源: https://www.cnblogs.com/857weir09432/p/16362781.html