Skip to content

Commit 0a75039

Browse files
vuanhphungIsaac
andcommitted
Treat a CloudFetch link without bytesNum as size 0
The Thrift reader doesn't enforce required fields, so a missing size must not fail the fetch; it only disables the sizing heuristic. Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 9ae3548 commit 0a75039

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎src/databricks/sql/result_set.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,11 @@ def __init__(
286286

287287
def _note_link_sizes(self, links) -> None:
288288
for link in links:
289-
if link.bytesNum > self._max_link_bytes:
290-
self._max_link_bytes = link.bytesNum
289+
# The reader doesn't enforce required fields; a missing size only
290+
# disables the sizing heuristic.
291+
size = link.bytesNum or 0
292+
if size > self._max_link_bytes:
293+
self._max_link_bytes = size
291294

292295
def _fetch_max_bytes(self) -> int:
293296
# The server packs CloudFetch links into a FetchResults reply up to maxBytes of

‎tests/unit/test_fetches.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,17 @@ def test_caps_at_four_buffers(self):
499499

500500
self.assertEqual(calls[0]["max_bytes"], 4 * self.BUFFER)
501501

502+
def test_links_without_size_keep_buffer_size(self):
503+
rs, calls = self._make_result_set(
504+
initial_link_sizes=[None],
505+
fetched_queues=[self._cloudfetch_queue(None), self._cloudfetch_queue()],
506+
)
507+
508+
rs._fill_results_buffer()
509+
rs._fill_results_buffer()
510+
511+
self.assertEqual([c["max_bytes"] for c in calls], [self.BUFFER, self.BUFFER])
512+
502513
def test_small_buffer_size_caps_batch(self):
503514
rs, calls = self._make_result_set(
504515
initial_link_sizes=[20 * self.MIB],

0 commit comments

Comments
 (0)