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

chore: add cross_sync annotations #1000

Merged
merged 341 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
341 commits
Select commit Hold shift + click to select a range
9cf3923
removed old sync tests
daniel-sanche Jun 21, 2024
c59eec2
got unit tests passing
daniel-sanche Jun 21, 2024
fac2583
Merge branch 'main' into sync_generator_cross_sync
daniel-sanche Jun 22, 2024
8ef9047
updated sync files
daniel-sanche Jun 22, 2024
0705ee9
got sharding working with cross_sync
daniel-sanche Jun 22, 2024
426057f
fixed mypy errors
daniel-sanche Jun 22, 2024
0c79e39
ran blacken
daniel-sanche Jun 22, 2024
4aa53eb
generate sync unit tests
daniel-sanche Jun 24, 2024
6ae2428
improved import generation
daniel-sanche Jun 24, 2024
fdce0bc
fixed cross sync import conditional
daniel-sanche Jun 24, 2024
adc8bb7
fixed import
daniel-sanche Jun 24, 2024
31fb77a
got rpc tests passing
daniel-sanche Jun 24, 2024
fc44b30
removed custom is_async
daniel-sanche Jun 24, 2024
255e124
support dropping methods
daniel-sanche Jun 24, 2024
87aecb3
got tests passing
daniel-sanche Jun 25, 2024
a1426a5
got test_client sync tests passing
daniel-sanche Jun 25, 2024
ba351e3
dded simplified transformer to crosssync
daniel-sanche Jun 28, 2024
d6fac8e
strip out basic sync code
daniel-sanche Jun 28, 2024
d25a517
include headers
daniel-sanche Jun 28, 2024
5dd32fd
add file imports
daniel-sanche Jul 2, 2024
cd40ba9
refactoring
daniel-sanche Jul 3, 2024
fd639e4
fixed docstrings
daniel-sanche Jul 3, 2024
c1053e9
made changes to docstring format in generated files
daniel-sanche Jul 3, 2024
c925760
simplified generator visit
daniel-sanche Jul 3, 2024
9f9ec0f
replace string types
daniel-sanche Jul 3, 2024
e5168a1
add mypyy disabling
daniel-sanche Jul 3, 2024
9bd13b3
regenerated imports
daniel-sanche Jul 3, 2024
6895968
got rename_sync decorator working
daniel-sanche Jul 3, 2024
09c090d
made convert decorator
daniel-sanche Jul 3, 2024
ab28899
added CrossSync.Awaitable
daniel-sanche Jul 3, 2024
40678e0
more targeted replacements
daniel-sanche Jul 3, 2024
79f7b74
got test conversion working
daniel-sanche Jul 3, 2024
2652158
keep try import blocks
daniel-sanche Jul 3, 2024
5b31779
refactored into node transformer
daniel-sanche Jul 3, 2024
53dbb77
added pytest decorator
daniel-sanche Jul 3, 2024
e93f2ac
got test_client passing again
daniel-sanche Jul 3, 2024
515f565
added mock to crosssync
daniel-sanche Jul 3, 2024
4c6bac2
more targeted replacements
daniel-sanche Jul 3, 2024
998829e
ran blacken
daniel-sanche Jul 4, 2024
40e961e
fixed some lint issues
daniel-sanche Jul 4, 2024
ec63aa7
got tests passing
daniel-sanche Jul 4, 2024
5cdf5d9
ran black
daniel-sanche Jul 4, 2024
b964c8d
use crossync for system tests
daniel-sanche Jul 8, 2024
a968905
don't manually clear channel refresh list
daniel-sanche Jul 8, 2024
95c30f8
mark each method to convert
daniel-sanche Jul 8, 2024
8c88f08
cleaning; adding docstrings
daniel-sanche Jul 8, 2024
c93597b
use custom class for decorators
daniel-sanche Jul 9, 2024
32f1631
mark pytest methods for conversion
daniel-sanche Jul 11, 2024
b6fb1d5
convert crosssync.pytest to sync
daniel-sanche Jul 11, 2024
f90d54c
removed unneeded check
daniel-sanche Jul 11, 2024
f5dfa3e
use AstDecorator for pytest_fixture
daniel-sanche Jul 11, 2024
ce45742
renamed class decorator
daniel-sanche Jul 11, 2024
49b4808
import instead of duplicate
daniel-sanche Jul 11, 2024
18e4977
import sync classes
daniel-sanche Jul 11, 2024
48bb06f
removed sync classes
daniel-sanche Jul 11, 2024
245bd08
removed conversion decorators
daniel-sanche Jul 11, 2024
74a69c3
removed main function from cross_sync
daniel-sanche Jul 11, 2024
276add1
removed sync classes from __init__.py
daniel-sanche Jul 11, 2024
d3906bf
removed unused file
daniel-sanche Jul 11, 2024
73c6e2f
remove sync pooled generator
daniel-sanche Jul 11, 2024
1911296
reverted some style changes
daniel-sanche Jul 11, 2024
e166bbe
removed left ofer crosssync.drop
daniel-sanche Jul 11, 2024
6b244c5
removed else branches of cross sync imports
daniel-sanche Jul 11, 2024
9e1afc3
fixed mypy error
daniel-sanche Jul 11, 2024
2a46630
added back file
daniel-sanche Jul 12, 2024
2691686
removed file
daniel-sanche Jul 12, 2024
f48604e
moved non-async helper classes out of async folder
daniel-sanche Jul 12, 2024
a61c54f
fixed lint
daniel-sanche Jul 12, 2024
8b379c8
improve version string calculation
daniel-sanche Jul 12, 2024
14259e2
created method for event loop verification
daniel-sanche Jul 12, 2024
9b7c1e2
reverted some behavior
daniel-sanche Jul 12, 2024
88fda0d
added comments
daniel-sanche Jul 12, 2024
c3787ca
added comments
daniel-sanche Jul 12, 2024
7f65063
removed sync implementation from cross_sync
daniel-sanche Jul 12, 2024
caf27e2
added sync_impl
daniel-sanche Jul 12, 2024
8af6438
added cross sync ast transform system
daniel-sanche Jul 12, 2024
8d763f8
added conversion annotations
daniel-sanche Jul 12, 2024
5efc840
fixed import
daniel-sanche Jul 12, 2024
eb5cd48
refactor outputs
daniel-sanche Jul 12, 2024
e5a8792
renamed artifact class; added comments
daniel-sanche Jul 12, 2024
39ae907
added back conversion annotations
daniel-sanche Jul 12, 2024
d17a98c
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 12, 2024
fd1fb71
fixed decorator sync_impl call
daniel-sanche Jul 12, 2024
c0b4185
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 12, 2024
adb092e
use add_mapping in place of replace_symbols
daniel-sanche Jul 12, 2024
45efa16
support automatic attribute registration
daniel-sanche Jul 12, 2024
e1ec974
reduced replace_symbols usage in tests
daniel-sanche Jul 13, 2024
021fde2
fixed lint issues
daniel-sanche Jul 13, 2024
58405d1
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 13, 2024
de0fd90
added missing imports
daniel-sanche Jul 13, 2024
6ca3ddd
get mappings working for sync implementation
daniel-sanche Jul 13, 2024
b2cf937
moved decorators into new file
daniel-sanche Jul 15, 2024
4860061
moved transformation from transformers into decorators
daniel-sanche Jul 16, 2024
63891d7
simplified arguments for decorators
daniel-sanche Jul 16, 2024
164f5a8
use separate decorate method
daniel-sanche Jul 16, 2024
8317973
comments and clean up
daniel-sanche Jul 17, 2024
f9dd41d
ran blacken
daniel-sanche Jul 17, 2024
22b093f
moved ast decorators into new file
daniel-sanche Jul 17, 2024
5ebf889
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 17, 2024
8d13c5e
ran blacken
daniel-sanche Jul 17, 2024
ea8072f
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 17, 2024
769cac1
changed sync impl name
daniel-sanche Jul 17, 2024
f87b832
fixed mapping function
daniel-sanche Jul 17, 2024
f2b6d08
convert to async with pytest mark
daniel-sanche Jul 17, 2024
754adf8
Merge branch 'cross_sync_pr1_replacements' into cross_sync_pr2_genera…
daniel-sanche Jul 17, 2024
3ed5935
convert changes async to sync def by default
daniel-sanche Jul 17, 2024
d0ba7b0
added rm_aio for stripping asyncio keywords
daniel-sanche Jul 18, 2024
37b4833
reverted client and test changes
daniel-sanche Jul 18, 2024
af020a2
Revert "reverted client and test changes"
daniel-sanche Jul 18, 2024
698902d
added sync pooled transport
daniel-sanche Jul 18, 2024
64166db
only strip CrossSync.rm_aio on Call visits
daniel-sanche Jul 18, 2024
73ba23b
support decorators in nested functions
daniel-sanche Jul 18, 2024
12e8860
added missing convert annotations
daniel-sanche Jul 22, 2024
63a528a
added import blocks for sync versions
daniel-sanche Jul 22, 2024
f5dcdf5
added annotations to tests
daniel-sanche Jul 22, 2024
be40771
removed unneeded test imports
daniel-sanche Jul 22, 2024
a676d49
ran blacken
daniel-sanche Jul 22, 2024
c63d88e
fixed lint issues
daniel-sanche Jul 22, 2024
03b60ed
removed quoted cross sync classes
daniel-sanche Jul 22, 2024
3762a03
fixed mypy issues
daniel-sanche Jul 22, 2024
274bd36
moved cross_sync into own directory
daniel-sanche Jul 22, 2024
5611614
added docstrings
daniel-sanche Jul 22, 2024
ad95748
added README
daniel-sanche Jul 22, 2024
cad416d
fixed README formatting
daniel-sanche Jul 22, 2024
9b92e65
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Jul 22, 2024
9a19658
added rm_aio to pytest and convert decorators
daniel-sanche Jul 23, 2024
a378c45
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Jul 23, 2024
02b2268
Merge branch 'main' into cross_sync2_pr1_architecture
daniel-sanche Jul 23, 2024
f3643f1
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Jul 23, 2024
b64c0c7
create paths when writing sync outputs
daniel-sanche Jul 23, 2024
223f337
moved files
daniel-sanche Jul 23, 2024
51d2358
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Jul 23, 2024
3600a63
moved add_mapping into metaclass
daniel-sanche Jul 24, 2024
295f3a2
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Jul 24, 2024
6ce1b5c
fixed mypy issues
daniel-sanche Jul 24, 2024
6ac4c71
ignore unneeded mypy check
daniel-sanche Jul 24, 2024
d76cb5c
add mappings in __init__.py
daniel-sanche Jul 25, 2024
a36f89d
Merge branch 'main' into cross_sync2_pr1_architecture
daniel-sanche Aug 9, 2024
ceabe03
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Aug 13, 2024
e5d6a29
added annotations for execute_query
daniel-sanche Aug 13, 2024
ebf126a
replace all instances in docstrings
daniel-sanche Aug 13, 2024
3d8c79b
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Aug 13, 2024
792abd9
added next to cross_sync
daniel-sanche Aug 30, 2024
1006496
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Aug 30, 2024
5dc231c
moved execute_query e2e tests from system to unit
daniel-sanche Aug 30, 2024
f73498c
ran blacken
daniel-sanche Aug 30, 2024
18854f0
added docstring templating
daniel-sanche Sep 3, 2024
97d63e0
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 3, 2024
5396bc4
use templating in docstrings
daniel-sanche Sep 3, 2024
2dce3b9
added test file for cross sync
daniel-sanche Sep 3, 2024
ade18b1
added some tests
daniel-sanche Sep 4, 2024
933a626
moved wait into aliases
daniel-sanche Sep 5, 2024
8efe71d
stripped out condition_wait
daniel-sanche Sep 5, 2024
09623f4
added tests for event_wait
daniel-sanche Sep 5, 2024
6fcbc89
added tests for create_task
daniel-sanche Sep 5, 2024
9044c4a
added tests for remaining functions
daniel-sanche Sep 5, 2024
ee11e04
added test outline for decorators
daniel-sanche Sep 5, 2024
89c2abe
added tests for ExportSync
daniel-sanche Sep 5, 2024
7925b24
added tests for convert
daniel-sanche Sep 5, 2024
de32f7f
added remaining decorator tests
daniel-sanche Sep 5, 2024
3c0f1de
added mapping tests
daniel-sanche Sep 5, 2024
da38ac4
added e2e test structure for cross_sync
daniel-sanche Sep 5, 2024
169255b
fixed failing nox tests
daniel-sanche Sep 5, 2024
5eddd03
added test cases
daniel-sanche Sep 5, 2024
c616143
added tests
daniel-sanche Sep 5, 2024
042f89b
added cross_sync_methods e2e test cases
daniel-sanche Sep 6, 2024
f186d6b
added tests for class generation
daniel-sanche Sep 6, 2024
7a0c638
moved cross_sync tests into system tests
daniel-sanche Sep 6, 2024
a3cb9a6
fixed lint issues
daniel-sanche Sep 6, 2024
0c91eb7
fixed mypy
daniel-sanche Sep 6, 2024
5484f5e
changed system_emulated version
daniel-sanche Sep 6, 2024
e7881da
fixed system test version format
daniel-sanche Sep 6, 2024
bc67b30
fixed unit-3.7 issues
daniel-sanche Sep 6, 2024
11ab1d0
fixed lint
daniel-sanche Sep 6, 2024
bb9c160
added mutations batcher tests
daniel-sanche Sep 9, 2024
06e0425
batcher uses multuple sync executors
daniel-sanche Sep 9, 2024
288c645
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 9, 2024
13abfd4
implemented wait manually
daniel-sanche Sep 9, 2024
93acd0d
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 9, 2024
1318ab6
fixed order of executor close
daniel-sanche Sep 10, 2024
7dc9a2b
simplified file processing
daniel-sanche Sep 11, 2024
aacd8aa
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 11, 2024
18484a2
updated CrossSync.export statements
daniel-sanche Sep 11, 2024
41576f7
fixed issues in generation
daniel-sanche Sep 11, 2024
7d5df6d
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 11, 2024
0b9f377
fixed lint
daniel-sanche Sep 11, 2024
c8d91c0
fixed underscores in annotations
daniel-sanche Sep 11, 2024
ef00397
fixed string access
daniel-sanche Sep 11, 2024
ea571bd
simplified transformers. Removed CrossSyncMethodHandler
daniel-sanche Sep 12, 2024
e42655b
simplified Convert decorator
daniel-sanche Sep 12, 2024
e972385
fixed 3.7 tests
daniel-sanche Sep 12, 2024
81a06f8
fixed mypy issues
daniel-sanche Sep 12, 2024
db8c156
extract header from code
daniel-sanche Sep 12, 2024
c418af2
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 12, 2024
d0dcbff
fix mock import
daniel-sanche Sep 12, 2024
37c3226
add warning to generated header
daniel-sanche Sep 13, 2024
54ee3be
updated README
daniel-sanche Sep 13, 2024
d44b829
made drop_method into drop, with support for classes
daniel-sanche Sep 13, 2024
61490e5
renamed export into convert_class
daniel-sanche Sep 13, 2024
ea0d5c4
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 13, 2024
b8b2181
use new decorator names
daniel-sanche Sep 13, 2024
a45a6f6
extracted branch trimming into own transformer
daniel-sanche Sep 13, 2024
7052b31
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 13, 2024
dd2a65f
fixed visit to generic visit
daniel-sanche Sep 13, 2024
59a5df2
update transformer value access
daniel-sanche Sep 17, 2024
85f2bfd
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 17, 2024
62d46ec
fixed py37 test
daniel-sanche Sep 17, 2024
487f8b2
generate into _sync_autogen directories
daniel-sanche Sep 17, 2024
77560c9
moved cross_sync directory
daniel-sanche Sep 18, 2024
252ddef
fixed outdated name
daniel-sanche Sep 18, 2024
f34d9a2
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 18, 2024
3c806b5
fixed import path
daniel-sanche Sep 18, 2024
fff417c
fixed import
daniel-sanche Sep 18, 2024
6e71ec9
fixed imports
daniel-sanche Sep 18, 2024
720cf81
fixed import
daniel-sanche Sep 18, 2024
c82d967
moved tests
daniel-sanche Sep 18, 2024
48d44a6
renamed test file
daniel-sanche Sep 18, 2024
7c52d54
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Sep 18, 2024
7f07436
rm_aio in decorator for async
daniel-sanche Sep 27, 2024
8cc4e07
use cross_sync for test proxy
daniel-sanche Sep 27, 2024
20bb81d
fixed test proxy issues
daniel-sanche Sep 27, 2024
14a5f25
renamed with_formatter
daniel-sanche Oct 24, 2024
8830375
fixed docstrings
daniel-sanche Oct 24, 2024
6be8180
cleaning up rm_aio
daniel-sanche Oct 24, 2024
54e3007
accept None as empty string
daniel-sanche Oct 24, 2024
5811a98
use None for empty string
daniel-sanche Oct 24, 2024
480b139
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 24, 2024
66fc807
move _MB_SIZE back to batcher
daniel-sanche Oct 24, 2024
8b3b9c9
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Oct 24, 2024
89a816a
removed rm_aio call annotations
daniel-sanche Oct 25, 2024
c6f053b
fixed broken imports
daniel-sanche Oct 25, 2024
bee3e84
rm_aio at function level by default
daniel-sanche Oct 25, 2024
36c78ba
render to disk by default
daniel-sanche Oct 25, 2024
3c44095
fixed lint
daniel-sanche Oct 25, 2024
9244f56
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Oct 25, 2024
6135ccc
fixed mypy issue
daniel-sanche Oct 25, 2024
ff9d019
fixed unit tests
daniel-sanche Oct 25, 2024
56c76ef
Merge branch 'cross_sync2_pr1_architecture' into cross_sync2_pr2_anno…
daniel-sanche Oct 31, 2024
ae5dc6a
Merge branch 'main' into cross_sync2_pr2_annotations
daniel-sanche Nov 8, 2024
c95ca68
addressing broken tests
daniel-sanche Nov 8, 2024
008e724
fix tests
daniel-sanche Nov 11, 2024
7fb2134
fixed grace_period for sync client
daniel-sanche Nov 11, 2024
e8d122e
fixed lint
daniel-sanche Nov 11, 2024
d489ad3
cleaned up imports
daniel-sanche Nov 12, 2024
39f12f1
moved execute query mapping
daniel-sanche Nov 12, 2024
99dd32a
mock create_channel
daniel-sanche Nov 12, 2024
5a41d24
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 12, 2024
615588d
fixed docstring
daniel-sanche Nov 14, 2024
b28a12e
remove pool size in tests
daniel-sanche Nov 14, 2024
c0abaed
renamed test classes
daniel-sanche Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
matrix:
test-version: [ "v0.0.2" ]
py-version: [ 3.8 ]
client-type: [ "Async v3", "Legacy" ]
client-type: [ "async", "legacy" ]
fail-fast: false
name: "${{ matrix.client-type }} Client / Python ${{ matrix.py-version }} / Test Tag ${{ matrix.test-version }}"
name: "${{ matrix.client-type }} client / python ${{ matrix.py-version }} / test tag ${{ matrix.test-version }}"
steps:
- uses: actions/checkout@v4
name: "Checkout python-bigtable"
Expand Down
3 changes: 1 addition & 2 deletions .kokoro/conformance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ PROXY_ARGS=""
TEST_ARGS=""
if [[ "${CLIENT_TYPE^^}" == "LEGACY" ]]; then
echo "Using legacy client"
PROXY_ARGS="--legacy-client"
# legacy client does not expose mutate_row. Disable those tests
TEST_ARGS="-skip TestMutateRow_"
fi

