Skip to content

Commit 8da84e8

Browse files
introduce __str__ methods for CommandId and SessionId
Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent ac984e4 commit 8da84e8

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/databricks/sql/backend/thrift_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ def cancel_command(self, command_id: CommandId) -> None:
11531153
if not thrift_handle:
11541154
raise ValueError("Not a valid Thrift command ID")
11551155

1156-
logger.debug("Cancelling command {}".format(command_id.guid))
1156+
logger.debug("Cancelling command {}".format(guid_to_hex_id(command_id.guid)))
11571157
req = ttypes.TCancelOperationReq(thrift_handle)
11581158
self.make_request(self._client.CancelOperation, req)
11591159

src/databricks/sql/backend/types.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ def __init__(
5959
self.secret = secret
6060
self.info = info or {}
6161

62+
def __str__(self) -> str:
63+
"""
64+
Return a string representation of the SessionId.
65+
66+
For SEA backend, returns the guid.
67+
For Thrift backend, returns a format like "guid|secret".
68+
69+
Returns:
70+
A string representation of the session ID
71+
"""
72+
if self.backend_type == BackendType.SEA:
73+
return str(self.guid)
74+
elif self.backend_type == BackendType.THRIFT:
75+
return f"{self.to_hex_id()}|{guid_to_hex_id(self.secret) if isinstance(self.secret, bytes) else str(self.secret)}"
76+
return str(self.guid)
77+
6278
@classmethod
6379
def from_thrift_handle(cls, session_handle, info: Optional[Dict[str, Any]] = None):
6480
"""
@@ -185,6 +201,22 @@ def __init__(
185201
self.has_result_set = has_result_set
186202
self.modified_row_count = modified_row_count
187203

204+
def __str__(self) -> str:
205+
"""
206+
Return a string representation of the CommandId.
207+
208+
For SEA backend, returns the guid.
209+
For Thrift backend, returns a format like "guid|secret".
210+
211+
Returns:
212+
A string representation of the command ID
213+
"""
214+
if self.backend_type == BackendType.SEA:
215+
return str(self.guid)
216+
elif self.backend_type == BackendType.THRIFT:
217+
return f"{self.to_hex_id()}|{guid_to_hex_id(self.secret) if isinstance(self.secret, bytes) else str(self.secret)}"
218+
return str(self.guid)
219+
188220
@classmethod
189221
def from_thrift_handle(cls, operation_handle):
190222
"""

src/databricks/sql/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ def __iter__(self):
12561256

12571257
def _fill_results_buffer(self):
12581258
if not isinstance(self.backend, ThriftDatabricksClient):
1259-
# This specific logic is for Thrift. SEA will have its own way.
1259+
# currently, we are assuming only the Thrift backend exists
12601260
raise NotImplementedError(
12611261
"Fetching further result batches is currently only implemented for the Thrift backend."
12621262
)

0 commit comments

Comments
 (0)