【问题标题】:Apache Spark Streaming is Not Reading the DirectoryApache Spark Streaming 未读取目录
【发布时间】:2015-04-27 23:36:50
【问题描述】:

我正在研究 Spark Streaming,我想设置一个本地目录以将数据流式传输到我的 spark 应用程序,以便该目录上的每个新文本文件都将流式传输到我的应用程序。我尝试使用StreamingContexttextFileStream 方法,但我没有从已移动到指定本地目录的文件中获取任何数据。你能帮我找出为什么会这样吗?

这是我写的代码:

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 &lt;path&gt; 创建了一个目录并将这个目录用作我的testFileStream 并且它有效。
  • 这是非常晚的响应,但默认情况下它是从 HDFS 读取的。为了从本地文件系统中读取,您必须使用 file: 前缀。例如file:/usr/lib/spark/docs/_site/index.html

标签: python apache-spark spark-streaming pyspark


【解决方案1】:

Spark 代码在工作中执行。因此,工作对您的本地文件系统没有任何访问权限。这是不可能的。您可以读取流文件然后制作RDD然后可以使用火花执行操作。 Spark 只能访问分布式数据。

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 1970-01-01
    • 2016-02-08
    • 2019-01-07
    • 1970-01-01
    • 2019-06-24
    • 2015-02-04
    • 2015-09-08
    • 2018-01-28
    相关资源
    最近更新 更多