# Build and start the proxy in a separate process
PROXY_PORT=9999
pushd test_proxy
nohup python test_proxy.py --port $PROXY_PORT $PROXY_ARGS &
nohup python test_proxy.py --port $PROXY_PORT --client_type=$CLIENT_TYPE &
proxyPID=$!
popd

Expand Down
16 changes: 15 additions & 1 deletion google/cloud/bigtable/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,30 @@
from google.cloud.bigtable.data._helpers import RowKeySamples
from google.cloud.bigtable.data._helpers import ShardedQuery

# setup custom CrossSync mappings for library
from google.cloud.bigtable_v2.services.bigtable.async_client import (
BigtableAsyncClient,
)
from google.cloud.bigtable.data._async._read_rows import _ReadRowsOperationAsync
from google.cloud.bigtable.data._async._mutate_rows import _MutateRowsOperationAsync

from google.cloud.bigtable.data._cross_sync import CrossSync

CrossSync.add_mapping("GapicClient", BigtableAsyncClient)
CrossSync.add_mapping("_ReadRowsOperation", _ReadRowsOperationAsync)
CrossSync.add_mapping("_MutateRowsOperation", _MutateRowsOperationAsync)
CrossSync.add_mapping("MutationsBatcher", MutationsBatcherAsync)


__version__: str = package_version.__version__

