【发布时间】:2015-04-27 23:36:50
【问题描述】:
我正在研究 Spark Streaming,我想设置一个本地目录以将数据流式传输到我的 spark 应用程序,以便该目录上的每个新文本文件都将流式传输到我的应用程序。我尝试使用StreamingContext 的textFileStream 方法,但我没有从已移动到指定本地目录的文件中获取任何数据。你能帮我找出为什么会这样吗?
这是我写的代码:
def main():
if len(sys.argv) != 5:
print 'Usage: SPARK_HOME/bin/spark-submit CoinpipeVectorBuilder.py <SPARK_HOME> <dir_streaming> ' \
'<dir_crawled_addresses> <dir_output_vectors>'
sys.exit(1)
#Set the path to crawled outputs according to the parameter passed to the spark script
global path_crawled_output
path_crawled_output = sys.argv[4]
global sc, ssc
sconf = SparkConf().setMaster("local[2]")\
.setAppName("CoinPipeVectorBuilder")\
.set("spark.hadoop.validateOutputSpecs", "false")
sc = SparkContext(conf=sconf)
ssc = StreamingContext(sc, 10)
tx_and_addr_stream = ssc.textFileStream(sys.argv[2])
tx_and_addr_stream.foreachRDD(parseAndBuildVectors)
ssc.start()
ssc.awaitTermination()
if __name__ == "__main__":
main()
因此,在 parseAndBuildVectors 中,即使我将新文件移动到已传递给 ssc.textFileStream 的指定目录,我也没有得到任何数据
【问题讨论】:
-
我用
hadoop fs -mkdir <path>创建了一个目录并将这个目录用作我的testFileStream 并且它有效。 -
这是非常晚的响应,但默认情况下它是从 HDFS 读取的。为了从本地文件系统中读取,您必须使用
file:前缀。例如file:/usr/lib/spark/docs/_site/index.html
标签: python apache-spark spark-streaming pyspark