Skip to content

Commit b114599

Browse files
add_link -> add_links for less heavy link additions
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent b5fbeb6 commit b114599

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ def _add_links(self, links: List[ExternalLink]):
188188
len(links),
189189
", ".join(str(l.chunk_index) for l in links) if links else "<none>",
190190
)
191-
for link in links:
192-
self.chunk_index_to_link[link.chunk_index] = link
193-
self.download_manager.add_link(LinkFetcher._convert_to_thrift_link(link))
191+
192+
self.chunk_index_to_link.update({link.chunk_index: link for link in links})
193+
self.download_manager.add_links(
194+
[LinkFetcher._convert_to_thrift_link(link) for link in links]
195+
)
194196

195197
def _get_next_chunk_index(self) -> Optional[int]:
196198
"""Return the next *chunk_index* that should be requested from the backend, or ``None`` if we have them all."""

src/databricks/sql/cloudfetch/download_manager.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,22 @@ def _schedule_downloads(self):
166166
with self._download_condition:
167167
self._download_condition.notify_all()
168168

169-
def add_link(self, link: TSparkArrowResultLink):
169+
def add_links(self, links: List[TSparkArrowResultLink]):
170170
"""
171171
Add more links to the download manager.
172172
173173
Args:
174174
link (TSparkArrowResultLink): The link to add to the download manager.
175175
"""
176-
if link.rowCount <= 0:
177-
return
178-
logger.debug(
179-
"ResultFileDownloadManager: adding file link, start offset {}, row count: {}".format(
180-
link.startRowOffset, link.rowCount
176+
for link in links:
177+
if link.rowCount <= 0:
178+
continue
179+
logger.debug(
180+
"ResultFileDownloadManager: adding file link, start offset {}, row count: {}".format(
181+
link.startRowOffset, link.rowCount
182+
)
181183
)
182-
)
183-
self._pending_links.append(link)
184+
self._pending_links.append(link)
184185

185186
self._schedule_downloads()
186187

src/databricks/sql/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def __init__(
381381
result_link.startRowOffset, result_link.rowCount
382382
)
383383
)
384-
self.download_manager.add_link(result_link)
384+
self.download_manager.add_links(self.result_links)
385385

386386
# Initialize table and position
387387
self.table = self._create_next_table()

tests/unit/test_sea_queue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def test_add_links_and_get_next_chunk_index(self, sample_links):
638638
fetcher, _backend, download_manager = self._create_fetcher([link0])
639639

640640
# add_link should have been called for the initial link
641-
download_manager.add_link.assert_called_once()
641+
download_manager.add_links.assert_called_once()
642642

643643
# Internal mapping should contain the link
644644
assert fetcher.chunk_index_to_link[0] == link0
@@ -668,7 +668,7 @@ def test_trigger_next_batch_download_success(self, sample_links):
668668
backend.get_chunk_links.assert_called_once_with("statement-123", 1)
669669
assert fetcher.chunk_index_to_link[1] == link1
670670
# Two calls to add_link: one for initial link, one for new link
671-
assert download_manager.add_link.call_count == 2
671+
assert download_manager.add_links.call_count == 2
672672

673673
def test_trigger_next_batch_download_error(self, sample_links):
674674
"""Ensure that errors from backend are captured and surfaced."""

0 commit comments

Comments
 (0)