Skip to content

[SPARK-52148][SQL] Fix CREATE OR REPLACE function for SQL user-defined TVFs #51191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,8 @@ class SessionCatalog(
// For a permanent function, because we loaded it to the FunctionRegistry
// when it's first used, we also need to drop it from the FunctionRegistry.
functionRegistry.dropFunction(qualifiedIdent)
} else if (tableFunctionRegistry.functionExists(qualifiedIdent)) {
tableFunctionRegistry.dropFunction(qualifiedIdent)
}
externalCatalog.dropFunction(db, funcName)
} else if (!ignoreIfNotExists) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2995,7 +2995,16 @@ org.apache.spark.sql.catalyst.analysis.FunctionAlreadyExistsException
-- !query
CREATE FUNCTION foo3_3at(x INT) RETURNS TABLE (a DOUBLE) RETURN SELECT 1 / x
-- !query analysis
CreateSQLFunctionCommand spark_catalog.default.foo3_3at, x INT, a DOUBLE, SELECT 1 / x, true, false, false, false
org.apache.spark.sql.catalyst.analysis.FunctionAlreadyExistsException
{
"errorClass" : "ROUTINE_ALREADY_EXISTS",
"sqlState" : "42723",
"messageParameters" : {
"existingRoutineType" : "routine",
"newRoutineType" : "routine",
"routineName" : "`default`.`foo3_3at`"
}
}


-- !query
Expand Down Expand Up @@ -3046,16 +3055,7 @@ CreateSQLFunctionCommand spark_catalog.default.foo3_3a, x INT, DOUBLE, 1 / x, fa
-- !query
CREATE OR REPLACE FUNCTION foo3_3at(x INT) RETURNS TABLE (a DOUBLE) RETURN SELECT 1 / x
-- !query analysis
org.apache.spark.sql.catalyst.analysis.FunctionAlreadyExistsException
{
"errorClass" : "ROUTINE_ALREADY_EXISTS",
"sqlState" : "42723",
"messageParameters" : {
"existingRoutineType" : "routine",
"newRoutineType" : "routine",
"routineName" : "`default`.`foo3_3at`"
}
}
CreateSQLFunctionCommand spark_catalog.default.foo3_3at, x INT, a DOUBLE, SELECT 1 / x, true, false, false, true


-- !query
Expand Down
29 changes: 3 additions & 26 deletions sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -2571,16 +2571,7 @@ CREATE OR REPLACE FUNCTION foo3_3at(x INT) RETURNS TABLE (a DOUBLE) RETURN SELEC
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.analysis.FunctionAlreadyExistsException
{
"errorClass" : "ROUTINE_ALREADY_EXISTS",
"sqlState" : "42723",
"messageParameters" : {
"existingRoutineType" : "routine",
"newRoutineType" : "routine",
"routineName" : "`default`.`foo3_3at`"
}
}



-- !query
Expand Down Expand Up @@ -2610,23 +2601,9 @@ NULL
-- !query
SELECT * FROM foo3_3at(0)
-- !query schema
struct<>
struct<a:double>
-- !query output
org.apache.spark.SparkArithmeticException
{
"errorClass" : "DIVIDE_BY_ZERO",
"sqlState" : "22012",
"messageParameters" : {
"config" : "\"spark.sql.ansi.enabled\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 12,
"fragment" : "1 / x"
} ]
}
NULL


-- !query
Expand Down