9
9
10
10
11
11
class CommandState (Enum ):
12
+ """
13
+ Enum representing the execution state of a command in Databricks SQL.
14
+
15
+ This enum maps Thrift operation states to normalized command states,
16
+ providing a consistent interface for tracking command execution status
17
+ across different backend implementations.
18
+
19
+ Attributes:
20
+ PENDING: Command is queued or initialized but not yet running
21
+ RUNNING: Command is currently executing
22
+ SUCCEEDED: Command completed successfully
23
+ FAILED: Command failed due to error, timeout, or unknown state
24
+ CLOSED: Command has been closed
25
+ CANCELLED: Command was cancelled before completion
26
+ """
27
+
12
28
PENDING = "PENDING"
13
29
RUNNING = "RUNNING"
14
30
SUCCEEDED = "SUCCEEDED"
@@ -18,6 +34,27 @@ class CommandState(Enum):
18
34
19
35
@classmethod
20
36
def from_thrift_state (cls , state : ttypes .TOperationState ) -> "CommandState" :
37
+ """
38
+ Convert a Thrift TOperationState to a normalized CommandState.
39
+
40
+ Args:
41
+ state: A TOperationState from the Thrift API representing the current
42
+ state of an operation
43
+
44
+ Returns:
45
+ CommandState: The corresponding normalized command state
46
+
47
+ Raises:
48
+ ValueError: If the provided state is not a recognized TOperationState
49
+
50
+ State Mappings:
51
+ - INITIALIZED_STATE, PENDING_STATE -> PENDING
52
+ - RUNNING_STATE -> RUNNING
53
+ - FINISHED_STATE -> SUCCEEDED
54
+ - ERROR_STATE, TIMEDOUT_STATE, UKNOWN_STATE -> FAILED
55
+ - CLOSED_STATE -> CLOSED
56
+ - CANCELED_STATE -> CANCELLED
57
+ """
21
58
if state in (
22
59
ttypes .TOperationState .INITIALIZED_STATE ,
23
60
ttypes .TOperationState .PENDING_STATE ,
0 commit comments