Skip to content

Commit ac34732

Browse files
pydoc for types
Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent af166b9 commit ac34732

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/databricks/sql/backend/types.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99

1010

1111
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+
1228
PENDING = "PENDING"
1329
RUNNING = "RUNNING"
1430
SUCCEEDED = "SUCCEEDED"
@@ -18,6 +34,27 @@ class CommandState(Enum):
1834

1935
@classmethod
2036
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+
"""
2158
if state in (
2259
ttypes.TOperationState.INITIALIZED_STATE,
2360
ttypes.TOperationState.PENDING_STATE,

0 commit comments

Comments
 (0)