|
2 | 2 | # Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. |
3 | 3 | # |
4 | 4 |
|
| 5 | +from contextlib import contextmanager |
5 | 6 | import pytest |
6 | 7 |
|
7 | 8 | from snowflake.connector.errors import ProgrammingError |
8 | 9 | from snowflake.snowpark._internal.utils import ( |
9 | 10 | TempObjectType, |
10 | 11 | random_name_for_temp_object, |
11 | 12 | ) |
| 13 | +from tests.utils import IS_IN_STORED_PROC |
12 | 14 |
|
13 | 15 |
|
14 | 16 | @pytest.mark.xfail( |
@@ -43,30 +45,37 @@ def test_create_scoped_temp_objects_syntax(session): |
43 | 45 | ) |
44 | 46 | assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
45 | 47 |
|
| 48 | + # CREATE SCOPED TEMPORARY TABLE previously only worked if the name of the object began with |
| 49 | + # SNOWPARK_TEMP_. This was changed to only enforce the naming convention if the query is issued |
| 50 | + # from within a stored procedure. |
| 51 | + |
| 52 | + @contextmanager |
| 53 | + def cm(): |
| 54 | + if IS_IN_STORED_PROC: |
| 55 | + with pytest.raises(ProgrammingError) as exc: |
| 56 | + yield |
| 57 | + assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
| 58 | + else: |
| 59 | + yield |
| 60 | + |
46 | 61 | temp_table_name = "temp_table" |
47 | | - with pytest.raises(ProgrammingError) as exc: |
| 62 | + with cm(): |
48 | 63 | session._run_query(f"create scoped temporary table {temp_table_name} (col int)") |
49 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
50 | | - with pytest.raises(ProgrammingError) as exc: |
| 64 | + with cm(): |
51 | 65 | session._run_query( |
52 | 66 | f"create scoped temporary view temp_view as select * from {temp_table_name}" |
53 | 67 | ) |
54 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
55 | | - with pytest.raises(ProgrammingError) as exc: |
| 68 | + with cm(): |
56 | 69 | session._run_query("create scoped temporary stage temp_stage") |
57 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
58 | | - with pytest.raises(ProgrammingError) as exc: |
| 70 | + with cm(): |
59 | 71 | session._run_query( |
60 | 72 | "create scoped temporary function temp_function (arg int) returns int" |
61 | 73 | ) |
62 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
63 | | - with pytest.raises(ProgrammingError) as exc: |
| 74 | + with cm(): |
64 | 75 | session._run_query( |
65 | | - "create scoped temporary function temp_talbe_function (arg int) returns table(col int) as $$ select * from {temp_table_name} $$" |
| 76 | + f"create scoped temporary function temp_table_function (arg int) returns table(col int) as $$ select col from {temp_table_name} $$" |
66 | 77 | ) |
67 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
68 | | - with pytest.raises(ProgrammingError) as exc: |
| 78 | + with cm(): |
69 | 79 | session._run_query( |
70 | 80 | "create scoped temporary file format temp_file_format type = csv" |
71 | 81 | ) |
72 | | - assert "Unsupported feature 'SCOPED_TEMPORARY'." in str(exc) |
|
0 commit comments