Structured Streaming本地local运行小例子

package com.lin.spark

import org.apache.spark.sql.SparkSession

object StructuredStreaming {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder()
      .appName("StructuredStreaming")
      .master("local[2]")
      .getOrCreate()

    import spark.implicits._

    val lines = spark.readStream
      .format("socket")
      .option("host","hadoop000")
      .option("port",9999)
      .load()

    val words = lines.as[String].flatMap(_.split(" "))

    val wordCounts = words.groupBy("value").count()

    val query = wordCounts.writeStream
      .outputMode("complete")
      .format("console")
      .start()

    query.awaitTermination()
  }
}

 

> nc -lk 9999

 

posted @ 2019-06-04 16:22  消失的白桦林  阅读(352)  评论(0编辑  收藏  举报