1- from dataclasses import dataclass
21from enum import Enum
3- from typing import Dict , List , Optional , Any , Tuple
2+ from typing import Dict , Optional , Any
43import logging
54
65from databricks .sql .backend .utils import guid_to_hex_id
@@ -81,28 +80,6 @@ def from_thrift_state(
8180 else :
8281 return None
8382
84- @classmethod
85- def from_sea_state (cls , state : str ) -> Optional ["CommandState" ]:
86- """
87- Map SEA state string to CommandState enum.
88-
89- Args:
90- state: SEA state string
91-
92- Returns:
93- CommandState: The corresponding CommandState enum value
94- """
95- state_mapping = {
96- "PENDING" : cls .PENDING ,
97- "RUNNING" : cls .RUNNING ,
98- "SUCCEEDED" : cls .SUCCEEDED ,
99- "FAILED" : cls .FAILED ,
100- "CLOSED" : cls .CLOSED ,
101- "CANCELED" : cls .CANCELLED ,
102- }
103-
104- return state_mapping .get (state , None )
105-
10683
10784class BackendType (Enum ):
10885 """
@@ -285,6 +262,9 @@ def __init__(
285262 backend_type : BackendType ,
286263 guid : Any ,
287264 secret : Optional [Any ] = None ,
265+ operation_type : Optional [int ] = None ,
266+ has_result_set : bool = False ,
267+ modified_row_count : Optional [int ] = None ,
288268 ):
289269 """
290270 Initialize a CommandId.
@@ -293,11 +273,17 @@ def __init__(
293273 backend_type: The type of backend (THRIFT or SEA)
294274 guid: The primary identifier for the command
295275 secret: The secret part of the identifier (only used for Thrift)
276+ operation_type: The operation type (only used for Thrift)
277+ has_result_set: Whether the command has a result set
278+ modified_row_count: The number of rows modified by the command
296279 """
297280
298281 self .backend_type = backend_type
299282 self .guid = guid
300283 self .secret = secret
284+ self .operation_type = operation_type
285+ self .has_result_set = has_result_set
286+ self .modified_row_count = modified_row_count
301287
302288 def __str__ (self ) -> str :
303289 """
@@ -332,6 +318,7 @@ def from_thrift_handle(cls, operation_handle):
332318 Returns:
333319 A CommandId instance
334320 """
321+
335322 if operation_handle is None :
336323 return None
337324
@@ -342,6 +329,9 @@ def from_thrift_handle(cls, operation_handle):
342329 BackendType .THRIFT ,
343330 guid_bytes ,
344331 secret_bytes ,
332+ operation_handle .operationType ,
333+ operation_handle .hasResultSet ,
334+ operation_handle .modifiedRowCount ,
345335 )
346336
347337 @classmethod
@@ -374,6 +364,9 @@ def to_thrift_handle(self):
374364 handle_identifier = ttypes .THandleIdentifier (guid = self .guid , secret = self .secret )
375365 return ttypes .TOperationHandle (
376366 operationId = handle_identifier ,
367+ operationType = self .operation_type ,
368+ hasResultSet = self .has_result_set ,
369+ modifiedRowCount = self .modified_row_count ,
377370 )
378371
379372 def to_sea_statement_id (self ):
@@ -401,19 +394,3 @@ def to_hex_guid(self) -> str:
401394 return guid_to_hex_id (self .guid )
402395 else :
403396 return str (self .guid )
404-
405-
406- @dataclass
407- class ExecuteResponse :
408- """Response from executing a SQL command."""
409-
410- command_id : CommandId
411- status : CommandState
412- description : Optional [
413- List [Tuple [str , str , None , None , Optional [int ], Optional [int ], bool ]]
414- ] = None
415- has_more_rows : bool = False
416- results_queue : Optional [Any ] = None
417- has_been_closed_server_side : bool = False
418- lz4_compressed : bool = True
419- is_staging_operation : bool = False
0 commit comments