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

perf: improve row merging #619

Merged
merged 4 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
The previous approach of duck typing the protobuf messages to plain python objects no longer works as we need to shuck protoplus now
  • Loading branch information
igorbernstein2 committed Aug 4, 2022
commit 609cdddd557448805284411dec407fb350ddb7c5
18 changes: 10 additions & 8 deletions tests/unit/test_row_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,15 @@ def test_partial_rows_data__copy_from_previous_filled():

def test_partial_rows_data_valid_last_scanned_row_key_on_start():
client = _Client()
response = _ReadRowsResponseV2(chunks=(), last_scanned_row_key="2.AFTER")
response = _ReadRowsResponseV2([], last_scanned_row_key=b"2.AFTER")
iterator = _MockCancellableIterator(response)
client._data_stub = mock.MagicMock()
client._data_stub.read_rows.side_effect = [iterator]
request = object()
yrd = _make_partial_rows_data(client._data_stub.read_rows, request)
yrd.last_scanned_row_key = "1.BEFORE"
yrd.last_scanned_row_key = b"1.BEFORE"
_partial_rows_data_consume_all(yrd)
assert yrd.last_scanned_row_key == "2.AFTER"
assert yrd.last_scanned_row_key == b"2.AFTER"


def test_partial_rows_data_invalid_empty_chunk():
Expand All @@ -666,6 +666,7 @@ def test_partial_rows_data_invalid_empty_chunk():

def test_partial_rows_data_state_cell_in_progress():
from google.cloud.bigtable_v2.services.bigtable import BigtableClient
from google.cloud.bigtable_v2.types import bigtable as messages_v2_pb2

LABELS = ["L1", "L2"]

Expand All @@ -682,6 +683,9 @@ def test_partial_rows_data_state_cell_in_progress():
value=VALUE,
labels=LABELS,
)
# _update_cell expects to be called after the protoplus wrapper has been
# shucked
chunk = messages_v2_pb2.ReadRowsResponse.CellChunk.pb(chunk)
yrd._update_cell(chunk)

more_cell_data = _ReadRowsResponseCellChunkPB(value=VALUE)
Expand Down Expand Up @@ -1455,11 +1459,9 @@ def __init__(self, **kw):
self.__dict__.update(kw)


class _ReadRowsResponseV2(object):
def __init__(self, chunks, last_scanned_row_key=""):
self.chunks = chunks
self.last_scanned_row_key = last_scanned_row_key

def _ReadRowsResponseV2(chunks, last_scanned_row_key=b""):
from google.cloud.bigtable_v2.types import bigtable as messages_v2_pb2
return messages_v2_pb2.ReadRowsResponse(chunks=chunks, last_scanned_row_key=last_scanned_row_key)

def _generate_cell_chunks(chunk_text_pbs):
from google.protobuf.text_format import Merge
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,10 +2206,9 @@ def next(self):
__next__ = next


class _ReadRowsResponseV2(object):
def __init__(self, chunks, last_scanned_row_key=""):
self.chunks = chunks
self.last_scanned_row_key = last_scanned_row_key
def _ReadRowsResponseV2(chunks, last_scanned_row_key=b""):
from google.cloud.bigtable_v2.types import bigtable as messages_v2_pb2
return messages_v2_pb2.ReadRowsResponse(chunks=chunks, last_scanned_row_key=last_scanned_row_key)


def _TablePB(*args, **kw):
Expand Down