[SPARK-56558][SQL] CTAS IF NOT EXISTS bypasses non-empty location check when table does not exist in catalog#55444
Open
planga82 wants to merge 5 commits intoapache:masterfrom
Open
Conversation
Contributor
Author
|
CC: @vinodkc |
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?
CREATE TABLE IF NOT EXISTS ... LOCATION ... AS SELECT silently overwrites data in a non-empty directory when the table does not yet exist in the catalog, bypassing the protection introduced in #32411.
IF NOT EXISTS semantics apply only to the catalog: if the table already exists, the command is a no-op. If the table does not exist in the catalog, the non-empty location check must still be enforced, identical to a plain CREATE TABLE ... AS SELECT.
This PR aligns the behaviour across the two scenarios CREATE TABLE and CREATE TABLE IF NOT EXISTS when the table do not exists.
Why are the changes needed?
Aling the behavior between CREATE TABLE and CREATE TABLE IF NOT EXISTS
Does this PR introduce any user-facing change?
Yes, now CREATE TABLE IF NOT EXISTS will fail if the location is not empty like CREATE TABLE
How was this patch tested?
Tests and manually
Was this patch authored or co-authored using generative AI tooling?
yes, co-authored by Claude Code