|
19 | 19 | OperationalError, |
20 | 20 | SessionAlreadyClosedError, |
21 | 21 | CursorAlreadyClosedError, |
| 22 | + Error, |
| 23 | + NotSupportedError, |
22 | 24 | ) |
23 | 25 | from databricks.sql.thrift_api.TCLIService import ttypes |
24 | 26 | from databricks.sql.backend.thrift_backend import ThriftDatabricksClient |
@@ -250,6 +252,20 @@ def read(self) -> Optional[OAuthToken]: |
250 | 252 | + str(self.get_session_id_hex()) |
251 | 253 | ) |
252 | 254 |
|
| 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 | + |
253 | 269 | self.use_inline_params = self._set_use_inline_params_with_warning( |
254 | 270 | kwargs.get("use_inline_params", False) |
255 | 271 | ) |
@@ -295,7 +311,7 @@ def __exit__(self, exc_type, exc_value, traceback): |
295 | 311 | return False |
296 | 312 |
|
297 | 313 | def __del__(self): |
298 | | - if self.open: |
| 314 | + if self.session.open: |
299 | 315 | logger.debug( |
300 | 316 | "Closing unclosed connection for session " |
301 | 317 | "{}".format(self.get_session_id_hex()) |
@@ -344,7 +360,7 @@ def cursor( |
344 | 360 |
|
345 | 361 | Will throw an Error if the connection has been closed. |
346 | 362 | """ |
347 | | - if not self.open: |
| 363 | + if not self.session.open: |
348 | 364 | raise Error("Cannot create cursor from closed connection") |
349 | 365 |
|
350 | 366 | cursor = Cursor( |
@@ -1502,7 +1518,7 @@ def close(self) -> None: |
1502 | 1518 | if ( |
1503 | 1519 | self.op_state != ttypes.TOperationState.CLOSED_STATE |
1504 | 1520 | and not self.has_been_closed_server_side |
1505 | | - and self.connection.open |
| 1521 | + and self.connection.session.open |
1506 | 1522 | ): |
1507 | 1523 | self.backend.close_command(self.command_id) |
1508 | 1524 | except RequestError as e: |
|
0 commit comments