Created
April 5, 2022 03:48
-
-
Save j-thepac/d1bc3764ccf551c364dbd6bff86c44a9 to your computer and use it in GitHub Desktop.
Spark Stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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