Skip to content

Commit 192901d

Browse files
return has_more_rows from ExecResponse conversion during GetRespMetadata
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 281a9e9 commit 192901d

File tree

3 files changed

+137
-139
lines changed

3 files changed

+137
-139
lines changed

src/databricks/sql/backend/thrift_backend.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,12 @@ def _results_message_to_execute_response(self, resp, operation_state):
758758
direct_results = resp.directResults
759759
has_been_closed_server_side = direct_results and direct_results.closeOperation
760760

761+
has_more_rows = (
762+
(not direct_results)
763+
or (not direct_results.resultSet)
764+
or direct_results.resultSet.hasMoreRows
765+
)
766+
761767
description = self._hive_schema_to_description(
762768
t_result_set_metadata_resp.schema
763769
)
@@ -779,7 +785,7 @@ def _results_message_to_execute_response(self, resp, operation_state):
779785
if status is None:
780786
raise ValueError(f"Unknown command state: {operation_state}")
781787

782-
return ExecuteResponse(
788+
execute_response = ExecuteResponse(
783789
command_id=command_id,
784790
status=status,
785791
description=description,
@@ -790,6 +796,8 @@ def _results_message_to_execute_response(self, resp, operation_state):
790796
result_format=t_result_set_metadata_resp.resultFormat,
791797
)
792798

799+
return execute_response, has_more_rows
800+
793801
def get_execution_result(
794802
self, command_id: CommandId, cursor: "Cursor"
795803
) -> "ResultSet":
@@ -855,6 +863,7 @@ def get_execution_result(
855863
t_row_set=resp.results,
856864
max_download_threads=self.max_download_threads,
857865
ssl_options=self._ssl_options,
866+
has_more_rows=has_more_rows,
858867
)
859868

860869
def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
@@ -967,7 +976,9 @@ def execute_command(
967976
self._handle_execute_response_async(resp, cursor)
968977
return None
969978
else:
970-
execute_response = self._handle_execute_response(resp, cursor)
979+
execute_response, has_more_rows = self._handle_execute_response(
980+
resp, cursor
981+
)
971982

972983
t_row_set = None
973984
if resp.directResults and resp.directResults.resultSet:
@@ -983,6 +994,7 @@ def execute_command(
983994
t_row_set=t_row_set,
984995
max_download_threads=self.max_download_threads,
985996
ssl_options=self._ssl_options,
997+
has_more_rows=has_more_rows,
986998
)
987999

9881000
def get_catalogs(
@@ -1004,7 +1016,7 @@ def get_catalogs(
10041016
)
10051017
resp = self.make_request(self._client.GetCatalogs, req)
10061018

1007-
execute_response = self._handle_execute_response(resp, cursor)
1019+
execute_response, has_more_rows = self._handle_execute_response(resp, cursor)
10081020

10091021
t_row_set = None
10101022
if resp.directResults and resp.directResults.resultSet:
@@ -1020,6 +1032,7 @@ def get_catalogs(
10201032
t_row_set=t_row_set,
10211033
max_download_threads=self.max_download_threads,
10221034
ssl_options=self._ssl_options,
1035+
has_more_rows=has_more_rows,
10231036
)
10241037

10251038
def get_schemas(
@@ -1045,7 +1058,7 @@ def get_schemas(
10451058
)
10461059
resp = self.make_request(self._client.GetSchemas, req)
10471060

1048-
execute_response = self._handle_execute_response(resp, cursor)
1061+
execute_response, has_more_rows = self._handle_execute_response(resp, cursor)
10491062

10501063
t_row_set = None
10511064
if resp.directResults and resp.directResults.resultSet:
@@ -1061,6 +1074,7 @@ def get_schemas(
10611074
t_row_set=t_row_set,
10621075
max_download_threads=self.max_download_threads,
10631076
ssl_options=self._ssl_options,
1077+
has_more_rows=has_more_rows,
10641078
)
10651079

10661080
def get_tables(
@@ -1090,7 +1104,7 @@ def get_tables(
10901104
)
10911105
resp = self.make_request(self._client.GetTables, req)
10921106

1093-
execute_response = self._handle_execute_response(resp, cursor)
1107+
execute_response, has_more_rows = self._handle_execute_response(resp, cursor)
10941108

10951109
t_row_set = None
10961110
if resp.directResults and resp.directResults.resultSet:
@@ -1106,6 +1120,7 @@ def get_tables(
11061120
t_row_set=t_row_set,
11071121
max_download_threads=self.max_download_threads,
11081122
ssl_options=self._ssl_options,
1123+
has_more_rows=has_more_rows,
11091124
)
11101125

11111126
def get_columns(
@@ -1135,7 +1150,7 @@ def get_columns(
11351150
)
11361151
resp = self.make_request(self._client.GetColumns, req)
11371152

1138-
execute_response = self._handle_execute_response(resp, cursor)
1153+
execute_response, has_more_rows = self._handle_execute_response(resp, cursor)
11391154

11401155
t_row_set = None
11411156
if resp.directResults and resp.directResults.resultSet:
@@ -1151,6 +1166,7 @@ def get_columns(
11511166
t_row_set=t_row_set,
11521167
max_download_threads=self.max_download_threads,
11531168
ssl_options=self._ssl_options,
1169+
has_more_rows=has_more_rows,
11541170
)
11551171

11561172
def _handle_execute_response(self, resp, cursor):

src/databricks/sql/result_set.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def __init__(
160160
t_row_set=None,
161161
max_download_threads: int = 10,
162162
ssl_options=None,
163+
has_more_rows: bool = True,
163164
):
164165
"""
165166
Initialize a ThriftResultSet with direct access to the ThriftDatabricksClient.
@@ -174,6 +175,7 @@ def __init__(
174175
t_row_set: The TRowSet containing result data (if available)
175176
max_download_threads: Maximum number of download threads for cloud fetch
176177
ssl_options: SSL options for cloud fetch
178+
has_more_rows: Whether there are more rows to fetch
177179
"""
178180
# Initialize ThriftResultSet-specific attributes
179181
self._arrow_schema_bytes = execute_response.arrow_schema_bytes
@@ -205,7 +207,7 @@ def __init__(
205207
command_id=execute_response.command_id,
206208
status=execute_response.status,
207209
has_been_closed_server_side=execute_response.has_been_closed_server_side,
208-
has_more_rows=True,
210+
has_more_rows=has_more_rows,
209211
results_queue=results_queue,
210212
description=execute_response.description,
211213
is_staging_operation=execute_response.is_staging_operation,

0 commit comments

Comments
 (0)