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()