Apache spark CentOS |错误apache spark文件已存在Sparkcontext
我无法写入我创建的文件。在windows中工作正常。在centos中,它表示文件已经存在,并且没有写入任何内容Apache spark CentOS |错误apache spark文件已存在Sparkcontext,apache-spark,parquet,file-exists,Apache Spark,Parquet,File Exists,我无法写入我创建的文件。在windows中工作正常。在centos中,它表示文件已经存在,并且没有写入任何内容 File tempFile= new File("temp/tempfile.parquet"); tempFile.createNewFile(); parquetDataSet.write().parquet(tempFile.getAbsolutePath()); 错误如下:文件已存在 2020-02-29 07:01:18.007 ERROR 1 --- [nio-8090-
File tempFile= new File("temp/tempfile.parquet");
tempFile.createNewFile();
parquetDataSet.write().parquet(tempFile.getAbsolutePath());
错误如下:文件已存在
2020-02-29 07:01:18.007 ERROR 1 --- [nio-8090-exec-1] c.gehc.odp.util.JsonToParquetConverter : Stack Trace: {}org.apache.spark.sql.AnalysisException: path file:/temp/myfile.parquet already exists.;
2020-02-29 07:01:18.007 ERROR 1 --- [nio-8090-exec-1] c.gehc.odp.util.JsonToParquetConverter : sparkcontext close
spark中的默认保存模式为ErrorIfExists。这意味着,如果与您打算写入的文件名相同的文件已经存在,它将给出一个类似于您上面得到的异常。这种情况发生在您的案例中,因为您是自己创建文件的,而不是将该任务留给spark。有两种方法可以解决这种情况: 1) 您可以在write命令中将savemode称为“overwrite”或“append”:
parquetDataSet.write.mode("overwrite").parquet(tempFile.getAbsolutePath());
2) 或者,您可以简单地删除“创建新文件”命令,并直接在spark write命令中传递目标路径,如下所示:
parquetDataSet.write.parquet("temp/tempfile.parquet");