-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathcontext.py
More file actions
45 lines (32 loc) · 2.03 KB
/
context.py
File metadata and controls
45 lines (32 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#
"""Context module for Snowpark."""
from typing import Callable, Optional
import snowflake.snowpark
import threading
_use_scoped_temp_objects = True
# This is an internal-only global flag, used to determine whether to execute code in a client's local sandbox or connect to a Snowflake account.
# If this is True, then the session instance is forcibly set to None to avoid any interaction with a Snowflake account.
_is_execution_environment_sandboxed_for_client: bool = False
# This callback, assigned by the caller environment outside Snowpark, can be used to share information about the extension function to be registered.
# It should also return a decision on whether to proceed with registring the extension function with the Snowflake account.
# If _should_continue_registration is None, i.e. a caller environment never assigned it an alternate callable, then we want to continue registration as part of the regular Snowpark workflow.
# If _should_continue_registration is not None, i.e. a caller environment has assigned it an alternate callable, then the callback is responsible for determining the rest of the Snowpark workflow.
_should_continue_registration: Optional[Callable[..., bool]] = None
# Internal-only global flag that determines if structured type semantics should be used
_use_structured_type_semantics = False
_use_structured_type_semantics_lock = threading.RLock()
def _should_use_structured_type_semantics():
global _use_structured_type_semantics
global _use_structured_type_semantics_lock
with _use_structured_type_semantics_lock:
return _use_structured_type_semantics
def get_active_session() -> "snowflake.snowpark.Session":
"""Returns the current active Snowpark session.
Raises: SnowparkSessionException: If there is more than one active session or no active sessions.
Returns:
A :class:`Session` object for the current session.
"""
return snowflake.snowpark.session._get_active_session()