Skip to content

Commit 2952d8d

Browse files
Revert "Merge branch 'sea-migration' into exec-models-sea"
This reverts commit 8bd12d8, reversing changes made to 030edf8.
1 parent 3ffa898 commit 2952d8d

File tree

11 files changed

+159
-237
lines changed

11 files changed

+159
-237
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def to_dict(self) -> Dict[str, Any]:
9898

9999
@dataclass
100100
class CreateSessionRequest:
101-
"""Representation of a request to create a new session."""
101+
"""Request to create a new session."""
102102

103103
warehouse_id: str
104104
session_confs: Optional[Dict[str, str]] = None
@@ -123,7 +123,7 @@ def to_dict(self) -> Dict[str, Any]:
123123

124124
@dataclass
125125
class DeleteSessionRequest:
126-
"""Representation of a request to delete a session."""
126+
"""Request to delete a session."""
127127

128128
warehouse_id: str
129129
session_id: str

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "GetStatementResponse":
146146

147147
@dataclass
148148
class CreateSessionResponse:
149-
"""Representation of the response from creating a new session."""
149+
"""Response from creating a new session."""
150150

151151
session_id: str
152152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import logging
33
import requests
4-
from typing import Callable, Dict, Any, Optional, List, Tuple
4+
from typing import Callable, Dict, Any, Optional, Union, List, Tuple
55
from urllib.parse import urljoin
66

77
from databricks.sql.auth.authenticators import AuthProvider

src/databricks/sql/backend/thrift_backend.py

Lines changed: 59 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
import logging
44
import math
55
import time
6+
import uuid
67
import threading
78
from typing import List, Union, Any, TYPE_CHECKING
89

910
if TYPE_CHECKING:
1011
from databricks.sql.client import Cursor
1112

13+
from databricks.sql.thrift_api.TCLIService.ttypes import TOperationState
1214
from databricks.sql.backend.types import (
1315
CommandState,
1416
SessionId,
1517
CommandId,
18+
BackendType,
19+
guid_to_hex_id,
1620
ExecuteResponse,
1721
)
1822
from databricks.sql.backend.utils import guid_to_hex_id
1923

