Visitar URL original
chore: reduce public api surface (#820) · googleapis/python-bigtable@a8cdf7c · GitHub
Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

Commit a8cdf7c

Browse files
chore: reduce public api surface (#820)
1 parent 0d92a84 commit a8cdf7c

16 files changed

Lines changed: 408 additions & 230 deletions

‎google/cloud/bigtable/data/_async/_mutate_rows.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from google.cloud.bigtable.data._helpers import _attempt_timeout_generator
2626

2727
# mutate_rows requests are limited to this number of mutations
28-
from google.cloud.bigtable.data.mutations import MUTATE_ROWS_REQUEST_MUTATION_LIMIT
28+
from google.cloud.bigtable.data.mutations import _MUTATE_ROWS_REQUEST_MUTATION_LIMIT
2929

3030
if TYPE_CHECKING:
3131
from google.cloud.bigtable_v2.services.bigtable.async_client import (
@@ -65,10 +65,10 @@ def __init__(
6565
"""
6666
# check that mutations are within limits
6767
total_mutations = sum(len(entry.mutations) for entry in mutation_entries)
68-
if total_mutations > MUTATE_ROWS_REQUEST_MUTATION_LIMIT:
68+
if total_mutations > _MUTATE_ROWS_REQUEST_MUTATION_LIMIT:
6969
raise ValueError(
7070
"mutate_rows requests can contain at most "
71-
f"{MUTATE_ROWS_REQUEST_MUTATION_LIMIT} mutations across "
71+
f"{_MUTATE_ROWS_REQUEST_MUTATION_LIMIT} mutations across "
7272
f"all entries. Found {total_mutations}."
7373
)
7474
# create partial function to pass to trigger rpc call

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
from google.cloud.bigtable.data import ShardedQuery
7575

7676
# used by read_rows_sharded to limit how many requests are attempted in parallel
77-
CONCURRENCY_LIMIT = 10
77+
_CONCURRENCY_LIMIT = 10
7878

7979
# used to register instance data with the client for channel warming
8080
_WarmedInstanceKey = namedtuple(
@@ -154,7 +154,7 @@ def __init__(
154154
self._channel_init_time = time.monotonic()
155155
self._channel_refresh_tasks: list[asyncio.Task[None]] = []
156156
try:
157-
self.start_background_channel_refresh()
157+
self._start_background_channel_refresh()
158158
except RuntimeError:
159159
warnings.warn(
160160
f"{self.__class__.__name__} should be started in an "
@@ -163,7 +163,7 @@ def __init__(
163163
stacklevel=2,
164164
)
165165

166-
def start_background_channel_refresh(self) -> None:
166+
def _start_background_channel_refresh(self) -> None:
167167
"""
168168
Starts a background task to ping and warm each channel in the pool
169169
Raises:
@@ -309,7 +309,7 @@ async def _register_instance(self, instance_id: str, owner: TableAsync) -> None:
309309
await self._ping_and_warm_instances(channel, instance_key)
310310
else:
311311
# refresh tasks aren't active. start them as background tasks
312-
self.start_background_channel_refresh()
312+
self._start_background_channel_refresh()
313313

314314
async def _remove_instance_registration(
315315
self, instance_id: str, owner: TableAsync
@@ -388,7 +388,7 @@ def get_table(
388388
)
389389

390390
async def __aenter__(self):
391-
self.start_background_channel_refresh()
391+
self._start_background_channel_refresh()
392392
return self
393393

394394
async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -493,7 +493,7 @@ def __init__(
493493

494494
async def read_rows_stream(
495495
self,
496-
query: ReadRowsQuery | dict[str, Any],
496+
query: ReadRowsQuery,
497497
*,
498498
operation_timeout: float | None = None,
499499
attempt_timeout: float | None = None,
@@ -557,7 +557,7 @@ async def read_rows_stream(
557557

558558
async def read_rows(
559559
self,
560-
query: ReadRowsQuery | dict[str, Any],
560+
query: ReadRowsQuery,
561561
*,
562562
operation_timeout: float | None = None,
563563
attempt_timeout: float | None = None,
@@ -687,10 +687,10 @@ async def read_rows_sharded(
687687
timeout_generator = _attempt_timeout_generator(
688688
operation_timeout, operation_timeout
689689
)
690-
# submit shards in batches if the number of shards goes over CONCURRENCY_LIMIT
690+
# submit shards in batches if the number of shards goes over _CONCURRENCY_LIMIT
691691
batched_queries = [
692-
sharded_query[i : i + CONCURRENCY_LIMIT]
693-
for i in range(0, len(sharded_query), CONCURRENCY_LIMIT)
692+
sharded_query[i : i + _CONCURRENCY_LIMIT]
693+
for i in range(0, len(sharded_query), _CONCURRENCY_LIMIT)
694694
]
695695
# run batches and collect results
696696
results_list = []
@@ -1038,7 +1038,7 @@ async def bulk_mutate_rows(
10381038
async def check_and_mutate_row(
10391039
self,
10401040
row_key: str | bytes,
1041-
predicate: RowFilter | dict[str, Any] | None,
1041+
predicate: RowFilter | None,
10421042
*,
10431043
true_case_mutations: Mutation | list[Mutation] | None = None,
10441044
false_case_mutations: Mutation | list[Mutation] | None = None,
@@ -1091,12 +1091,12 @@ async def check_and_mutate_row(
10911091
):
10921092
false_case_mutations = [false_case_mutations]
10931093
false_case_dict = [m._to_dict() for m in false_case_mutations or []]
1094-
if predicate is not None and not isinstance(predicate, dict):
1095-
predicate = predicate.to_dict()
10961094
metadata = _make_metadata(self.table_name, self.app_profile_id)
10971095
result = await self.client._gapic_client.check_and_mutate_row(
10981096
request={
1099-
"predicate_filter": predicate,
1097+
"predicate_filter": predicate._to_dict()
1098+
if predicate is not None
1099+
else None,
11001100
"true_mutations": true_case_dict,
11011101
"false_mutations": false_case_dict,
11021102
"table_name": self.table_name,

‎google/cloud/bigtable/data/_async/mutations_batcher.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from google.cloud.bigtable.data._async._mutate_rows import _MutateRowsOperationAsync
2929
from google.cloud.bigtable.data._async._mutate_rows import (
30-
MUTATE_ROWS_REQUEST_MUTATION_LIMIT,
30+
_MUTATE_ROWS_REQUEST_MUTATION_LIMIT,
3131
)
3232
from google.cloud.bigtable.data.mutations import Mutation
3333

@@ -144,7 +144,7 @@ async def add_to_flow(self, mutations: RowMutationEntry | list[RowMutationEntry]
144144
self._has_capacity(next_count, next_size)
145145
# make sure not to exceed per-request mutation count limits
146146
and (batch_mutation_count + next_count)
147-
<= MUTATE_ROWS_REQUEST_MUTATION_LIMIT
147+
<= _MUTATE_ROWS_REQUEST_MUTATION_LIMIT
148148
):
149149
# room for new mutation; add to batch
150150
end_idx += 1

‎google/cloud/bigtable/data/mutations.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from abc import ABC, abstractmethod
2020
from sys import getsizeof
2121

22-
from google.cloud.bigtable.data.read_modify_write_rules import MAX_INCREMENT_VALUE
2322

24-
# special value for SetCell mutation timestamps. If set, server will assign a timestamp
25-
SERVER_SIDE_TIMESTAMP = -1
23+
from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE
2624

25+
# special value for SetCell mutation timestamps. If set, server will assign a timestamp
26+
_SERVER_SIDE_TIMESTAMP = -1
2727

2828
# mutation entries above this should be rejected
29-
MUTATE_ROWS_REQUEST_MUTATION_LIMIT = 100_000
29+
_MUTATE_ROWS_REQUEST_MUTATION_LIMIT = 100_000
3030

3131

3232
class Mutation(ABC):
@@ -112,7 +112,7 @@ def __init__(
112112
if isinstance(new_value, str):
113113
new_value = new_value.encode()
114114
elif isinstance(new_value, int):
115-
if abs(new_value) > MAX_INCREMENT_VALUE:
115+
if abs(new_value) > _MAX_INCREMENT_VALUE:
116116
raise ValueError(
117117
"int values must be between -2**63 and 2**63 (64-bit signed int)"
118118
)
@@ -123,9 +123,9 @@ def __init__(
123123
# use current timestamp, with milisecond precision
124124
timestamp_micros = time.time_ns() // 1000
125125
timestamp_micros = timestamp_micros - (timestamp_micros % 1000)
126-
if timestamp_micros < SERVER_SIDE_TIMESTAMP:
126+
if timestamp_micros < _SERVER_SIDE_TIMESTAMP:
127127
raise ValueError(
128-
"timestamp_micros must be positive (or -1 for server-side timestamp)"
128+
f"timestamp_micros must be positive (or {_SERVER_SIDE_TIMESTAMP} for server-side timestamp)"
129129
)
130130
self.family = family
131131
self.qualifier = qualifier
@@ -145,7 +145,7 @@ def _to_dict(self) -> dict[str, Any]:
145145

146146
def is_idempotent(self) -> bool:
147147
"""Check if the mutation is idempotent"""
148-
return self.timestamp_micros != SERVER_SIDE_TIMESTAMP
148+
return self.timestamp_micros != _SERVER_SIDE_TIMESTAMP
149149

150150

151151
@dataclass
@@ -208,9 +208,9 @@ def __init__(self, row_key: bytes | str, mutations: Mutation | list[Mutation]):
208208
mutations = [mutations]
209209
if len(mutations) == 0:
210210
raise ValueError("mutations must not be empty")
211-
elif len(mutations) > MUTATE_ROWS_REQUEST_MUTATION_LIMIT:
211+
elif len(mutations) > _MUTATE_ROWS_REQUEST_MUTATION_LIMIT:
212212
raise ValueError(
213-
f"entries must have <= {MUTATE_ROWS_REQUEST_MUTATION_LIMIT} mutations"
213+
f"entries must have <= {_MUTATE_ROWS_REQUEST_MUTATION_LIMIT} mutations"
214214
)
215215
self.row_key = row_key
216216
self.mutations = tuple(mutations)

‎google/cloud/bigtable/data/read_modify_write_rules.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import abc
1818

1919
# value must fit in 64-bit signed integer
20-
MAX_INCREMENT_VALUE = (1 << 63) - 1
20+
_MAX_INCREMENT_VALUE = (1 << 63) - 1
2121

2222

2323
class ReadModifyWriteRule(abc.ABC):
@@ -37,7 +37,7 @@ class IncrementRule(ReadModifyWriteRule):
3737
def __init__(self, family: str, qualifier: bytes | str, increment_amount: int = 1):
3838
if not isinstance(increment_amount, int):
3939
raise TypeError("increment_amount must be an integer")
40-
if abs(increment_amount) > MAX_INCREMENT_VALUE:
40+
if abs(increment_amount) > _MAX_INCREMENT_VALUE:
4141
raise ValueError(
4242
"increment_amount must be between -2**63 and 2**63 (64-bit signed int)"
4343
)

0 commit comments

Comments
 (0)