DStream使用Pyspark在Spark流中保存空文件

DStream使用Pyspark在Spark流中保存空文件,pyspark,spark-streaming,Pyspark,Spark Streaming,如果已经有人问过这个问题,请原谅。我正在尝试使用pyspark将流数据保存到HDFS中。 正在HDFS上成功创建文件,但这些文件为空。下面是我正在使用的简单代码 请帮助解决此问题 从pyspark导入SparkContext from pyspark.streaming import StreamingContext # Create a local StreamingContextwith two working thread and batch interval of 1 second s

如果已经有人问过这个问题,请原谅。我正在尝试使用pyspark将流数据保存到HDFS中。 正在HDFS上成功创建文件,但这些文件为空。下面是我正在使用的简单代码

请帮助解决此问题

从pyspark导入SparkContext

from pyspark.streaming import StreamingContext

# Create a local StreamingContextwith two working thread and batch interval of 1 second
sc= SparkContext("local[2]", "NetworkWordCount")
ssc= StreamingContext(sc, 2)
#创建一个将连接到hostname:port的数据流,如localhost:9999

#将内容保存到HDFS中


使用spark 1.6.2版本附带的Cloudera quick start VM。

请专家对我的queryNo one进行评论,以帮助我吗?
linesDStream= ssc.socketTextStream("localhost", 9999)

# Split each line into words
wordsDStream= linesDStream.flatMap(lambda line: line.split(" "))

    # Count each word in each batch
pairsDStream= wordsDStream.map(lambda word: (word, 1))
wordCountsDStream= pairsDStream.reduceByKey(lambda x, y: x + y)
wordCountsDStream.saveAsTextFiles("/home/cloudera/stream_Output/file")
wordCountsDStream.pprint()

# Start the computation

ssc.start() 
# Wait for the computation to terminate
ssc.awaitTermination()