Skip to content

Commit 5d59610

Browse files
committed
Acknowledge reception of data in TrinoResult
1 parent ac4c458 commit 5d59610

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

trino/client.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ class TrinoResult(object):
594594

595595
def __init__(self, query, rows=None, experimental_python_types: bool = False):
596596
self._query = query
597-
self._rows = rows or []
597+
# Initial rows from the first POST request
598+
self._rows = rows
598599
self._rownumber = 0
599600
self._experimental_python_types = experimental_python_types
600601

@@ -603,20 +604,17 @@ def rownumber(self) -> int:
603604
return self._rownumber
604605

605606
def __iter__(self):
606-
# Initial fetch from the first POST request
607-
for row in self._rows:
608-
self._rownumber += 1
609-
yield self._map_row(self._experimental_python_types, row, self._query.columns)
610-
self._rows = None
611-
612-
# Subsequent fetches from GET requests until next_uri is empty.
613-
while not self._query.finished:
614-
rows = self._query.fetch()
615-
for row in rows:
607+
# A query only transitions to a FINISHED state when the results are fully consumed:
608+
# The reception of the data is acknowledged by calling the next_uri before exposing the data through dbapi.
609+
while not self._query.finished or self._rows is not None:
610+
next_rows = self._query.fetch() if not self._query.finished else None
611+
for row in self._rows:
616612
self._rownumber += 1
617613
logger.debug("row %s", row)
618614
yield self._map_row(self._experimental_python_types, row, self._query.columns)
619615

616+
self._rows = next_rows
617+
620618
@property
621619
def response_headers(self):
622620
return self._query.response_headers

trino/dbapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def _prepare_statement(self, operation, statement_name):
322322
operation=operation
323323
)
324324

325-
# Send prepare statement. Copy the _request object to avoid poluting the
325+
# Send prepare statement. Copy the _request object to avoid polluting the
326326
# one that is going to be used to execute the actual operation.
327327
query = trino.client.TrinoQuery(copy.deepcopy(self._request), sql=sql,
328328
experimental_python_types=self._experimental_pyton_types)

0 commit comments

Comments
 (0)