streaming代码
This commit is contained in:
14
testnc.py
Normal file
14
testnc.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from pyspark.sql import SparkSession
|
||||
|
||||
spark = SparkSession.builder.appName("StreamingApp").getOrCreate() # 创建 SparkSession
|
||||
|
||||
df = spark.readStream.format("socket").option("host", "niit-node2").option("port", "9999").load()
|
||||
|
||||
|
||||
df = df.selectExpr("explode(split(value, '\t'))as word") \
|
||||
.groupBy("word") \
|
||||
.count()
|
||||
|
||||
|
||||
|
||||
df.writeStream.outputMode("complete").format("console").start().awaitTermination()
|
||||
Reference in New Issue
Block a user