python - Apache Spark Streaming 不读取目录

标签 python apache-spark spark-streaming pyspark

我正在处理 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

的指定目录,我也得不到任何数据

最佳答案

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

关于python - Apache Spark Streaming 不读取目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728118/

相关文章:

apache-spark - Spark 流: using object as key in 'mapToPair'

Scala 到 Pyspark

scala - Spark : How to split an RDD[T]` into Seq[RDD[T]] and preserve the ordering

python - 给定系列的总和

python - pygame连续下雨

python - 启动 Python shell 时出错,一周前运行的脚本出错

Python 元组到 JSON 输出

r - Spark Dataframe 中的重复列

apache-spark - 更改数据数据类型拆分后的Spark RDD如何在不更改数据类型的情况下拆分

apache-spark - 如何将 Spark 数据集保存到 Bigquery 表