Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataset_select_paginated: do not clone on each paginated query #629

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/datachain/data_storage/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,28 @@ def dataset_select_paginated(
offset = 0
num_yielded = 0

while True:
if limit is not None:
limit -= num_yielded
if limit == 0:
break
if limit < page_size:
paginated_query = paginated_query.limit(None).limit(limit)

# Ensure we're using a thread-local connection
with self.clone() as wh:
# Ensure we're using a thread-local connection
with self.clone() as wh:
while True:
if limit is not None:
limit -= num_yielded
if limit == 0:
break
if limit < page_size:
paginated_query = paginated_query.limit(None).limit(limit)

# Cursor results are not thread-safe, so we convert them to a list
results = list(wh.dataset_rows_select(paginated_query.offset(offset)))

processed = False
for row in results:
processed = True
yield row
num_yielded += 1
processed = False
for row in results:
processed = True
yield row
num_yielded += 1

if not processed:
break # no more results
offset += page_size
if not processed:
break # no more results
offset += page_size

#
# Table Name Internal Functions
Expand Down