【问题标题】:Spark `FileAlreadyExistsException` when `saveAsTextFile` even though the output directory doesn't exist [duplicate]Spark `FileAlreadyExistsException` 当`saveAsTextFile`即使输出目录不存在[重复]
【发布时间】:2016-06-16 08:34:46
【问题描述】:

我正在运行这个命令行:

hadoop fs -rm -r /tmp/output

然后使用 main() 进行 Java8 火花作业

    SparkConf sparkConf = new SparkConf();
    JavaSparkContext sc = new JavaSparkContext(sparkConf);
    JavaRDD<JSONObject> rdd = sc.textFile("/tmp/input")
            .map (s -> new JSONObject(s))
    rdd.saveAsTextFile("/tmp/output");
    sc.stop();

我得到这个错误:

ERROR ApplicationMaster: User class threw exception: org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory /tmp/output already exists

知道怎么解决吗?

【问题讨论】:

  • 我在 SparkConf 中使用了以下命令,它运行良好yourSparkConf.set("spark.hadoop.validateOutputSpecs", "false")

标签: java hadoop apache-spark hdfs


【解决方案1】:

您删除了 HDFS 目录,但 Spark 尝试保存在本地文件系统中。

要保存在 hdfs 中试试这个:

rdd.saveAsTextFile("hdfs://<URL-hdfs>:<PORT-hdfs>/tmp/output");

本地主机的默认值是:

rdd.saveAsTextFile("hdfs://localhost:9000/tmp/output");

其他解决方案是从本地文件系统中删除 /tmp/output

最好的问候

【讨论】:

    猜你喜欢
    • 2017-02-23
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    相关资源
    最近更新 更多