__all__ = (
"BigtableDataClientAsync",
"TableAsync",
"MutationsBatcherAsync",
"RowKeySamples",
"ReadRowsQuery",
"RowRange",
"MutationsBatcherAsync",
"Mutation",
"RowMutationEntry",
"SetCell",
Expand Down
40 changes: 22 additions & 18 deletions google/cloud/bigtable/data/_async/_mutate_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,38 @@
from __future__ import annotations

from typing import Sequence, TYPE_CHECKING
from dataclasses import dataclass
import functools

from google.api_core import exceptions as core_exceptions
from google.api_core import retry as retries
import google.cloud.bigtable_v2.types.bigtable as types_pb
import google.cloud.bigtable.data.exceptions as bt_exceptions
from google.cloud.bigtable.data._helpers import _attempt_timeout_generator
from google.cloud.bigtable.data._helpers import _retry_exception_factory

# mutate_rows requests are limited to this number of mutations
from google.cloud.bigtable.data.mutations import _MUTATE_ROWS_REQUEST_MUTATION_LIMIT
from google.cloud.bigtable.data.mutations import _EntryWithProto

from google.cloud.bigtable.data._cross_sync import CrossSync

if TYPE_CHECKING:
from google.cloud.bigtable_v2.services.bigtable.async_client import (
BigtableAsyncClient,
)
from google.cloud.bigtable.data.mutations import RowMutationEntry
from google.cloud.bigtable.data._async.client import TableAsync


@dataclass
class _EntryWithProto:
"""
A dataclass to hold a RowMutationEntry and its corresponding proto representation.
"""
if CrossSync.is_async:
from google.cloud.bigtable_v2.services.bigtable.async_client import (
BigtableAsyncClient as GapicClientType,
)
from google.cloud.bigtable.data._async.client import TableAsync as TableType
else:
from google.cloud.bigtable_v2.services.bigtable.client import ( # type: ignore
BigtableClient as GapicClientType,
)
from google.cloud.bigtable.data._sync_autogen.client import Table as TableType # type: ignore

entry: RowMutationEntry
proto: types_pb.MutateRowsRequest.Entry
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._mutate_rows"


@CrossSync.convert_class("_MutateRowsOperation")
class _MutateRowsOperationAsync:
"""
MutateRowsOperation manages the logic of sending a set of row mutations,
Expand All @@ -65,10 +66,11 @@ class _MutateRowsOperationAsync:
If not specified, the request will run until operation_timeout is reached.
"""

@CrossSync.convert
def __init__(
self,
gapic_client: "BigtableAsyncClient",
table: "TableAsync",
gapic_client: GapicClientType,
table: TableType,
mutation_entries: list["RowMutationEntry"],
operation_timeout: float,
attempt_timeout: float | None,
Expand Down Expand Up @@ -97,7 +99,7 @@ def __init__(
bt_exceptions._MutateRowsIncomplete,
)
sleep_generator = retries.exponential_sleep_generator(0.01, 2, 60)
self._operation = retries.retry_target_async(
self._operation = lambda: CrossSync.retry_target(
self._run_attempt,
self.is_retryable,
sleep_generator,
Expand All @@ -112,6 +114,7 @@ def __init__(
self.remaining_indices = list(range(len(self.mutations)))
self.errors: dict[int, list[Exception]] = {}

@CrossSync.convert
async def start(self):
"""
Start the operation, and run until completion
Expand All @@ -121,7 +124,7 @@ async def start(self):
"""
try:
# trigger mutate_rows
await self._operation
await self._operation()
except Exception as exc:
# exceptions raised by retryable are added to the list of exceptions for all unfinalized mutations
incomplete_indices = self.remaining_indices.copy()
Expand All @@ -148,6 +151,7 @@ async def start(self):
all_errors, len(self.mutations)
)

@CrossSync.convert
async def _run_attempt(self):
"""
Run a single attempt of the mutate_rows rpc.
Expand Down
46 changes: 24 additions & 22 deletions google/cloud/bigtable/data/_async/_read_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

from __future__ import annotations

from typing import (
TYPE_CHECKING,
AsyncGenerator,
AsyncIterable,
Awaitable,
Sequence,
)
from typing import Sequence, TYPE_CHECKING

from google.cloud.bigtable_v2.types import ReadRowsRequest as ReadRowsRequestPB
from google.cloud.bigtable_v2.types import ReadRowsResponse as ReadRowsResponsePB
Expand All @@ -32,21 +26,25 @@
from google.cloud.bigtable.data.read_rows_query import ReadRowsQuery
from google.cloud.bigtable.data.exceptions import InvalidChunk
from google.cloud.bigtable.data.exceptions import _RowSetComplete
from google.cloud.bigtable.data.exceptions import _ResetRow
from google.cloud.bigtable.data._helpers import _attempt_timeout_generator
from google.cloud.bigtable.data._helpers import _retry_exception_factory

from google.api_core import retry as retries
from google.api_core.retry import exponential_sleep_generator

if TYPE_CHECKING:
from google.cloud.bigtable.data._async.client import TableAsync
from google.cloud.bigtable.data._cross_sync import CrossSync

if TYPE_CHECKING:
if CrossSync.is_async:
from google.cloud.bigtable.data._async.client import TableAsync as TableType
else:
from google.cloud.bigtable.data._sync_autogen.client import Table as TableType # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dumb question.. isn't _sync_autogen.client also generated from cross sync? how can we import a not yet generated class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point, this should really just be in the next PR, since the file doesn't exist yet

For the "how" part: this import statement isn't actually executed, since it's behind an if False branch. This import is just for the generated file


class _ResetRow(Exception):
def __init__(self, chunk):
self.chunk = chunk
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._read_rows"


@CrossSync.convert_class("_ReadRowsOperation")
class _ReadRowsOperationAsync:
"""
ReadRowsOperation handles the logic of merging chunks from a ReadRowsResponse stream
Expand Down Expand Up @@ -80,7 +78,7 @@ class _ReadRowsOperationAsync:
def __init__(
self,
query: ReadRowsQuery,
table: "TableAsync",
table: TableType,
operation_timeout: float,
attempt_timeout: float,
retryable_exceptions: Sequence[type[Exception]] = (),
Expand All @@ -102,22 +100,22 @@ def __init__(
self._last_yielded_row_key: bytes | None = None
self._remaining_count: int | None = self.request.rows_limit or None

def start_operation(self) -> AsyncGenerator[Row, None]:
def start_operation(self) -> CrossSync.Iterable[Row]:
"""
Start the read_rows operation, retrying on retryable errors.

Yields:
Row: The next row in the stream
"""
return retries.retry_target_stream_async(
return CrossSync.retry_target_stream(
self._read_rows_attempt,
self._predicate,
exponential_sleep_generator(0.01, 60, multiplier=2),
self.operation_timeout,
exception_factory=_retry_exception_factory,
)

def _read_rows_attempt(self) -> AsyncGenerator[Row, None]:
def _read_rows_attempt(self) -> CrossSync.Iterable[Row]:
"""
Attempt a single read_rows rpc call.
This function is intended to be wrapped by retry logic,
Expand Down Expand Up @@ -152,9 +150,10 @@ def _read_rows_attempt(self) -> AsyncGenerator[Row, None]:
chunked_stream = self.chunk_stream(gapic_stream)
return self.merge_rows(chunked_stream)

@CrossSync.convert()
async def chunk_stream(
self, stream: Awaitable[AsyncIterable[ReadRowsResponsePB]]
) -> AsyncGenerator[ReadRowsResponsePB.CellChunk, None]:
self, stream: CrossSync.Awaitable[CrossSync.Iterable[ReadRowsResponsePB]]
) -> CrossSync.Iterable[ReadRowsResponsePB.CellChunk]:
"""
process chunks out of raw read_rows stream

Expand Down Expand Up @@ -204,9 +203,12 @@ async def chunk_stream(
current_key = None

@staticmethod
@CrossSync.convert(
replace_symbols={"__aiter__": "__iter__", "__anext__": "__next__"},
)
async def merge_rows(
chunks: AsyncGenerator[ReadRowsResponsePB.CellChunk, None] | None
) -> AsyncGenerator[Row, None]:
chunks: CrossSync.Iterable[ReadRowsResponsePB.CellChunk] | None,
) -> CrossSync.Iterable[Row]:
"""
Merge chunks into rows

Expand All @@ -222,7 +224,7 @@ async def merge_rows(
while True:
try:
c = await it.__anext__()
except StopAsyncIteration:
except CrossSync.StopIteration:
# stream complete
return
row_key = c.row_key
Expand Down Expand Up @@ -315,7 +317,7 @@ async def merge_rows(
):
raise InvalidChunk("reset row with data")
continue
except StopAsyncIteration:
except CrossSync.StopIteration:
raise InvalidChunk("premature end of stream")

@staticmethod
Expand Down
Loading
Loading