Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 9d83a7b

Browse files
committed
feat: Reworked MutateRows to use the data client
1 parent 6153a5c commit 9d83a7b

7 files changed

Lines changed: 321 additions & 938 deletions

File tree

google/cloud/bigtable/data/_async/client.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,33 @@ async def mutate_row(
15561556
exception_factory=_retry_exception_factory,
15571557
)
15581558

1559+
@CrossSync.convert
1560+
def _get_mutate_rows_operation(
1561+
self,
1562+
mutation_entries: list[RowMutationEntry],
1563+
*,
1564+
operation_timeout: float | TABLE_DEFAULT,
1565+
attempt_timeout: float | None | TABLE_DEFAULT,
1566+
retryable_errors: Sequence[type[Exception]] | TABLE_DEFAULT,
1567+
) -> CrossSync._MutateRowsOperation:
1568+
"""
1569+
Gets the bulk mutate rows operation object for the given mutation entries.
1570+
"""
1571+
operation_timeout, attempt_timeout = _get_timeouts(
1572+
operation_timeout, attempt_timeout, self
1573+
)
1574+
retryable_excs = _get_retryable_errors(retryable_errors, self)
1575+
1576+
operation = CrossSync._MutateRowsOperation(
1577+
self.client._gapic_client,
1578+
self,
1579+
mutation_entries,
1580+
operation_timeout,
1581+
attempt_timeout,
1582+
retryable_exceptions=retryable_excs,
1583+
)
1584+
return operation
1585+
15591586
@CrossSync.convert
15601587
async def bulk_mutate_rows(
15611588
self,
@@ -1597,18 +1624,11 @@ async def bulk_mutate_rows(
15971624
Contains details about any failed entries in .exceptions
15981625
ValueError: if invalid arguments are provided
15991626
"""
1600-
operation_timeout, attempt_timeout = _get_timeouts(
1601-
operation_timeout, attempt_timeout, self
1602-
)
1603-
retryable_excs = _get_retryable_errors(retryable_errors, self)
1604-
1605-
operation = CrossSync._MutateRowsOperation(
1606-
self.client._gapic_client,
1607-
self,
1627+
operation = self._get_mutate_rows_operation(
16081628
mutation_entries,
1609-
operation_timeout,
1610-
attempt_timeout,
1611-
retryable_exceptions=retryable_excs,
1629+
operation_timeout=operation_timeout,
1630+
attempt_timeout=attempt_timeout,
1631+
retryable_errors=retryable_errors,
16121632
)
16131633
await operation.start()
16141634

google/cloud/bigtable/data/_sync_autogen/client.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,29 @@ def mutate_row(
12991299
exception_factory=_retry_exception_factory,
13001300
)
13011301

1302+
def _get_mutate_rows_operation(
1303+
self,
1304+
mutation_entries: list[RowMutationEntry],
1305+
*,
1306+
operation_timeout: float | TABLE_DEFAULT,
1307+
attempt_timeout: float | None | TABLE_DEFAULT,
1308+
retryable_errors: Sequence[type[Exception]] | TABLE_DEFAULT,
1309+
) -> CrossSync._Sync_Impl._MutateRowsOperation:
1310+
"""Gets the bulk mutate rows operation object for the given mutation entries."""
1311+
(operation_timeout, attempt_timeout) = _get_timeouts(
1312+
operation_timeout, attempt_timeout, self
1313+
)
1314+
retryable_excs = _get_retryable_errors(retryable_errors, self)
1315+
operation = CrossSync._Sync_Impl._MutateRowsOperation(
1316+
self.client._gapic_client,
1317+
self,
1318+
mutation_entries,
1319+
operation_timeout,
1320+
attempt_timeout,
1321+
retryable_exceptions=retryable_excs,
1322+
)
1323+
return operation
1324+
13021325
def bulk_mutate_rows(
13031326
self,
13041327
mutation_entries: list[RowMutationEntry],
@@ -1337,17 +1360,11 @@ def bulk_mutate_rows(
13371360
MutationsExceptionGroup: if one or more mutations fails
13381361
Contains details about any failed entries in .exceptions
13391362
ValueError: if invalid arguments are provided"""
1340-
(operation_timeout, attempt_timeout) = _get_timeouts(
1341-
operation_timeout, attempt_timeout, self
1342-
)
1343-
retryable_excs = _get_retryable_errors(retryable_errors, self)
1344-
operation = CrossSync._Sync_Impl._MutateRowsOperation(
1345-
self.client._gapic_client,
1346-
self,
1363+
operation = self._get_mutate_rows_operation(
13471364
mutation_entries,
1348-
operation_timeout,
1349-
attempt_timeout,
1350-
retryable_exceptions=retryable_excs,
1365+
operation_timeout=operation_timeout,
1366+
attempt_timeout=attempt_timeout,
1367+
retryable_errors=retryable_errors,
13511368
)
13521369
operation.start()
13531370

google/cloud/bigtable/row.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,16 @@ def _set_cell(self, column_family_id, column, value, timestamp=None, state=None)
153153
integer (8 bytes).
154154
155155
:type timestamp: :class:`datetime.datetime`
156-
:param timestamp: (Optional) The timestamp of the operation.
156+
:param timestamp: (Optional) The timestamp of the operation. If a
157+
timestamp is not provided, the current system time
158+
will be used.
157159
158160
:type state: bool
159161
:param state: (Optional) The state that is passed along to
160162
:meth:`_get_mutations`.
161163
"""
162-
if timestamp is None:
163-
# Use current Bigtable server time.
164-
timestamp_micros = mutations._SERVER_SIDE_TIMESTAMP
164+
if timestamp is None or timestamp == mutations._SERVER_SIDE_TIMESTAMP:
165+
timestamp_micros = timestamp
165166
else:
166167
timestamp_micros = _microseconds_from_datetime(timestamp)
167168
# Truncate to millisecond granularity.
@@ -351,7 +352,9 @@ def set_cell(self, column_family_id, column, value, timestamp=None):
351352
integer (8 bytes).
352353
353354
:type timestamp: :class:`datetime.datetime`
354-
:param timestamp: (Optional) The timestamp of the operation.
355+
:param timestamp: (Optional) The timestamp of the operation. If a
356+
timestamp is not provided, the current system time
357+
will be used.
355358
"""
356359
self._set_cell(column_family_id, column, value, timestamp=timestamp, state=None)
357360

@@ -651,7 +654,9 @@ def set_cell(self, column_family_id, column, value, timestamp=None, state=True):
651654
integer (8 bytes).
652655
653656
:type timestamp: :class:`datetime.datetime`
654-
:param timestamp: (Optional) The timestamp of the operation.
657+
:param timestamp: (Optional) The timestamp of the operation. If a
658+
timestamp is not provided, the current system time
659+
will be used.
655660
656661
:type state: bool
657662
:param state: (Optional) The state that the mutation should be

0 commit comments

Comments
 (0)