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

Bigtable: Add 'PartialRowsData.cancel'. #8176

Merged
merged 9 commits into from
Jun 20, 2019
18 changes: 11 additions & 7 deletions bigtable/google/cloud/bigtable/row_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ def __init__(self, read_method, request, retry=DEFAULT_RETRY_READ_ROWS):
self.rows = {}
self._state = self.STATE_NEW_ROW

# Flag to stop iteration, for any reason not related to self.retry()
self.stop = False
mf2199 marked this conversation as resolved.
Show resolved Hide resolved

@property
def state(self):
"""State machine state.
Expand Down Expand Up @@ -439,18 +442,19 @@ def __iter__(self):
while True:
try:
response = self._read_next_response()
for chunk in response.chunks:
if self.stop:
raise StopIteration
mf2199 marked this conversation as resolved.
Show resolved Hide resolved
self._process_chunk(chunk)
if chunk.commit_row:
self.last_scanned_row_key = self._previous_row.row_key
self._counter += 1
yield self._previous_row
except StopIteration:
if self.state != self.NEW_ROW:
raise ValueError("The row remains partial / is not committed.")
break
tseaver marked this conversation as resolved.
Show resolved Hide resolved

for chunk in response.chunks:
self._process_chunk(chunk)
if chunk.commit_row:
self.last_scanned_row_key = self._previous_row.row_key
self._counter += 1
yield self._previous_row

resp_last_key = response.last_scanned_row_key
if resp_last_key and resp_last_key > self.last_scanned_row_key:
self.last_scanned_row_key = resp_last_key
Expand Down