This is an automated email from the ASF dual-hosted git repository.

allisonwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 634362cbe2d5 [SPARK-52147][SQL][TESTS] Block temporary object 
references in persistent SQL UDFs
634362cbe2d5 is described below

commit 634362cbe2d5f59a78525320c6be8773c023938a
Author: Allison Wang <allison.w...@databricks.com>
AuthorDate: Wed Jul 23 14:38:21 2025 -0700

    [SPARK-52147][SQL][TESTS] Block temporary object references in persistent 
SQL UDFs
    
    ### What changes were proposed in this pull request?
    
    This PR adds test cases to block temporary object references in persistent 
SQL UDFs.
    
    ### Why are the changes needed?
    
    To improve test coverage for a SQL UDF feature.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Test only.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No
    
    Closes #51625 from allisonwang-db/spark-52147-block-temp-obj.
    
    Authored-by: Allison Wang <allison.w...@databricks.com>
    Signed-off-by: Allison Wang <allison.w...@databricks.com>
---
 .../sql-tests/analyzer-results/sql-udf.sql.out     | 120 +++++++++++++++++
 .../test/resources/sql-tests/inputs/sql-udf.sql    |  19 +++
 .../resources/sql-tests/results/sql-udf.sql.out    | 144 +++++++++++++++++++++
 3 files changed, 283 insertions(+)

diff --git 
a/sql/core/src/test/resources/sql-tests/analyzer-results/sql-udf.sql.out 
b/sql/core/src/test/resources/sql-tests/analyzer-results/sql-udf.sql.out
index a04f72d85a39..51cf4cf0f7d2 100644
--- a/sql/core/src/test/resources/sql-tests/analyzer-results/sql-udf.sql.out
+++ b/sql/core/src/test/resources/sql-tests/analyzer-results/sql-udf.sql.out
@@ -3747,6 +3747,96 @@ RESET spark.sql.ansi.enabled
 ResetCommand spark.sql.ansi.enabled
 
 
+-- !query
+CREATE TEMPORARY VIEW t AS VALUES (0) t(a)
+-- !query analysis
+CreateViewCommand `t`, VALUES (0) t(a), false, false, LocalTempView, 
UNSUPPORTED, true
+   +- SubqueryAlias t
+      +- LocalRelation [a#x]
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5a(x INT) RETURNS INT RETURN x
+-- !query analysis
+CreateSQLFunctionCommand foo3_5a, x INT, INT, x, false, true, false, false
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5b(x INT) RETURNS INT RETURN (SELECT SUM(a) 
FROM t)
+-- !query analysis
+CreateSQLFunctionCommand foo3_5b, x INT, INT, (SELECT SUM(a) FROM t), false, 
true, false, false
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5c(x INT) RETURNS TABLE (a INT) RETURN SELECT a 
FROM t
+-- !query analysis
+CreateSQLFunctionCommand foo3_5c, x INT, a INT, SELECT a FROM t, true, true, 
false, false
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN foo3_5a(x)
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "FUNCTION",
+    "tempObjName" : "`foo3_5a`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT foo3_5a(x)
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "FUNCTION",
+    "tempObjName" : "`foo3_5a`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN (SELECT SUM(a) FROM t)
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "VIEW",
+    "tempObjName" : "`t`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT a FROM t
+-- !query analysis
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "VIEW",
+    "tempObjName" : "`t`"
+  }
+}
+
+
 -- !query
 CREATE FUNCTION foo3_14a() RETURNS INT RETURN 1
 -- !query analysis
@@ -4828,3 +4918,33 @@ DropFunctionCommand spark_catalog.default.foo4_2, true, 
false
 DROP FUNCTION IF EXISTS foo4_3
 -- !query analysis
 DropFunctionCommand spark_catalog.default.foo4_3, true, false
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo1d3
+-- !query analysis
+DropFunctionCommand foo1d3, true, true
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_3b
+-- !query analysis
+DropFunctionCommand foo3_3b, true, true
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5a
+-- !query analysis
+DropFunctionCommand foo3_5a, true, true
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5b
+-- !query analysis
+DropFunctionCommand foo3_5b, true, true
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5c
+-- !query analysis
+DropFunctionCommand foo3_5c, true, true
diff --git a/sql/core/src/test/resources/sql-tests/inputs/sql-udf.sql 
b/sql/core/src/test/resources/sql-tests/inputs/sql-udf.sql
index 2c257b41239f..e5060b9d512d 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/sql-udf.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/sql-udf.sql
@@ -787,6 +787,18 @@ SELECT * FROM foo3_3ct();
 SELECT * FROM foo3_3dt();
 RESET spark.sql.ansi.enabled;
 
