Skip to content

[SPARK-54866][SQL][FOLLOWUP] Fix DROP FUNCTION IF EXISTS to not fail when namespace doesn't exist#53835

Closed
cloud-fan wants to merge 1 commit intoapache:masterfrom
cloud-fan:fix_drop_func_non_existing_ns
Closed

[SPARK-54866][SQL][FOLLOWUP] Fix DROP FUNCTION IF EXISTS to not fail when namespace doesn't exist#53835
cloud-fan wants to merge 1 commit intoapache:masterfrom
cloud-fan:fix_drop_func_non_existing_ns

Conversation

@cloud-fan
Copy link
Contributor

@cloud-fan cloud-fan commented Jan 16, 2026

What changes were proposed in this pull request?

This PR fixes a regression introduced by SPARK-54866 (PR #53638) where DROP FUNCTION IF EXISTS would fail when the namespace doesn't exist.

Previously, when dropping a function in a non-existing namespace with IF EXISTS, the UnresolvedFunctionName would remain unchanged because CatalogV2Util.loadFunction returns None. Later, the drop function command was converted to NoopCommand, which gracefully handles the case.

After PR #53638, the drop function command directly calls SessionCatalog.dropFunction, which calls requireDbExists and throws an exception when the namespace doesn't exist, even with IF EXISTS specified.

Why are the changes needed?

To fix a regression where DROP FUNCTION IF EXISTS fails on non-existing namespace instead of gracefully doing nothing.

Does this PR introduce any user-facing change?

Yes, it fixes a regression. DROP FUNCTION IF EXISTS db.func no longer throws an error when db doesn't exist.

How was this patch tested?

Added a new test in DataSourceV2FunctionSuite.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: cursor 2.3.35

…pace doesn't exist

### What changes were proposed in this pull request?

This PR fixes a regression introduced by SPARK-54866 (PR apache#53638) where `DROP FUNCTION IF EXISTS` would fail when the namespace doesn't exist.

Previously, when dropping a function in a non-existing namespace with `IF EXISTS`, the `UnresolvedFunctionName` would remain unchanged because `CatalogV2Util.loadFunction` returns None. Later, the drop function command was converted to `NoopCommand`, which gracefully handles the case.

After PR apache#53638, the drop function command directly calls `SessionCatalog.dropFunction`, which calls `requireDbExists` and throws an exception when the namespace doesn't exist, even with `IF EXISTS` specified.

### Why are the changes needed?

To fix a regression where `DROP FUNCTION IF EXISTS` fails on non-existing namespace instead of gracefully doing nothing.

### Does this PR introduce _any_ user-facing change?

Yes, it fixes a regression. `DROP FUNCTION IF EXISTS db.func` no longer throws an error when `db` doesn't exist.

### How was this patch tested?

Added a new test in `DataSourceV2FunctionSuite`.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: cursor
@github-actions
Copy link

github-actions bot commented Jan 16, 2026

JIRA Issue Information

=== Improvement SPARK-54866 ===
Summary: Refactor Drop/RefreshFunction to avoid catalog lookup
Assignee: Wenchen Fan
Status: Resolved
Affected: ["4.2.0"]


This comment was automatically generated by GitHub Actions

@github-actions github-actions bot added the SQL label Jan 16, 2026
@cloud-fan cloud-fan changed the title [SPARK-50984][SQL] Fix DROP FUNCTION IF EXISTS to not fail when namespace doesn't exist [SPARK-54866][SQL][FOLLOWUP] Fix DROP FUNCTION IF EXISTS to not fail when namespace doesn't exist Jan 16, 2026
@cloud-fan
Copy link
Contributor Author

cc @allisonwang-db

Copy link
Member

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question, is the behavior a bit different than drop table if not exists?

@cloud-fan
Copy link
Contributor Author

@szehon-ho behavior is the same between DROP TABLE and DROP FUNCTION, but the implementation is different. In DropTableExec, we call dropTable after we check tableExists.

@szehon-ho
Copy link
Member

szehon-ho commented Jan 16, 2026

Ah ok, i was looking at sessioncatalog API dropTable which always check if database exists


but i guess the end behavior is the same

@sarutak
Copy link
Member

sarutak commented Jan 19, 2026

Merging to master. Thank you @cloud-fan @szehon-ho @yaooqinn .

@sarutak sarutak closed this in 5b10478 Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants