Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark CentOS |错误apache spark文件已存在Sparkcontext_Apache Spark_Parquet_File Exists - Fatal编程技术网

Apache spark CentOS |错误apache spark文件已存在Sparkcontext

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-

我无法写入我创建的文件。在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-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");