+-- 3.5 Permanent functions with temp objects are not allowed
+CREATE TEMPORARY VIEW t AS VALUES (0) t(a);
+CREATE TEMPORARY FUNCTION foo3_5a(x INT) RETURNS INT RETURN x;
+CREATE TEMPORARY FUNCTION foo3_5b(x INT) RETURNS INT RETURN (SELECT SUM(a) 
FROM t);
+CREATE TEMPORARY FUNCTION foo3_5c(x INT) RETURNS TABLE (a INT) RETURN SELECT a 
FROM t;
+-- Expect error: permanent function cannot reference temporary function
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN foo3_5a(x);
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT foo3_5a(x);
+-- Expect error: permanent function cannot reference temporary view
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN (SELECT SUM(a) FROM t);
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT a FROM t;
+
 -- 3.14 Invalid usage of SQL scalar/table functions in query clauses.
 CREATE FUNCTION foo3_14a() RETURNS INT RETURN 1;
 CREATE FUNCTION foo3_14b() RETURNS TABLE (a INT) RETURN SELECT 1;
@@ -948,3 +960,10 @@ DROP FUNCTION IF EXISTS foo4_0;
 DROP FUNCTION IF EXISTS foo4_1;
 DROP FUNCTION IF EXISTS foo4_2;
 DROP FUNCTION IF EXISTS foo4_3;
+
+-- Drop temporary functions
+DROP TEMPORARY FUNCTION IF EXISTS foo1d3;
+DROP TEMPORARY FUNCTION IF EXISTS foo3_3b;
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5a;
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5b;
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5c;
diff --git a/sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out 
b/sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out
index c2fbda4fdff2..a962632592f8 100644
--- a/sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/sql-udf.sql.out
@@ -3887,6 +3887,110 @@ struct<>
 
 
 
+-- !query
+CREATE TEMPORARY VIEW t AS VALUES (0) t(a)
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5a(x INT) RETURNS INT RETURN x
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5b(x INT) RETURNS INT RETURN (SELECT SUM(a) 
FROM t)
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+CREATE TEMPORARY FUNCTION foo3_5c(x INT) RETURNS TABLE (a INT) RETURN SELECT a 
FROM t
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN foo3_5a(x)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "FUNCTION",
+    "tempObjName" : "`foo3_5a`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT foo3_5a(x)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "FUNCTION",
+    "tempObjName" : "`foo3_5a`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS INT RETURN (SELECT SUM(a) FROM t)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "VIEW",
+    "tempObjName" : "`t`"
+  }
+}
+
+
+-- !query
+CREATE FUNCTION foo3_5d(x INT) RETURNS TABLE (a INT) RETURN SELECT a FROM t
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.sql.AnalysisException
+{
+  "errorClass" : "INVALID_TEMP_OBJ_REFERENCE",
+  "sqlState" : "42K0F",
+  "messageParameters" : {
+    "obj" : "FUNCTION",
+    "objName" : "`default`.`foo3_5d`",
+    "tempObj" : "VIEW",
+    "tempObjName" : "`t`"
+  }
+}
+
+
 -- !query
 CREATE FUNCTION foo3_14a() RETURNS INT RETURN 1
 -- !query schema
@@ -5095,3 +5199,43 @@ DROP FUNCTION IF EXISTS foo4_3
 struct<>
 -- !query output
 
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo1d3
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_3b
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5a
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5b
+-- !query schema
+struct<>
+-- !query output
+
+
+
+-- !query
+DROP TEMPORARY FUNCTION IF EXISTS foo3_5c
+-- !query schema
+struct<>
+-- !query output
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to