Skip to content

Commit 1ed3514

Browse files
decouple session class from existing Connection
ensure maintenance of current APIs of Connection while delegating responsibility Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 066aef9 commit 1ed3514

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/databricks/sql/client.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
OperationalError,
2020
SessionAlreadyClosedError,
2121
CursorAlreadyClosedError,
22+
Error,
23+
NotSupportedError,
2224
)
2325
from databricks.sql.thrift_api.TCLIService import ttypes
2426
from databricks.sql.backend.thrift_backend import ThriftDatabricksClient
@@ -250,6 +252,20 @@ def read(self) -> Optional[OAuthToken]:
250252
+ str(self.get_session_id_hex())
251253
)
252254

255+
# Create the session
256+
self.session = Session(
257+
server_hostname,
258+
http_path,
259+
http_headers,
260+
session_configuration,
261+
catalog,
262+
schema,
263+
_use_arrow_native_complex_types,
264+
**kwargs
265+
)
266+
267+
logger.info("Successfully opened connection with session " + str(self.get_session_id_hex()))
268+
253269
self.use_inline_params = self._set_use_inline_params_with_warning(
254270
kwargs.get("use_inline_params", False)
255271
)
@@ -295,7 +311,7 @@ def __exit__(self, exc_type, exc_value, traceback):
295311
return False
296312

297313
def __del__(self):
298-
if self.open:
314+
if self.session.open:
299315
logger.debug(
300316
"Closing unclosed connection for session "
301317
"{}".format(self.get_session_id_hex())
@@ -344,7 +360,7 @@ def cursor(
344360
345361
Will throw an Error if the connection has been closed.
346362
"""
347-
if not self.open:
363+
if not self.session.open:
348364
raise Error("Cannot create cursor from closed connection")
349365

350366
cursor = Cursor(
@@ -1502,7 +1518,7 @@ def close(self) -> None:
15021518
if (
15031519
self.op_state != ttypes.TOperationState.CLOSED_STATE
15041520
and not self.has_been_closed_server_side
1505-
and self.connection.open
1521+
and self.connection.session.open
15061522
):
15071523
self.backend.close_command(self.command_id)
15081524
except RequestError as e:

0 commit comments

Comments
 (0)