【问题标题】:Spark - Read hidden files from hdfsSpark - 从 hdfs 读取隐藏文件
【发布时间】:2021-06-25 19:48:50
【问题描述】:

我正在使用 pyspark shell 来分析 hdfs 中的数据。 hdfs 路径中有隐藏文件,我想通过 shell 读取它们。然而,点文件被火花忽略。我如何阅读它们?

# This is not loading hidden files into data-frame
dir="/abc/xyz"
df=spark.read.text(dir)

# This is not loading hidden files into data-frame
dir="/abc/xyz/*"
df=spark.read.text(dir)

# This is not loading hidden files into data-frame
dir="/abc/xyz/.*"
df=spark.read.text(dir)

任何建议将不胜感激。

【问题讨论】:

    标签: apache-spark pyspark hdfs


    【解决方案1】:

    Spark 使用 Hadoop API 从 HDFS 读取数据。 Hadoop 输入格式具有路径过滤器,可以过滤掉以“_”和“.”开头的文件。 尝试在配置中设置此属性 FileInputFormat.setInputPathFilter ,然后使用 newAPIHadoopFile 创建 RDD

    【讨论】:

    • 我从谷歌了解到有一些属性需要设置,但我没有找到任何示例。你介意提供一个例子吗?
    【解决方案2】:

    尝试改变你的路径。

      # This is not loading hidden files into data-frame
        # dir="/abc/xyz/.*"
        dir = "hdfs://yourhost:yourport/abc/xyz/"
        df=spark.read.text(dir)
    

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 1970-01-01
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 2019-10-25
      • 2017-08-07
      • 1970-01-01
      相关资源
      最近更新 更多