Skip to content

Commit 1dada97

Browse files
correct tests and merge artifacts
Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent 7f6073d commit 1dada97

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

src/databricks/sql/backend/databricks_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def cancel_command(self, command_id: CommandId) -> None:
108108
pass
109109

110110
@abstractmethod
111-
def close_command(self, command_id: CommandId) -> ttypes.TStatus:
111+
def close_command(self, command_id: CommandId) -> None:
112112
"""
113113
Closes a command and releases associated resources.
114114
@@ -118,17 +118,14 @@ def close_command(self, command_id: CommandId) -> ttypes.TStatus:
118118
Args:
119119
command_id: The command identifier to close
120120
121-
Returns:
122-
ttypes.TStatus: The status of the close operation
123-
124121
Raises:
125122
ValueError: If the command ID is invalid
126123
OperationalError: If there's an error closing the command
127124
"""
128125
pass
129126

130127
@abstractmethod
131-
def get_query_state(self, command_id: CommandId) -> ttypes.TOperationState:
128+
def get_query_state(self, command_id: CommandId) -> CommandState:
132129
"""
133130
Gets the current state of a query or command.
134131
@@ -204,7 +201,7 @@ def get_columns(
204201
schema_name: Optional[str] = None,
205202
table_name: Optional[str] = None,
206203
column_name: Optional[str] = None,
207-
) -> ExecuteResponse:
204+
) -> "ResultSet":
208205
"""
209206
Retrieves a list of columns, optionally filtered by catalog, schema, table, and column name patterns.
210207

src/databricks/sql/backend/thrift_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from databricks.sql.thrift_api.TCLIService.ttypes import TOperationState
1414
from databricks.sql.backend.types import (
15+
CommandState,
1516
SessionId,
1617
CommandId,
1718
BackendType,

src/databricks/sql/backend/types.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
from enum import Enum
2-
from typing import Dict, Optional, Any, Union
2+
from typing import Dict, Optional, Any
33
import logging
44

55
from databricks.sql.backend.utils import guid_to_hex_id
6+
from databricks.sql.thrift_api.TCLIService import ttypes
67

78
logger = logging.getLogger(__name__)
89

910

11+
class CommandState(Enum):
12+
PENDING = "PENDING"
13+
RUNNING = "RUNNING"
14+
SUCCEEDED = "SUCCEEDED"
15+
FAILED = "FAILED"
16+
CLOSED = "CLOSED"
17+
CANCELLED = "CANCELLED"
18+
19+
@classmethod
20+
def from_thrift_state(cls, state: ttypes.TOperationState) -> "CommandState":
21+
if state in (
22+
ttypes.TOperationState.INITIALIZED_STATE,
23+
ttypes.TOperationState.PENDING_STATE,
24+
):
25+
return cls.PENDING
26+
elif state == ttypes.TOperationState.RUNNING_STATE:
27+
return cls.RUNNING
28+
elif state == ttypes.TOperationState.FINISHED_STATE:
29+
return cls.SUCCEEDED
30+
elif state in (
31+
ttypes.TOperationState.ERROR_STATE,
32+
ttypes.TOperationState.TIMEDOUT_STATE,
33+
ttypes.TOperationState.UKNOWN_STATE,
34+
):
35+
return cls.FAILED
36+
elif state == ttypes.TOperationState.CLOSED_STATE:
37+
return cls.CLOSED
38+
elif state == ttypes.TOperationState.CANCELED_STATE:
39+
return cls.CANCELLED
40+
else:
41+
raise ValueError(f"Unknown command state: {state}")
42+
43+
1044
class BackendType(Enum):
1145
"""
1246
Enum representing the type of backend

tests/unit/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def test_closing_result_set_with_closed_connection_soft_closes_commands(self):
133133

134134
result_set = ThriftResultSet(
135135
connection=mock_connection,
136-
backend=mock_backend,
137136
execute_response=Mock(),
138137
thrift_client=mock_backend,
139138
)

0 commit comments

Comments
 (0)