【问题标题】:AWS EMR Spark: Error writing to S3 - IllegalArgumentException - Cannot create a path from an empty stringAWS EMR Spark:写入 S3 时出错 - IllegalArgumentException - 无法从空字符串创建路径
【发布时间】:2017-12-12 23:28:33
【问题描述】:

我已经尝试解决这个问题很长时间了......不知道为什么我会得到这个?仅供参考,我在 AWS EMR 集群上的集群上运行 Spark。我调试并清楚地看到提供的目标路径......类似于s3://my-bucket-name/。 spark 作业创建 orc 文件并在创建分区后写入它们,如下所示:date=2017-06-10。有什么想法吗?

17/07/08 22:48:31 ERROR ApplicationMaster: User class threw exception: java.lang.IllegalArgumentException: Can not create a Path from an empty string
java.lang.IllegalArgumentException: Can not create a Path from an empty string
    at org.apache.hadoop.fs.Path.checkPathArg(Path.java:126)
    at org.apache.hadoop.fs.Path.<init>(Path.java:134)
    at org.apache.hadoop.fs.Path.<init>(Path.java:93)
    at org.apache.hadoop.fs.Path.suffix(Path.java:361)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand.deleteMatchingPartitions(InsertIntoHadoopFsRelationCommand.scala:138)
    at org.apache.spark.sql.execution.datasources.InsertIntoHadoopFsRelationCommand.run(InsertIntoHadoopFsRelationCommand.scala:82)

写orc的代码:

dataframe.write
   .partitionBy(partition)
   .option("compression", ZLIB.toString)
   .mode(SaveMode.Overwrite)
   .orc(destination)

【问题讨论】:

  • 有没有可能有空分区?
  • orc 文件首先写入_temporary 目录,然后移动到主目录。不知道这种情况会如何出现!
  • 贴出可能有助于理解问题的代码
  • 用编写的代码更新了问题。

标签: amazon-web-services apache-spark amazon-s3 amazon-emr


【解决方案1】:

我在将 parquet 文件写入 S3 时遇到了类似的问题。问题是SaveMode.Overwrite。此模式似乎无法与 S3 结合使用。在写入之前尝试删除 S3 存储桶 my-bucket-name 中的所有数据。那么您的代码应该可以成功运行。

要从您的存储桶my-bucket-name 中删除所有文件,您可以使用以下 pyspark 代码:

# see https://www.quora.com/How-do-you-overwrite-the-output-directory-when-using-PySpark
URI = sc._gateway.jvm.java.net.URI
Path = sc._gateway.jvm.org.apache.hadoop.fs.Path
FileSystem = sc._gateway.jvm.org.apache.hadoop.fs.FileSystem

# see http://crazyslate.com/how-to-rename-hadoop-files-using-wildcards-while-patterns/
fs = FileSystem.get(URI("s3a://my-bucket-name"), sc._jsc.hadoopConfiguration())
file_status = fs.globStatus(Path("/*"))
for status in file_status:
    fs.delete(status.getPath(), True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-13
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 2021-02-04
    • 1970-01-01
    相关资源
    最近更新 更多