Scala 我的Spark作业是删除hdfs中的目标文件夹

Scala 我的Spark作业是删除hdfs中的目标文件夹,scala,file,csv,apache-spark,hdfs,Scala,File,Csv,Apache Spark,Hdfs,我有一个脚本,可以将配置单元表内容写入HDFS中的CSV文件。 目标文件夹名称在JSON参数文件中给出。当我启动脚本时,我注意到我已经创建的文件夹被自动删除,然后抛出一个错误,指出目标文件不存在。这是我的剧本: sigma.cache // sigma is the df that contains the hive table. Tested OK sigma.repartition(1).write.mode(SaveMode.Overwrite).format("csv").option(

我有一个脚本,可以将配置单元表内容写入HDFS中的CSV文件。 目标文件夹名称在JSON参数文件中给出。当我启动脚本时,我注意到我已经创建的文件夹被自动删除,然后抛出一个错误,指出目标文件不存在。这是我的剧本:

sigma.cache // sigma is the df that contains the hive table. Tested OK
sigma.repartition(1).write.mode(SaveMode.Overwrite).format("csv").option("header", true).option("delimiter", "|").save(Parametre_vigiliste.cible)
val conf = new Configuration()
val fs = FileSystem.get(conf)
//Parametre_vigiliste.cible is the variable inide the JSON file that contains the target folder name
val file = fs.globStatus(new Path(Parametre_vigiliste.cible + "/part*"))(0).getPath().getName(); 
fs.rename(new Path(Parametre_vigiliste.cible + "/" + file), new Path(Parametre_vigiliste.cible + "/" + "FIC_PER_DATALAKE_.txt"));
sigma.unpersist()
抛出错误:

捕获到异常:java.lang.UnsupportedOperationException:CSV数据 源不支持空数据类型


此代码是否可以出于某种原因删除文件夹?谢谢。

正如Prateek建议的那样,我尝试了
sigma.printSchema
,发现了一些空列。我纠正了这一点,效果很好。

尝试将保存模式从覆盖更改为附加,因此
SaveMode。覆盖
更改为
SaveMode。附加
已经尝试过了。同样的问题..对于
sigma.repartition(1).write.mode(SaveMode.Overwrite).format(“csv”).option(“header”,true).option(“delimiter”,“|”).save(Parametre_vigiliste.cible)
,您确定输出文件不是空的吗?我不认为spark会将空df写入输出位置,这可能是在没有找到文件的情况下被覆盖的方式。请运行sigma.printSchema并检查列类型。此代码是否可以出于某种原因删除文件夹?是的,因为SaveMode.Overwrite,它将被删除。作业成功与否目标文件夹一旦被覆盖将被重新创建。@请确认输出文件最初不存在。我想要脚本来创建它。Prateek printSchema返回:root,然后返回所有my df列:string(nullable=true)