Skip to content

[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
planga82:fix/create_table_existing_location
Open

[SPARK-56558][SQL] CTAS IF NOT EXISTS bypasses non-empty location check when table does not exist in catalog#55444
planga82 wants to merge 5 commits intoapache:masterfrom
planga82:fix/create_table_existing_location

Conversation

@planga82
Copy link
Copy Markdown
Contributor

@planga82 planga82 commented Apr 21, 2026

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

@planga82
Copy link
Copy Markdown
Contributor Author

CC: @vinodkc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant