yuanqiao 发表于 2019-1-31 08:12:52

NetWordCound

  import org.apache.spark.{SparkContext, SparkConf}
  import org.apache.spark.streaming.{Seconds,StreamingContext}
  import org.apache.spark.storage.StorageLevel
  val conf=new SparkConf().setMaster("local").setAppName("wordcount")
  val sc=new SparkContext(conf);
  val ssc=new StreamingContext(sc,Seconds(10));
  

  val lines=ssc.socketTextStream("localhost",9999,StorageLevel.MEMORY_AND_DISK_SER);
  

  

  val wordCount=lines.flatMap(_.split(",")).map(x=>(x,1)).reduceByKey((a,b)=>a+b);
  

  wordCount.print()
  

  ssc.start();
  ssc.awaitTermination()
  




页: [1]
查看完整版本: NetWordCound