Repository navigation
[SPARK-60360][SQL] Validate file source writes before deleting existing data in static overwrite - #59610
Open
dongjoon-hyun wants to merge 1 commit into
Open
[SPARK-60360][SQL] Validate file source writes before deleting existing data in static overwrite#59610dongjoon-hyun wants to merge 1 commit into
dongjoon-hyun wants to merge 1 commit into
Conversation
…ng data in static overwrite
HyukjinKwon
approved these changes
Oct 19, 2026
Member
Author
|
Thank you so much always, @HyukjinKwon ! 😄 |
Member
Author
|
Also, FYI, @peter-toth . |
peter-toth
reviewed
Oct 20, 2026
peter-toth
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the PR, @dongjoon-hyun!
The static-mode delete now runs in a beforeSetupJob callback inside FileFormatWriter.write. That is after verifySchema, checkFieldNames and prepareWrite, and still before setupJob. No built-in prepareWrite touches the output path, so a valid write is unchanged. The 6 new tests pass on the head, and I checked that all of them fail on the base.
Non-blocking
- 1.
saveAsTablestill loses the table: On an existing V1 table,spark.range(5).write.mode("overwrite").option("compression", "bogus").saveAsTable("t")fails withCODEC_NOT_AVAILABLEand leaves notbehind, on both the base and the head.SaveAsV1TableCommanddrops the table atddl.scala:1064before the CTAS reachesFileFormatWriter. Could you note it as out of scope in the description, or file a follow-up?
peter-toth
approved these changes
Oct 20, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR keeps the existing data when a static-mode overwrite fails the driver side checks of the write. The S3A magic committer on S3 benefits the most:
FileCommitProtocol.deleteWithJob, whichPathOutputCommitProtocoldoes not override) before the job starts.InsertIntoHadoopFsRelationCommandused to delete the matching output before callingFileFormatWriter.write, which then checks the data schema (verifySchema,checkFieldNames) and the write options (FileFormat.prepareWrite). NowFileFormatWriter.writetakes abeforeSetupJobcallback (a no-op by default) that runs right beforecommitter.setupJob, andInsertIntoHadoopFsRelationCommanddeletes the matching output there. The delete still happens beforesetupJob, where the magic committer creates its__magic_job-<uuid>directory under the destination, so valid writes are unchanged.Why are the changes needed?
When these checks fail, the existing data has already been deleted.
The same happens with an unsupported data type (e.g. a map column in CSV), with
binaryFile, which does not support writes, and withINSERT OVERWRITEinto tables (including converted Hive tables) and directories. This has been the behavior since Spark 1.4.Does this PR introduce any user-facing change?
Yes. A static-mode overwrite that fails these checks keeps the existing data instead of deleting it, with any committer. Valid writes are unchanged.
How was this patch tested?
Added tests to
InsertSuiteofsql/coreandsql/hive. They fail without this fix. The delete does not depend on the committer, so the tests use the default one.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5