-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Batch Write API implementation and samples
- Loading branch information
Showing
8 changed files
with
528 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2508,6 +2508,44 @@ def test_partition_query(sessions_database, not_emulator): | |
batch_txn.close() | ||
|
||
|
||
def test_mutation_groups_insert_or_update_then_query(sessions_database): | ||
sd = _sample_data | ||
ROW_DATA = ( | ||
(1, "Phred", "Phlyntstone", "[email protected]"), | ||
(2, "Bharney", "Rhubble", "[email protected]"), | ||
(3, "Wylma", "Phlyntstone", "[email protected]"), | ||
(4, "Pebbles", "Phlyntstone", "[email protected]"), | ||
(5, "Betty", "Rhubble", "[email protected]"), | ||
(6, "Slate", "Stephenson", "[email protected]"), | ||
) | ||
num_groups = 3 | ||
num_mutations_per_group = len(ROW_DATA) // num_groups | ||
|
||
with sessions_database.mutation_groups() as groups: | ||
for i in range(num_groups): | ||
group = groups.group() | ||
for j in range(num_mutations_per_group): | ||
group.insert_or_update( | ||
sd.TABLE, sd.COLUMNS, [ROW_DATA[i * num_mutations_per_group + j]] | ||
) | ||
# Response indexes received | ||
seen = collections.Counter() | ||
for response in groups.batch_write(): | ||
_check_batch_status(response.status.code) | ||
assert response.commit_timestamp is not None | ||
assert len(response.indexes) > 0 | ||
seen.update(response.indexes) | ||
# All indexes must be in the range [0, num_groups-1] and seen exactly once | ||
assert len(seen) == num_groups | ||
assert all((0 <= idx < num_groups and ct == 1) for (idx, ct) in seen.items()) | ||
|
||
# Verify the writes by reading from the database | ||
with sessions_database.snapshot() as snapshot: | ||
rows = list(snapshot.execute_sql(sd.SQL)) | ||
|
||
sd._check_rows_data(rows, ROW_DATA) | ||
|
||
|
||
class FauxCall: | ||
def __init__(self, code, details="FauxCall"): | ||
self._code = code | ||
|
Oops, something went wrong.