Skip to content

Commit 7f96b70

Browse files
remove ExecuteResponse namedtuple, use as backend obj store
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent e351834 commit 7f96b70

File tree

9 files changed

+217
-276
lines changed

9 files changed

+217
-276
lines changed

src/databricks/sql/backend/databricks_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
from databricks.sql.thrift_api.TCLIService import ttypes
1818
from databricks.sql.backend.types import SessionId, CommandId, CommandState
19-
from databricks.sql.utils import ExecuteResponse
20-
from databricks.sql.types import SSLOptions
2119

2220
# Forward reference for type hints
2321
from typing import TYPE_CHECKING

src/databricks/sql/backend/filters.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
TYPE_CHECKING,
1818
)
1919

20-
# Import SeaResultSet for type checking
21-
from databricks.sql.backend.sea_result_set import SeaResultSet
22-
2320
if TYPE_CHECKING:
24-
from databricks.sql.result_set import ResultSet
21+
from databricks.sql.result_set import ResultSet, SeaResultSet
2522

2623
logger = logging.getLogger(__name__)
2724

@@ -36,8 +33,8 @@ class ResultSetFilter:
3633

3734
@staticmethod
3835
def _filter_sea_result_set(
39-
result_set: SeaResultSet, filter_func: Callable[[List[Any]], bool]
40-
) -> SeaResultSet:
36+
result_set: "SeaResultSet", filter_func: Callable[[List[Any]], bool]
37+
) -> "SeaResultSet":
4138
"""
4239
Filter a SEA result set using the provided filter function.
4340

src/databricks/sql/backend/sea/backend.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import re
33
import uuid
44
import time
5-
from typing import Dict, Tuple, List, Optional, Any, Union, TYPE_CHECKING
5+
from typing import Dict, Set, Tuple, List, Optional, Any, Union, TYPE_CHECKING
66

7-
from databricks.sql.backend.sea.utils.constants import ALLOWED_SESSION_CONF_TO_DEFAULT_VALUES_MAP
7+
from databricks.sql.backend.sea.utils.constants import (
8+
ALLOWED_SESSION_CONF_TO_DEFAULT_VALUES_MAP,
9+
)
810

911
if TYPE_CHECKING:
1012
from databricks.sql.client import Cursor
@@ -60,6 +62,7 @@ def _filter_session_configuration(
6062

6163
return filtered_session_configuration
6264

65+
6366
class SeaDatabricksClient(DatabricksClient):
6467
"""
6568
Statement Execution API (SEA) implementation of the DatabricksClient interface.
@@ -493,7 +496,7 @@ def get_execution_result(
493496
)
494497

495498
# Create and return a SeaResultSet
496-
from databricks.sql.backend.sea_result_set import SeaResultSet
499+
from databricks.sql.result_set import SeaResultSet
497500

498501
return SeaResultSet(
499502
connection=cursor.connection,

src/databricks/sql/backend/sea/models/responses.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ def from_dict(cls, data: Dict[str, Any]) -> "ExecuteStatementResponse":
3737
error_code=error_data.get("error_code"),
3838
)
3939

40+
state = CommandState.from_sea_state(status_data.get("state", ""))
41+
if state is None:
42+
raise ValueError(f"Invalid state: {status_data.get('state', '')}")
4043
status = StatementStatus(
41-
state=CommandState.from_sea_state(status_data.get("state", "")),
44+
state=state,
4245
error=error,
4346
sql_state=status_data.get("sql_state"),
4447
)
@@ -72,8 +75,12 @@ def from_dict(cls, data: Dict[str, Any]) -> "GetStatementResponse":
7275
error_code=error_data.get("error_code"),
7376
)
7477

78+
state = CommandState.from_sea_state(status_data.get("state", ""))
79+
if state is None:
80+
raise ValueError(f"Invalid state: {status_data.get('state', '')}")
81+
7582
status = StatementStatus(
76-
state=CommandState.from_sea_state(status_data.get("state", "")),
83+
state=state,
7784
error=error,
7885
sql_state=status_data.get("sql_state"),
7986
)

src/databricks/sql/backend/sea_result_set.py

Lines changed: 0 additions & 188 deletions
This file was deleted.

src/databricks/sql/backend/types.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from dataclasses import dataclass
12
from enum import Enum
2-
from typing import Dict, Optional, Any
3+
from typing import Dict, List, Optional, Any, Tuple
34
import logging
45

56
from databricks.sql.backend.utils import guid_to_hex_id
@@ -80,6 +81,28 @@ def from_thrift_state(
8081
else:
8182
return None
8283

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+
83106

84107
class BackendType(Enum):
85108
"""
@@ -371,3 +394,19 @@ def to_hex_guid(self) -> str:
371394
return guid_to_hex_id(self.guid)
372395
else:
373396
return str(self.guid)
397+
398+
399+
@dataclass
400+
class ExecuteResponse:
401+
"""Response from executing a SQL command."""
402+
403+
command_id: CommandId
404+
status: CommandState
405+
description: Optional[
406+
List[Tuple[str, str, None, None, Optional[int], Optional[int], bool]]
407+
] = None
408+
has_more_rows: bool = False
409+
results_queue: Optional[Any] = None
410+
has_been_closed_server_side: bool = False
411+
lz4_compressed: bool = True
412+
is_staging_operation: bool = False

src/databricks/sql/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from databricks.sql.backend.thrift_backend import ThriftDatabricksClient
2525
from databricks.sql.backend.databricks_client import DatabricksClient
2626
from databricks.sql.utils import (
27-
ExecuteResponse,
2827
ParamEscaper,
2928
inject_parameters,
3029
transform_paramstyle,

0 commit comments

Comments
 (0)