20-
2124
try:
2225
import pyarrow
2326
except ImportError:
@@ -757,13 +760,11 @@ def _results_message_to_execute_response(self, resp, operation_state):
757760
)
758761
direct_results = resp.directResults
759762
has_been_closed_server_side = direct_results and direct_results.closeOperation
760-
761-
is_direct_results = (
763+
has_more_rows = (
762764
(not direct_results)
763765
or (not direct_results.resultSet)
764766
or direct_results.resultSet.hasMoreRows
765767
)
766-
767768
description = self._hive_schema_to_description(
768769
t_result_set_metadata_resp.schema
769770
)
@@ -779,25 +780,43 @@ def _results_message_to_execute_response(self, resp, operation_state):
779780
schema_bytes = None
780781

781782
lz4_compressed = t_result_set_metadata_resp.lz4Compressed
783+
is_staging_operation = t_result_set_metadata_resp.isStagingOperation
784+
if direct_results and direct_results.resultSet:
785+
assert direct_results.resultSet.results.startRowOffset == 0
786+
assert direct_results.resultSetMetadata
787+
788+
arrow_queue_opt = ResultSetQueueFactory.build_queue(
789+
row_set_type=t_result_set_metadata_resp.resultFormat,
790+
t_row_set=direct_results.resultSet.results,
791+
arrow_schema_bytes=schema_bytes,
792+
max_download_threads=self.max_download_threads,
793+
lz4_compressed=lz4_compressed,
794+
description=description,
795+
ssl_options=self._ssl_options,
796+
)
797+
else:
798+
arrow_queue_opt = None
799+
782800
command_id = CommandId.from_thrift_handle(resp.operationHandle)
783801

784802
status = CommandState.from_thrift_state(operation_state)
785803
if status is None:
786804
raise ValueError(f"Unknown command state: {operation_state}")
787805

788-
execute_response = ExecuteResponse(
789-
command_id=command_id,
790-
status=status,
791-
description=description,
792-
has_been_closed_server_side=has_been_closed_server_side,
793-
lz4_compressed=lz4_compressed,
794-
is_staging_operation=t_result_set_metadata_resp.isStagingOperation,
795-
arrow_schema_bytes=schema_bytes,
796-
result_format=t_result_set_metadata_resp.resultFormat,
806+
return (
807+
ExecuteResponse(
808+
command_id=command_id,
809+
status=status,
810+
description=description,
811+
has_more_rows=has_more_rows,
812+
results_queue=arrow_queue_opt,
813+
has_been_closed_server_side=has_been_closed_server_side,
814+
lz4_compressed=lz4_compressed,
815+
is_staging_operation=is_staging_operation,
816+
),
817+
schema_bytes,
797818
)
798819

799-
return execute_response, is_direct_results
800-
801820
def get_execution_result(
802821
self, command_id: CommandId, cursor: "Cursor"
803822
) -> "ResultSet":
@@ -822,6 +841,9 @@ def get_execution_result(
822841

823842
t_result_set_metadata_resp = resp.resultSetMetadata
824843

844+
lz4_compressed = t_result_set_metadata_resp.lz4Compressed
845+
is_staging_operation = t_result_set_metadata_resp.isStagingOperation
846+
has_more_rows = resp.hasMoreRows
825847
description = self._hive_schema_to_description(
826848
t_result_set_metadata_resp.schema
827849
)
@@ -836,21 +858,25 @@ def get_execution_result(
836858
else:
837859
schema_bytes = None
838860

839-
lz4_compressed = t_result_set_metadata_resp.lz4Compressed
840-
is_staging_operation = t_result_set_metadata_resp.isStagingOperation
841-
is_direct_results = resp.hasMoreRows
842-
843-
status = self.get_query_state(command_id)
861+
queue = ResultSetQueueFactory.build_queue(
862+
row_set_type=resp.resultSetMetadata.resultFormat,
863+
t_row_set=resp.results,
864+
arrow_schema_bytes=schema_bytes,
865+
max_download_threads=self.max_download_threads,
866+
lz4_compressed=lz4_compressed,
867+
description=description,
868+
ssl_options=self._ssl_options,
869+
)
844870

845871
execute_response = ExecuteResponse(
846872
command_id=command_id,
847873
status=status,
848874
description=description,
875+
has_more_rows=has_more_rows,
876+
results_queue=queue,
849877
has_been_closed_server_side=False,
850878
lz4_compressed=lz4_compressed,
851879
is_staging_operation=is_staging_operation,
852-
arrow_schema_bytes=schema_bytes,
853-
result_format=t_result_set_metadata_resp.resultFormat,
854880
)
855881

856882
return ThriftResultSet(
@@ -860,10 +886,7 @@ def get_execution_result(
860886
buffer_size_bytes=cursor.buffer_size_bytes,
861887
arraysize=cursor.arraysize,
862888
use_cloud_fetch=cursor.connection.use_cloud_fetch,
863-
t_row_set=resp.results,
864-
max_download_threads=self.max_download_threads,
865-
ssl_options=self._ssl_options,
866-
is_direct_results=is_direct_results,
889+
arrow_schema_bytes=schema_bytes,
867890
)
868891

869892
def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
@@ -976,25 +999,18 @@ def execute_command(
976999
self._handle_execute_response_async(resp, cursor)
9771000
return None
9781001
else:
979-
execute_response, is_direct_results = self._handle_execute_response(
1002+
execute_response, arrow_schema_bytes = self._handle_execute_response(
9801003
resp, cursor
9811004
)
9821005

983-
t_row_set = None
984-
if resp.directResults and resp.directResults.resultSet:
985-
t_row_set = resp.directResults.resultSet.results
986-
9871006
return ThriftResultSet(
9881007
connection=cursor.connection,
9891008
execute_response=execute_response,
9901009
thrift_client=self,
9911010
buffer_size_bytes=max_bytes,
9921011
arraysize=max_rows,
9931012
use_cloud_fetch=use_cloud_fetch,
994-
t_row_set=t_row_set,
995-
max_download_threads=self.max_download_threads,
996-
ssl_options=self._ssl_options,
997-
is_direct_results=is_direct_results,
1013+
arrow_schema_bytes=arrow_schema_bytes,
9981014
)
9991015

10001016
def get_catalogs(
@@ -1016,25 +1032,18 @@ def get_catalogs(
10161032
)
10171033
resp = self.make_request(self._client.GetCatalogs, req)
10181034

1019-
execute_response, is_direct_results = self._handle_execute_response(
1035+
execute_response, arrow_schema_bytes = self._handle_execute_response(
10201036
resp, cursor
10211037
)
10221038

1023-
t_row_set = None
1024-
if resp.directResults and resp.directResults.resultSet:
1025-
t_row_set = resp.directResults.resultSet.results
1026-
10271039
return ThriftResultSet(
10281040
connection=cursor.connection,
10291041
execute_response=execute_response,
10301042
thrift_client=self,
10311043
buffer_size_bytes=max_bytes,
10321044
arraysize=max_rows,
10331045
use_cloud_fetch=cursor.connection.use_cloud_fetch,
1034-
t_row_set=t_row_set,
1035-
max_download_threads=self.max_download_threads,
1036-
ssl_options=self._ssl_options,
1037-
is_direct_results=is_direct_results,
1046+
arrow_schema_bytes=arrow_schema_bytes,
10381047
)
10391048

10401049
def get_schemas(
@@ -1060,25 +1069,18 @@ def get_schemas(
10601069
)
10611070
resp = self.make_request(self._client.GetSchemas, req)
10621071

1063-
execute_response, is_direct_results = self._handle_execute_response(
1072+
execute_response, arrow_schema_bytes = self._handle_execute_response(
10641073
resp, cursor
10651074
)
10661075

1067-
t_row_set = None
1068-
if resp.directResults and resp.directResults.resultSet:
1069-
t_row_set = resp.directResults.resultSet.results
1070-
10711076
return ThriftResultSet(
10721077
connection=cursor.connection,
10731078
execute_response=execute_response,
10741079
thrift_client=self,
10751080
buffer_size_bytes=max_bytes,
10761081
arraysize=max_rows,
10771082
use_cloud_fetch=cursor.connection.use_cloud_fetch,
1078-
t_row_set=t_row_set,
1079-
max_download_threads=self.max_download_threads,
1080-
ssl_options=self._ssl_options,
1081-
is_direct_results=is_direct_results,
1083+
arrow_schema_bytes=arrow_schema_bytes,
10821084
)
10831085

10841086
def get_tables(
@@ -1108,25 +1110,18 @@ def get_tables(
11081110
)
11091111
resp = self.make_request(self._client.GetTables, req)
11101112

1111-
execute_response, is_direct_results = self._handle_execute_response(
1113+
execute_response, arrow_schema_bytes = self._handle_execute_response(
11121114
resp, cursor
11131115
)
11141116

1115-
t_row_set = None
1116-
if resp.directResults and resp.directResults.resultSet:
1117-
t_row_set = resp.directResults.resultSet.results
1118-
11191117
return ThriftResultSet(
11201118
connection=cursor.connection,
11211119
execute_response=execute_response,
11221120
thrift_client=self,
11231121
buffer_size_bytes=max_bytes,
11241122
arraysize=max_rows,
11251123
use_cloud_fetch=cursor.connection.use_cloud_fetch,
1126-
t_row_set=t_row_set,
1127-
max_download_threads=self.max_download_threads,
1128-
ssl_options=self._ssl_options,
1129-
is_direct_results=is_direct_results,
1124+
arrow_schema_bytes=arrow_schema_bytes,
11301125
)
11311126

11321127
def get_columns(
@@ -1156,25 +1151,18 @@ def get_columns(
11561151
)
11571152
resp = self.make_request(self._client.GetColumns, req)
11581153

1159-
execute_response, is_direct_results = self._handle_execute_response(
1154+
execute_response, arrow_schema_bytes = self._handle_execute_response(
11601155
resp, cursor
11611156
)
11621157

1163-
t_row_set = None
1164-
if resp.directResults and resp.directResults.resultSet:
1165-
t_row_set = resp.directResults.resultSet.results
1166-
11671158
return ThriftResultSet(
11681159
connection=cursor.connection,
11691160
execute_response=execute_response,
11701161
thrift_client=self,
11711162
buffer_size_bytes=max_bytes,
11721163
arraysize=max_rows,
11731164
use_cloud_fetch=cursor.connection.use_cloud_fetch,
1174-
t_row_set=t_row_set,
1175-
max_download_threads=self.max_download_threads,
1176-
ssl_options=self._ssl_options,
1177-
is_direct_results=is_direct_results,
1165+
arrow_schema_bytes=arrow_schema_bytes,
11781166
)
11791167

11801168
def _handle_execute_response(self, resp, cursor):

src/databricks/sql/backend/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,11 @@ class ExecuteResponse:
423423

424424
command_id: CommandId
425425
status: CommandState
426-
description: Optional[List[Tuple]] = None
426+
description: Optional[
427+
List[Tuple[str, str, None, None, Optional[int], Optional[int], bool]]
428+
] = None
429+
has_more_rows: bool = False
430+
results_queue: Optional[Any] = None
427431
has_been_closed_server_side: bool = False
428432
lz4_compressed: bool = True
429433
is_staging_operation: bool = False
430-
arrow_schema_bytes: Optional[bytes] = None
431-
result_format: Optional[Any] = None

0 commit comments

Comments
 (0)