[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
Closed
[SPARK-54866][SQL][FOLLOWUP] Fix DROP FUNCTION IF EXISTS to not fail when namespace doesn't exist#53835cloud-fan wants to merge 1 commit intoapache:masterfrom
cloud-fan wants to merge 1 commit intoapache:masterfrom
Conversation
…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
JIRA Issue Information=== Improvement SPARK-54866 === This comment was automatically generated by GitHub Actions |
Contributor
Author
szehon-ho
approved these changes
Jan 16, 2026
Member
szehon-ho
left a comment
There was a problem hiding this comment.
question, is the behavior a bit different than drop table if not exists?
Contributor
Author
|
@szehon-ho behavior is the same between DROP TABLE and DROP FUNCTION, but the implementation is different. In |
Member
|
Ah ok, i was looking at sessioncatalog API dropTable which always check if database exists but i guess the end behavior is the same |
yaooqinn
approved these changes
Jan 19, 2026
sarutak
approved these changes
Jan 19, 2026
Member
|
Merging to |
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 fixes a regression introduced by SPARK-54866 (PR #53638) where
DROP FUNCTION IF EXISTSwould fail when the namespace doesn't exist.Previously, when dropping a function in a non-existing namespace with
IF EXISTS, theUnresolvedFunctionNamewould remain unchanged becauseCatalogV2Util.loadFunctionreturns None. Later, the drop function command was converted toNoopCommand, which gracefully handles the case.After PR #53638, the drop function command directly calls
SessionCatalog.dropFunction, which callsrequireDbExistsand throws an exception when the namespace doesn't exist, even withIF EXISTSspecified.Why are the changes needed?
To fix a regression where
DROP FUNCTION IF EXISTSfails 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.funcno longer throws an error whendbdoesn'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