@@ -29,10 +29,14 @@ def __init__(
29
29
30
30
This class handles all session-related behavior and communication with the backend.
31
31
"""
32
- self .open = False
32
+ self .is_open = False
33
33
self .host = server_hostname
34
34
self .port = kwargs .get ("_port" , 443 )
35
35
36
+ self .session_configuration = session_configuration
37
+ self .catalog = catalog
38
+ self .schema = schema
39
+
36
40
auth_provider = get_python_sql_connector_auth_provider (
37
41
server_hostname , ** kwargs
38
42
)
@@ -78,12 +82,16 @@ def __init__(
78
82
** kwargs ,
79
83
)
80
84
85
+ self ._session_handle = None
86
+ self .protocol_version = None
87
+
88
+ def open (self ) -> None :
81
89
self ._open_session_resp = self .thrift_backend .open_session (
82
- session_configuration , catalog , schema
90
+ self . session_configuration , self . catalog , self . schema
83
91
)
84
92
self ._session_handle = self ._open_session_resp .sessionHandle
85
93
self .protocol_version = self .get_protocol_version (self ._open_session_resp )
86
- self .open = True
94
+ self .is_open = True
87
95
logger .info ("Successfully opened session " + str (self .get_session_id_hex ()))
88
96
89
97
@staticmethod
@@ -114,10 +122,16 @@ def get_session_handle(self):
114
122
return self ._session_handle
115
123
116
124
def get_session_id (self ):
117
- return self .thrift_backend .handle_to_id (self ._session_handle )
125
+ session_handle = self .get_session_handle ()
126
+ if session_handle is None :
127
+ return None
128
+ return self .thrift_backend .handle_to_id (session_handle )
118
129
119
130
def get_session_id_hex (self ):
120
- return self .thrift_backend .handle_to_hex_id (self ._session_handle )
131
+ session_handle = self .get_session_handle ()
132
+ if session_handle is None :
133
+ return None
134
+ return self .thrift_backend .handle_to_hex_id (session_handle )
121
135
122
136
def close (self ) -> None :
123
137
"""Close the underlying session."""
@@ -127,7 +141,7 @@ def close(self) -> None:
127
141
return
128
142
129
143
try :
130
- self .thrift_backend .close_session (self ._session_handle )
144
+ self .thrift_backend .close_session (self .get_session_handle () )
131
145
except RequestError as e :
132
146
if isinstance (e .args [1 ], SessionAlreadyClosedError ):
133
147
logger .info ("Session was closed by a prior request" )
@@ -143,4 +157,4 @@ def close(self) -> None:
143
157
except Exception as e :
144
158
logger .error (f"Attempt to close session raised a local exception: { e } " )
145
159
146
- self .open = False
160
+ self .is_open = False
0 commit comments