Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Created April 5, 2022 03:48
Show Gist options
  • Save j-thepac/d1bc3764ccf551c364dbd6bff86c44a9 to your computer and use it in GitHub Desktop.
Save j-thepac/d1bc3764ccf551c364dbd6bff86c44a9 to your computer and use it in GitHub Desktop.
Spark Stream
package ch06
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.lit
import org.apache.spark.sql.types.StringType
//nc -l -p 9999
object SimpleStream extends App {
val spark = SparkSession.builder
.master("local")
.appName("StructuredNetworkWordCount")
.getOrCreate()
spark.sparkContext.setLogLevel("ERROR")
var max = 0
val lines = spark.readStream
.format("socket")
.option("host", "localhost")
.option("port", 9999)
.load()
val query = lines.writeStream
.outputMode("append") //complete ,update
.format("console")
.start()
.awaitTermination()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment