Skip to content

Commit 83adb1e

Browse files
yoshi-automationbusunkim96larkee
authored
chore: add RequestOptions proto; add optimizer_statistics_package to QueryOptions (#288)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * chore: update gapic-generator-python to 0.40.11 PiperOrigin-RevId: 359562873 Source-Author: Google APIs <[email protected]> Source-Date: Thu Feb 25 10:52:32 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 07932bb995e7dc91b43620ea8402c6668c7d102c Source-Link: googleapis/googleapis@07932bb * feat(spanner): add `optimizer_statistics_package` field in `QueryOptions` PiperOrigin-RevId: 360758638 Source-Author: Google APIs <[email protected]> Source-Date: Wed Mar 3 14:32:33 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: dff6e4625d4ea0a16fc44d3b9be115219c403f07 Source-Link: googleapis/googleapis@dff6e46 * chore: upgrade gapic-generator-python to 0.42.2 PiperOrigin-RevId: 361662015 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 8 14:47:18 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 28a591963253d52ce3a25a918cafbdd9928de8cf Source-Link: googleapis/googleapis@28a5919 * chore: upgrade gapic-generator-python to 0.43.1 PiperOrigin-RevId: 364411656 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 14:40:22 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 149a3a84c29c9b8189576c7442ccb6dcf6a8f95b Source-Link: googleapis/googleapis@149a3a8 * feat: add RPC Priority request options PiperOrigin-RevId: 364449524 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 17:39:37 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 6598bb829c9e9a534be674649ffd1b4671a821f9 Source-Link: googleapis/googleapis@6598bb8 * feat: add tagging request options PiperOrigin-RevId: 365498709 Source-Author: Google APIs <[email protected]> Source-Date: Sun Mar 28 20:54:25 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 6ce40ff8faf68226782f507ca6b2d497a77044de Source-Link: googleapis/googleapis@6ce40ff * fix: fix dependencies * chore: revert changes taht break tests * style: fix lint Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: larkee <[email protected]>
1 parent 7ae8e0b commit 83adb1e

File tree

39 files changed

+1601
-623
lines changed

39 files changed

+1601
-623
lines changed

UPGRADING.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ limitations under the License.
1414

1515
# 2.0.0 Migration Guide
1616

17-
The 2.0 release of the `google-cloud-spanner` client is a significant update based on a
17+
The 2.0 release of the `google-cloud-spanner` client is a significant update based on a
1818
[next-gen code generator](https://github.com/googleapis/gapic-generator-python).
19-
It drops support for Python versions below 3.6.
19+
It drops support for Python versions below 3.6.
2020

2121
The handwritten client surfaces have minor changes which may require minimal updates to existing user code.
2222

23-
The generated client surfaces have substantial interface changes. Existing user code which uses these surfaces directly
23+
The generated client surfaces have substantial interface changes. Existing user code which uses these surfaces directly
2424
will require significant updates to use this version.
2525

2626
This document describes the changes that have been made, and what you need to do to update your usage.
@@ -89,7 +89,7 @@ for database_pb in instance.list_databases():
8989
> **WARNING**: Breaking change
9090
9191
The library now handles pages for the user. Previously, the library would return a page generator which required a user
92-
to then iterate over each page to get the resource. Now, the library handles iterating over the pages and only returns
92+
to then iterate over each page to get the resource. Now, the library handles iterating over the pages and only returns
9393
the resource protos.
9494

9595
**Before:**
@@ -176,14 +176,14 @@ for database_pb in instance.list_databases():
176176
177177
Methods expect request objects. We provide scripts that will convert most common use cases.
178178

179-
* Install the library
179+
* Install the library with `libcst`.
180180

181181
```py
182-
python3 -m pip install google-cloud-spanner
182+
python3 -m pip install google-cloud-spanner[libcst]
183183
```
184184

185185
* The scripts `fixup_spanner_v1_keywords.py`, `fixup_spanner_admin_database_v1_keywords.py`, and
186-
`fixup_spanner_admin_instance_v1_keywords.py` are shipped with the library. They expect an input directory (with the
186+
`fixup_spanner_admin_instance_v1_keywords.py` are shipped with the library. They expect an input directory (with the
187187
code to convert) and an empty destination directory.
188188

189189
```sh
@@ -194,10 +194,10 @@ $ fixup_spanner_v1_keywords.py --input-directory .samples/ --output-directory sa
194194
>the handwritten surfaces e.g. `client.list_instances()`
195195
196196
#### More details
197-
197+
198198
In `google-cloud-spanner<2.0.0`, parameters required by the API were positional parameters and optional parameters were
199199
keyword parameters.
200-
200+
201201
**Before:**
202202
```py
203203
def list_instances(
@@ -210,14 +210,14 @@ def list_instances(
210210
metadata=None,
211211
):
212212
```
213-
214-
In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a
213+
214+
In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a
215215
parameter is required or optional.
216-
217-
Some methods have additional keyword only parameters. The available parameters depend on the
216+
217+
Some methods have additional keyword only parameters. The available parameters depend on the
218218
[`google.api.method_signature` annotation](https://github.com/googleapis/googleapis/blob/master/google/spanner/admin/instance/v1/spanner_instance_admin.proto#L86) specified by the API producer.
219-
220-
219+
220+
221221
**After:**
222222
```py
223223
def list_instances(
@@ -230,30 +230,30 @@ def list_instances(
230230
metadata: Sequence[Tuple[str, str]] = (),
231231
) -> pagers.ListInstancesPager:
232232
```
233-
233+
234234
> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
235235
> Passing both will result in an error.
236-
237-
236+
237+
238238
Both of these calls are valid:
239-
239+
240240
```py
241241
response = client.list_instances(
242242
request={
243243
"parent": project_name,
244244
}
245245
)
246246
```
247-
247+
248248
```py
249249
response = client.execute_sql(
250250
parent=project_name,
251251
)
252252
```
253-
253+
254254
This call is invalid because it mixes `request` with a keyword argument `parent`. Executing this code
255255
will result in an error.
256-
256+
257257
```py
258258
response = client.execute_sql(
259259
request={},

google/cloud/spanner_admin_database_v1/proto/spanner_database_admin.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ message RestoreDatabaseRequest {
736736
// to. If this field is not specified, the restored database will use the same
737737
// encryption configuration as the backup by default, namely
738738
// [encryption_type][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig.encryption_type]
739-
// = `USE_CONFIG_DEFAULT_OR_DATABASE_ENCRYPTION`.
739+
// = `USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION`.
740740
RestoreDatabaseEncryptionConfig encryption_config = 4
741741
[(google.api.field_behavior) = OPTIONAL];
742742
}

google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,36 @@ class DatabaseAdminAsyncClient:
103103
DatabaseAdminClient.parse_common_location_path
104104
)
105105

106-
from_service_account_info = DatabaseAdminClient.from_service_account_info
107-
from_service_account_file = DatabaseAdminClient.from_service_account_file
106+
@classmethod
107+
def from_service_account_info(cls, info: dict, *args, **kwargs):
108+
"""Creates an instance of this client using the provided credentials info.
109+
110+
Args:
111+
info (dict): The service account private key info.
112+
args: Additional arguments to pass to the constructor.
113+
kwargs: Additional arguments to pass to the constructor.
114+
115+
Returns:
116+
DatabaseAdminAsyncClient: The constructed client.
117+
"""
118+
return DatabaseAdminClient.from_service_account_info.__func__(DatabaseAdminAsyncClient, info, *args, **kwargs) # type: ignore
119+
120+
@classmethod
121+
def from_service_account_file(cls, filename: str, *args, **kwargs):
122+
"""Creates an instance of this client using the provided credentials
123+
file.
124+
125+
Args:
126+
filename (str): The path to the service account private key json
127+
file.
128+
args: Additional arguments to pass to the constructor.
129+
kwargs: Additional arguments to pass to the constructor.
130+
131+
Returns:
132+
DatabaseAdminAsyncClient: The constructed client.
133+
"""
134+
return DatabaseAdminClient.from_service_account_file.__func__(DatabaseAdminAsyncClient, filename, *args, **kwargs) # type: ignore
135+
108136
from_service_account_json = from_service_account_file
109137

110138
@property
@@ -236,6 +264,7 @@ async def list_databases(
236264
predicate=retries.if_exception_type(
237265
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
238266
),
267+
deadline=3600.0,
239268
),
240269
default_timeout=3600.0,
241270
client_info=DEFAULT_CLIENT_INFO,
@@ -431,6 +460,7 @@ async def get_database(
431460
predicate=retries.if_exception_type(
432461
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
433462
),
463+
deadline=3600.0,
434464
),
435465
default_timeout=3600.0,
436466
client_info=DEFAULT_CLIENT_INFO,
@@ -559,6 +589,7 @@ async def update_database_ddl(
559589
predicate=retries.if_exception_type(
560590
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
561591
),
592+
deadline=3600.0,
562593
),
563594
default_timeout=3600.0,
564595
client_info=DEFAULT_CLIENT_INFO,
@@ -642,6 +673,7 @@ async def drop_database(
642673
predicate=retries.if_exception_type(
643674
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
644675
),
676+
deadline=3600.0,
645677
),
646678
default_timeout=3600.0,
647679
client_info=DEFAULT_CLIENT_INFO,
@@ -726,6 +758,7 @@ async def get_database_ddl(
726758
predicate=retries.if_exception_type(
727759
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
728760
),
761+
deadline=3600.0,
729762
),
730763
default_timeout=3600.0,
731764
client_info=DEFAULT_CLIENT_INFO,
@@ -1007,6 +1040,7 @@ async def get_iam_policy(
10071040
predicate=retries.if_exception_type(
10081041
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
10091042
),
1043+
deadline=30.0,
10101044
),
10111045
default_timeout=30.0,
10121046
client_info=DEFAULT_CLIENT_INFO,
@@ -1302,6 +1336,7 @@ async def get_backup(
13021336
predicate=retries.if_exception_type(
13031337
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
13041338
),
1339+
deadline=3600.0,
13051340
),
13061341
default_timeout=3600.0,
13071342
client_info=DEFAULT_CLIENT_INFO,
@@ -1402,6 +1437,7 @@ async def update_backup(
14021437
predicate=retries.if_exception_type(
14031438
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
14041439
),
1440+
deadline=3600.0,
14051441
),
14061442
default_timeout=3600.0,
14071443
client_info=DEFAULT_CLIENT_INFO,
@@ -1481,6 +1517,7 @@ async def delete_backup(
14811517
predicate=retries.if_exception_type(
14821518
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
14831519
),
1520+
deadline=3600.0,
14841521
),
14851522
default_timeout=3600.0,
14861523
client_info=DEFAULT_CLIENT_INFO,
@@ -1566,6 +1603,7 @@ async def list_backups(
15661603
predicate=retries.if_exception_type(
15671604
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
15681605
),
1606+
deadline=3600.0,
15691607
),
15701608
default_timeout=3600.0,
15711609
client_info=DEFAULT_CLIENT_INFO,
@@ -1795,6 +1833,7 @@ async def list_database_operations(
17951833
predicate=retries.if_exception_type(
17961834
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
17971835
),
1836+
deadline=3600.0,
17981837
),
17991838
default_timeout=3600.0,
18001839
client_info=DEFAULT_CLIENT_INFO,
@@ -1897,6 +1936,7 @@ async def list_backup_operations(
18971936
predicate=retries.if_exception_type(
18981937
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
18991938
),
1939+
deadline=3600.0,
19001940
),
19011941
default_timeout=3600.0,
19021942
client_info=DEFAULT_CLIENT_INFO,

google/cloud/spanner_admin_database_v1/services/database_admin/client.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,10 @@ def set_iam_policy(
10821082
"the individual field arguments should be set."
10831083
)
10841084

1085-
# The request isn't a proto-plus wrapped type,
1086-
# so it must be constructed via keyword expansion.
10871085
if isinstance(request, dict):
1086+
# The request isn't a proto-plus wrapped type,
1087+
# so it must be constructed via keyword expansion.
10881088
request = iam_policy.SetIamPolicyRequest(**request)
1089-
10901089
elif not request:
10911090
# Null request, just make one.
10921091
request = iam_policy.SetIamPolicyRequest()
@@ -1219,11 +1218,10 @@ def get_iam_policy(
12191218
"the individual field arguments should be set."
12201219
)
12211220

1222-
# The request isn't a proto-plus wrapped type,
1223-
# so it must be constructed via keyword expansion.
12241221
if isinstance(request, dict):
1222+
# The request isn't a proto-plus wrapped type,
1223+
# so it must be constructed via keyword expansion.
12251224
request = iam_policy.GetIamPolicyRequest(**request)
1226-
12271225
elif not request:
12281226
# Null request, just make one.
12291227
request = iam_policy.GetIamPolicyRequest()
@@ -1311,11 +1309,10 @@ def test_iam_permissions(
13111309
"the individual field arguments should be set."
13121310
)
13131311

1314-
# The request isn't a proto-plus wrapped type,
1315-
# so it must be constructed via keyword expansion.
13161312
if isinstance(request, dict):
1313+
# The request isn't a proto-plus wrapped type,
1314+
# so it must be constructed via keyword expansion.
13171315
request = iam_policy.TestIamPermissionsRequest(**request)
1318-
13191316
elif not request:
13201317
# Null request, just make one.
13211318
request = iam_policy.TestIamPermissionsRequest()

0 commit comments

Comments
 (0)