For spark sql, how should we fetch data from one folder in HDFS, do some modifications, and save the updated data to the same folder in HDFS via Overwrite save mode<
I solved this , first I write my Dataframe to a temp directory , and delete the source I reading , and rename the temp directory to source name . QAQ
I faced similar issue. I was writing dataframe to a hive table using below code
dataframe.write.mode("overwrite").saveAsTable("mydatabase.tablename")
When I tried to query this table, I was getting the same error. I then added the below line of code after creating table to refresh the table, which solved the issue.
spark.catalog.refreshTable("mydatabase.tablename")
val dfOut = df.filter(r => r.getAs[Long]("dsctimestamp") > (System.currentTimeMillis() - 1800000))
In the above line of code, df
had an underlying Hadoop partition. Once I had made this transformation (i.e., to dfOut
), I could not find a way to delete, rename, or overwrite the underlying partition until dfOut
had been garbage collected.
My solution was to keep the old partition, create a new partition for dfOut
, flag the new partition as current and then delete the old partition some given time later, after dfOut
had been garbage collected.
May not be an ideal solution. I would love to learn a less tortuous way of addressing this issue. But it works.
Why don't you just cache it after reading it. Saving it to another file directory and then moving the directory might entail some extra permissions. I also have been forcing an action as well, like a show().
val myDF = spark.read.format("csv")
.option("header", "false")
.option("delimiter", ",")
.load("/directory/tofile/")
myDF.cache()
myDF.show(2)