|
229 | 229 | _to_col_if_str, |
230 | 230 | _to_col_if_str_or_int, |
231 | 231 | ) |
232 | | -from snowflake.snowpark.stored_procedure import StoredProcedure |
| 232 | +from snowflake.snowpark.context import _is_execution_environment_sandboxed_for_client |
| 233 | +from snowflake.snowpark.stored_procedure import ( |
| 234 | + StoredProcedure, |
| 235 | + StoredProcedureRegistration, |
| 236 | +) |
233 | 237 | from snowflake.snowpark.types import ( |
234 | 238 | ArrayType, |
235 | 239 | DataType, |
|
240 | 244 | TimestampTimeZone, |
241 | 245 | TimestampType, |
242 | 246 | ) |
243 | | -from snowflake.snowpark.udaf import UserDefinedAggregateFunction |
244 | | -from snowflake.snowpark.udf import UserDefinedFunction |
245 | | -from snowflake.snowpark.udtf import UserDefinedTableFunction |
| 247 | +from snowflake.snowpark.udaf import UDAFRegistration, UserDefinedAggregateFunction |
| 248 | +from snowflake.snowpark.udf import UDFRegistration, UserDefinedFunction |
| 249 | +from snowflake.snowpark.udtf import UDTFRegistration, UserDefinedTableFunction |
246 | 250 |
|
247 | 251 | # Python 3.8 needs to use typing.Iterable because collections.abc.Iterable is not subscriptable |
248 | 252 | # Python 3.9 can use both |
@@ -9460,13 +9464,16 @@ def udf( |
9460 | 9464 | ) |
9461 | 9465 |
|
9462 | 9466 | if session is None: |
9463 | | - warning( |
9464 | | - name=f"udf_no_active_session_{func.__name__ if func else 'unknown'}", |
9465 | | - text="WARN: UDF registration requires an active session. " |
9466 | | - "This function was not registered.", |
9467 | | - warning_times=1, |
9468 | | - ) |
9469 | | - return func |
| 9467 | + udf_registration_method = UDFRegistration(session=session).register |
| 9468 | + if not _is_execution_environment_sandboxed_for_client: |
| 9469 | + # This happens when the user uses the decorator without an active session. |
| 9470 | + warning( |
| 9471 | + name=f"udf_no_active_session_{func.__name__ if func else 'unknown'}", |
| 9472 | + text="WARN: UDF registration requires an active session. " |
| 9473 | + "This function was not registered.", |
| 9474 | + warning_times=1, |
| 9475 | + ) |
| 9476 | + return func |
9470 | 9477 | else: |
9471 | 9478 | udf_registration_method = session.udf.register |
9472 | 9479 |
|
@@ -9716,13 +9723,16 @@ def udtf( |
9716 | 9723 | session |
9717 | 9724 | ) |
9718 | 9725 | if session is None: |
9719 | | - warning( |
9720 | | - name=f"udtf_no_active_session_{handler.__name__ if handler else 'unknown'}", |
9721 | | - text="WARN: UDTF registration requires an active session. " |
9722 | | - "This function was not registered.", |
9723 | | - warning_times=1, |
9724 | | - ) |
9725 | | - return handler |
| 9726 | + udtf_registration_method = UDTFRegistration(session=session).register |
| 9727 | + if not _is_execution_environment_sandboxed_for_client: |
| 9728 | + # This happens when the user uses the decorator without an active session. |
| 9729 | + warning( |
| 9730 | + name=f"udtf_no_active_session_{handler.__name__ if handler else 'unknown'}", |
| 9731 | + text="WARN: UDTF registration requires an active session. " |
| 9732 | + "This function was not registered.", |
| 9733 | + warning_times=1, |
| 9734 | + ) |
| 9735 | + return handler |
9726 | 9736 | else: |
9727 | 9737 | udtf_registration_method = session.udtf.register |
9728 | 9738 |
|
@@ -9974,13 +9984,16 @@ def udaf( |
9974 | 9984 | session |
9975 | 9985 | ) |
9976 | 9986 | if session is None: |
9977 | | - warning( |
9978 | | - name=f"udaf_no_active_session_{handler.__name__ if handler else 'unknown'}", |
9979 | | - text="WARN: UDAF registration requires an active session. " |
9980 | | - "This function was not registered.", |
9981 | | - warning_times=1, |
9982 | | - ) |
9983 | | - return handler |
| 9987 | + udaf_registration_method = UDAFRegistration(session=session).register |
| 9988 | + if not _is_execution_environment_sandboxed_for_client: |
| 9989 | + # This happens when the user uses the decorator without an active session. |
| 9990 | + warning( |
| 9991 | + name=f"udaf_no_active_session_{handler.__name__ if handler else 'unknown'}", |
| 9992 | + text="WARN: UDAF registration requires an active session. " |
| 9993 | + "This function was not registered.", |
| 9994 | + warning_times=1, |
| 9995 | + ) |
| 9996 | + return handler |
9984 | 9997 | else: |
9985 | 9998 | udaf_registration_method = session.udaf.register |
9986 | 9999 |
|
@@ -10676,13 +10689,18 @@ def sproc( |
10676 | 10689 | session |
10677 | 10690 | ) |
10678 | 10691 | if session is None: |
10679 | | - warning( |
10680 | | - name=f"sproc_no_active_session_{func.__name__ if func else 'unknown'}", |
10681 | | - text="WARN: SPROC registration requires an active session. " |
10682 | | - "This function was not registered.", |
10683 | | - warning_times=1, |
10684 | | - ) |
10685 | | - return func |
| 10692 | + sproc_registration_method = StoredProcedureRegistration( |
| 10693 | + session=session |
| 10694 | + ).register |
| 10695 | + if not _is_execution_environment_sandboxed_for_client: |
| 10696 | + # This happens when the user uses the decorator without an active session. |
| 10697 | + warning( |
| 10698 | + name=f"sproc_no_active_session_{func.__name__ if func else 'unknown'}", |
| 10699 | + text="WARN: SPROC registration requires an active session. " |
| 10700 | + "This function was not registered.", |
| 10701 | + warning_times=1, |
| 10702 | + ) |
| 10703 | + return func |
10686 | 10704 | else: |
10687 | 10705 | sproc_registration_method = session.sproc.register |
10688 | 10706 |
|
|
0 commit comments