Skip to content

Commit 130b0d3

Browse files
raise ServerOperationError for no 0th chunk
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 777f7c1 commit 130b0d3

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def get_chunk_link(self, statement_id: str, chunk_index: int) -> ExternalLink:
653653
)
654654
response = GetChunksResponse.from_dict(response_data)
655655

656-
links = response.external_links
656+
links = response.external_links or []
657657
link = next((l for l in links if l.chunk_index == chunk_index), None)
658658
if not link:
659659
raise ServerOperationError(

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ def __init__(
147147
initial_links = result_data.external_links or []
148148
first_link = next((l for l in initial_links if l.chunk_index == 0), None)
149149
if not first_link:
150-
return
150+
raise ServerOperationError(
151+
"No initial link found for chunk 0",
152+
{
153+
"operation-id": statement_id,
154+
"diagnostic-info": None,
155+
},
156+
)
151157

152158
# Track the current chunk we're processing
153159
self._current_chunk_link = first_link

tests/unit/test_sea_queue.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,33 +378,19 @@ def test_init_no_initial_links(
378378
):
379379
"""Test initialization with no initial links."""
380380
# Create a queue with empty initial links
381-
queue = SeaCloudFetchQueue(
382-
result_data=ResultData(external_links=[]),
383-
max_download_threads=5,
384-
ssl_options=ssl_options,
385-
sea_client=mock_sea_client,
386-
statement_id="test-statement-123",
387-
total_chunk_count=0,
388-
lz4_compressed=False,
389-
description=description,
390-
)
391-
392-
# Verify debug message was logged
393-
mock_logger.debug.assert_called_with(
394-
"SeaCloudFetchQueue: Initialize CloudFetch loader for statement {}, total chunks: {}".format(
395-
"test-statement-123", 0
381+
with pytest.raises(
382+
ServerOperationError, match="No initial link found for chunk 0"
383+
):
384+
queue = SeaCloudFetchQueue(
385+
result_data=ResultData(external_links=[]),
386+
max_download_threads=5,
387+
ssl_options=ssl_options,
388+
sea_client=mock_sea_client,
389+
statement_id="test-statement-123",
390+
total_chunk_count=0,
391+
lz4_compressed=False,
392+
description=description,
396393
)
397-
)
398-
399-
# Verify download manager wasn't created
400-
mock_download_manager_class.assert_not_called()
401-
402-
# Verify attributes
403-
assert queue._statement_id == "test-statement-123"
404-
assert (
405-
not hasattr(queue, "_current_chunk_link")
406-
or queue._current_chunk_link is None
407-
)
408394

409395
@patch("databricks.sql.backend.sea.queue.logger")
410396
def test_progress_chunk_link_no_current_link(self, mock_logger):

0 commit comments

Comments
 (0)