Skip to content

Commit 1dd3877

Browse files
remove additional call on success
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 4f11ff0 commit 1dd3877

File tree

4 files changed

+32
-45
lines changed

4 files changed

+32
-45
lines changed

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
DeleteSessionRequest,
4141
StatementParameter,
4242
ExecuteStatementResponse,
43-
GetStatementResponse,
4443
CreateSessionResponse,
4544
)
4645

@@ -323,7 +322,7 @@ def _extract_description_from_manifest(
323322
return columns
324323

325324
def _results_message_to_execute_response(
326-
self, response: GetStatementResponse
325+
self, response: ExecuteStatementResponse
327326
) -> ExecuteResponse:
328327
"""
329328
Convert a SEA response to an ExecuteResponse and extract result data.
@@ -357,6 +356,28 @@ def _results_message_to_execute_response(
357356

358357
return execute_response
359358

359+
def _response_to_result_set(
360+
self, response: ExecuteStatementResponse, cursor: Cursor
361+
) -> SeaResultSet:
362+
"""
363+
Convert a SEA response to a SeaResultSet.
364+
"""
365+
366+
# Create and return a SeaResultSet
367+
from databricks.sql.backend.sea.result_set import SeaResultSet
368+
369+
execute_response = self._results_message_to_execute_response(response)
370+
371+
return SeaResultSet(
372+
connection=cursor.connection,
373+
execute_response=execute_response,
374+
sea_client=self,
375+
result_data=response.result,
376+
manifest=response.manifest,
377+
buffer_size_bytes=cursor.buffer_size_bytes,
378+
arraysize=cursor.arraysize,
379+
)
380+
360381
def _check_command_not_in_failed_or_closed_state(
361382
self, state: CommandState, command_id: CommandId
362383
) -> None:
@@ -491,6 +512,10 @@ def execute_command(
491512
if async_op:
492513
return None
493514

515+
if response.status.state == CommandState.SUCCEEDED:
516+
# if the response succeeded within the wait_timeout, return the results immediately
517+
return self._response_to_result_set(response, cursor)
518+
494519
self._wait_until_command_done(response)
495520
return self.get_execution_result(command_id, cursor)
496521

@@ -573,7 +598,7 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
573598
)
574599

575600
# Parse the response
576-
response = GetStatementResponse.from_dict(response_data)
601+
response = ExecuteStatementResponse.from_dict(response_data)
577602
return response.status.state
578603

579604
def get_execution_result(
@@ -611,22 +636,9 @@ def get_execution_result(
611636
path=self.STATEMENT_PATH_WITH_ID.format(sea_statement_id),
612637
data=request.to_dict(),
613638
)
614-
response = GetStatementResponse.from_dict(response_data)
615-
616-
# Create and return a SeaResultSet
617-
from databricks.sql.backend.sea.result_set import SeaResultSet
618-
619-
execute_response = self._results_message_to_execute_response(response)
639+
response = ExecuteStatementResponse.from_dict(response_data)
620640

621-
return SeaResultSet(
622-
connection=cursor.connection,
623-
execute_response=execute_response,
624-
sea_client=self,
625-
result_data=response.result,
626-
manifest=response.manifest,
627-
buffer_size_bytes=cursor.buffer_size_bytes,
628-
arraysize=cursor.arraysize,
629-
)
641+
return self._response_to_result_set(response, cursor)
630642

631643
# == Metadata Operations ==
632644

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
from databricks.sql.backend.sea.models.responses import (
2727
ExecuteStatementResponse,
28-
GetStatementResponse,
2928
CreateSessionResponse,
3029
)
3130

@@ -47,6 +46,5 @@
4746
"DeleteSessionRequest",
4847
# Response models
4948
"ExecuteStatementResponse",
50-
"GetStatementResponse",
5149
"CreateSessionResponse",
5250
]

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,6 @@ def from_dict(cls, data: Dict[str, Any]) -> "ExecuteStatementResponse":
124124
)
125125

126126

127-
@dataclass
128-
class GetStatementResponse:
129-
"""Representation of the response from getting information about a statement."""
130-
131-
statement_id: str
132-
status: StatementStatus
133-
manifest: ResultManifest
134-
result: ResultData
135-
136-
@classmethod
137-
def from_dict(cls, data: Dict[str, Any]) -> "GetStatementResponse":
138-
"""Create a GetStatementResponse from a dictionary."""
139-
return cls(
140-
statement_id=data.get("statement_id", ""),
141-
status=_parse_status(data),
142-
manifest=_parse_manifest(data),
143-
result=_parse_result(data),
144-
)
145-
146-
147127
@dataclass
148128
class CreateSessionResponse:
149129
"""Representation of the response from creating a new session."""

tests/unit/test_sea_backend.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def test_command_execution_sync(
225225
mock_http_client._make_request.return_value = execute_response
226226

227227
with patch.object(
228-
sea_client, "get_execution_result", return_value="mock_result_set"
228+
sea_client, "_response_to_result_set", return_value="mock_result_set"
229229
) as mock_get_result:
230230
result = sea_client.execute_command(
231231
operation="SELECT 1",
@@ -240,9 +240,6 @@ def test_command_execution_sync(
240240
enforce_embedded_schema_correctness=False,
241241
)
242242
assert result == "mock_result_set"
243-
cmd_id_arg = mock_get_result.call_args[0][0]
244-
assert isinstance(cmd_id_arg, CommandId)
245-
assert cmd_id_arg.guid == "test-statement-123"
246243

247244
# Test with invalid session ID
248245
with pytest.raises(ValueError) as excinfo:
@@ -357,7 +354,7 @@ def test_command_execution_advanced(
357354
mock_http_client._make_request.return_value = execute_response
358355
param = {"name": "param1", "value": "value1", "type": "STRING"}
359356

360-
with patch.object(sea_client, "get_execution_result"):
357+
with patch.object(sea_client, "_response_to_result_set"):
361358
sea_client.execute_command(
362359
operation="SELECT * FROM table WHERE col = :param1",
363360
session_id=sea_session_id,

0 commit comments

Comments
 (0)