Skip to content

Commit 26aa45c

Browse files
make get_chunk_link return mandatory ExternalLink
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 23dba80 commit 26aa45c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ def _trigger_next_batch_download(self) -> bool:
178178

179179
return True
180180

181-
def get_chunk_link(self, chunk_index: int) -> Optional[ExternalLink]:
181+
def get_chunk_link(self, chunk_index: int) -> ExternalLink:
182182
if chunk_index >= self.total_chunk_count:
183-
return None
183+
raise ValueError(
184+
f"Chunk index {chunk_index} is out of range for total chunk count {self.total_chunk_count}"
185+
)
184186

185187
with self._link_data_update:
186188
while chunk_index not in self.chunk_index_to_link:
@@ -194,7 +196,7 @@ def get_chunk_link(self, chunk_index: int) -> Optional[ExternalLink]:
194196
)
195197
self._link_data_update.wait()
196198

197-
return self.chunk_index_to_link.get(chunk_index, None)
199+
return self.chunk_index_to_link[chunk_index]
198200

199201
@staticmethod
200202
def _convert_to_thrift_link(link: ExternalLink) -> TSparkArrowResultLink:
@@ -296,8 +298,6 @@ def _create_next_table(self) -> Union["pyarrow.Table", None]:
296298
return None
297299

298300
chunk_link = self.link_fetcher.get_chunk_link(self._current_chunk_index)
299-
if not chunk_link:
300-
return None
301301

302302
row_offset = chunk_link.row_offset
303303
arrow_table = self._create_table_at_offset(row_offset)

tests/unit/test_sea_queue.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,14 @@ def _worker():
717717
# The thread should have finished and captured link1
718718
assert result_container.get("link") == link1
719719

720-
def test_get_chunk_link_out_of_range_returns_none(self, sample_links):
720+
def test_get_chunk_link_out_of_range_raises_value_error(self, sample_links):
721721
"""Requesting a chunk index >= total_chunk_count should immediately return None."""
722722
link0, _ = sample_links
723723

724724
fetcher, _backend, _dm = self._create_fetcher([link0], total_chunk_count=1)
725725

726-
assert fetcher.get_chunk_link(10) is None
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)

0 commit comments

Comments
 (0)