Skip to content

Commit 2ca7c2b

Browse files
return None for out of range
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 6b1b972 commit 2ca7c2b

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,15 @@ def _trigger_next_batch_download(self) -> bool:
231231
)
232232
return True
233233

234-
def get_chunk_link(self, chunk_index: int) -> ExternalLink:
234+
def get_chunk_link(self, chunk_index: int) -> Optional[ExternalLink]:
235235
"""Return (blocking) the :class:`ExternalLink` associated with *chunk_index*."""
236236
logger.debug(
237237
"LinkFetcher[%s]: waiting for link of chunk %d",
238238
self._statement_id,
239239
chunk_index,
240240
)
241241
if chunk_index >= self.total_chunk_count:
242-
raise ValueError(
243-
f"Chunk index {chunk_index} is out of range for total chunk count {self.total_chunk_count}"
244-
)
242+
return None
245243

246244
with self._link_data_update:
247245
while chunk_index not in self.chunk_index_to_link:
@@ -367,6 +365,8 @@ def _create_next_table(self) -> Union["pyarrow.Table", None]:
367365
return None
368366

369367
chunk_link = self.link_fetcher.get_chunk_link(self._current_chunk_index)
368+
if chunk_link is None:
369+
return None
370370

371371
row_offset = chunk_link.row_offset
372372
# NOTE: link has already been submitted to download manager at this point

tests/unit/test_sea_queue.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,9 @@ def test_init_with_valid_initial_link(
351351
description=description,
352352
)
353353

354-
# Verify debug message was logged
355-
mock_logger.debug.assert_called_with(
356-
"SeaCloudFetchQueue: Initialize CloudFetch loader for statement {}, total chunks: {}".format(
357-
"test-statement-123", 1
358-
)
359-
)
360-
361354
# Verify attributes
362355
assert queue._current_chunk_index == 0
356+
assert queue.link_fetcher is not None
363357

364358
@patch("databricks.sql.backend.sea.queue.ResultFileDownloadManager")
365359
@patch("databricks.sql.backend.sea.queue.logger")
@@ -717,14 +711,10 @@ def _worker():
717711
# The thread should have finished and captured link1
718712
assert result_container.get("link") == link1
719713

720-
def test_get_chunk_link_out_of_range_raises_value_error(self, sample_links):
714+
def test_get_chunk_link_out_of_range_returns_none(self, sample_links):
721715
"""Requesting a chunk index >= total_chunk_count should immediately return None."""
722716
link0, _ = sample_links
723717

724718
fetcher, _backend, _dm = self._create_fetcher([link0], total_chunk_count=1)
725719

726-
with pytest.raises(
727-
ValueError,
728-
match="Chunk index 10 is out of range for total chunk count 1",
729-
):
730-
fetcher.get_chunk_link(10)
720+
assert fetcher.get_chunk_link(10) is None

0 commit comments

Comments
 (0)