streaming代码

This commit is contained in:
2025-01-02 17:32:13 +08:00
parent eeda4a7e9b
commit 926b86d894
9 changed files with 28818 additions and 29 deletions

14
testnc.py Normal file
View 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()