google-cloud-spanner 3.55.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. google/cloud/spanner.py +47 -0
  2. google/cloud/spanner_admin_database_v1/__init__.py +146 -0
  3. google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
  4. google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
  5. google/cloud/spanner_admin_database_v1/py.typed +2 -0
  6. google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
  7. google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
  8. google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
  9. google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
  10. google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
  11. google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
  12. google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
  13. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
  14. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
  15. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
  16. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
  17. google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
  18. google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
  19. google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
  20. google/cloud/spanner_admin_database_v1/types/common.py +180 -0
  21. google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
  22. google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
  23. google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
  24. google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
  25. google/cloud/spanner_admin_instance_v1/py.typed +2 -0
  26. google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
  27. google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
  28. google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
  29. google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
  30. google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
  31. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
  32. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
  33. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
  34. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
  35. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
  36. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
  37. google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
  38. google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
  39. google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
  40. google/cloud/spanner_dbapi/__init__.py +93 -0
  41. google/cloud/spanner_dbapi/_helpers.py +113 -0
  42. google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
  43. google/cloud/spanner_dbapi/checksum.py +80 -0
  44. google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
  45. google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
  46. google/cloud/spanner_dbapi/connection.py +818 -0
  47. google/cloud/spanner_dbapi/cursor.py +609 -0
  48. google/cloud/spanner_dbapi/exceptions.py +172 -0
  49. google/cloud/spanner_dbapi/parse_utils.py +392 -0
  50. google/cloud/spanner_dbapi/parsed_statement.py +63 -0
  51. google/cloud/spanner_dbapi/parser.py +258 -0
  52. google/cloud/spanner_dbapi/partition_helper.py +41 -0
  53. google/cloud/spanner_dbapi/transaction_helper.py +294 -0
  54. google/cloud/spanner_dbapi/types.py +106 -0
  55. google/cloud/spanner_dbapi/utils.py +147 -0
  56. google/cloud/spanner_dbapi/version.py +20 -0
  57. google/cloud/spanner_v1/__init__.py +154 -0
  58. google/cloud/spanner_v1/_helpers.py +751 -0
  59. google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
  60. google/cloud/spanner_v1/backup.py +397 -0
  61. google/cloud/spanner_v1/batch.py +433 -0
  62. google/cloud/spanner_v1/client.py +538 -0
  63. google/cloud/spanner_v1/data_types.py +350 -0
  64. google/cloud/spanner_v1/database.py +1968 -0
  65. google/cloud/spanner_v1/database_sessions_manager.py +249 -0
  66. google/cloud/spanner_v1/gapic_metadata.json +268 -0
  67. google/cloud/spanner_v1/gapic_version.py +16 -0
  68. google/cloud/spanner_v1/instance.py +735 -0
  69. google/cloud/spanner_v1/keyset.py +193 -0
  70. google/cloud/spanner_v1/merged_result_set.py +146 -0
  71. google/cloud/spanner_v1/metrics/constants.py +71 -0
  72. google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
  73. google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
  74. google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
  75. google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
  76. google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
  77. google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
  78. google/cloud/spanner_v1/param_types.py +110 -0
  79. google/cloud/spanner_v1/pool.py +813 -0
  80. google/cloud/spanner_v1/py.typed +2 -0
  81. google/cloud/spanner_v1/request_id_header.py +64 -0
  82. google/cloud/spanner_v1/services/__init__.py +15 -0
  83. google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
  84. google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
  85. google/cloud/spanner_v1/services/spanner/client.py +2624 -0
  86. google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
  87. google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
  88. google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
  89. google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
  90. google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
  91. google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
  92. google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
  93. google/cloud/spanner_v1/session.py +631 -0
  94. google/cloud/spanner_v1/session_options.py +133 -0
  95. google/cloud/spanner_v1/snapshot.py +1057 -0
  96. google/cloud/spanner_v1/streamed.py +402 -0
  97. google/cloud/spanner_v1/table.py +181 -0
  98. google/cloud/spanner_v1/testing/__init__.py +0 -0
  99. google/cloud/spanner_v1/testing/database_test.py +121 -0
  100. google/cloud/spanner_v1/testing/interceptors.py +118 -0
  101. google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
  102. google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
  103. google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
  104. google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
  105. google/cloud/spanner_v1/transaction.py +747 -0
  106. google/cloud/spanner_v1/types/__init__.py +118 -0
  107. google/cloud/spanner_v1/types/commit_response.py +94 -0
  108. google/cloud/spanner_v1/types/keys.py +248 -0
  109. google/cloud/spanner_v1/types/mutation.py +201 -0
  110. google/cloud/spanner_v1/types/query_plan.py +220 -0
  111. google/cloud/spanner_v1/types/result_set.py +379 -0
  112. google/cloud/spanner_v1/types/spanner.py +1815 -0
  113. google/cloud/spanner_v1/types/transaction.py +818 -0
  114. google/cloud/spanner_v1/types/type.py +288 -0
  115. google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
  116. google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
  117. google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
  118. google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
  119. google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,818 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2025 Google LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ from __future__ import annotations
17
+
18
+ from typing import MutableMapping, MutableSequence
19
+
20
+ import proto # type: ignore
21
+
22
+ from google.protobuf import duration_pb2 # type: ignore
23
+ from google.protobuf import timestamp_pb2 # type: ignore
24
+
25
+
26
+ __protobuf__ = proto.module(
27
+ package="google.spanner.v1",
28
+ manifest={
29
+ "TransactionOptions",
30
+ "Transaction",
31
+ "TransactionSelector",
32
+ "MultiplexedSessionPrecommitToken",
33
+ },
34
+ )
35
+
36
+
37
+ class TransactionOptions(proto.Message):
38
+ r"""Transactions:
39
+
40
+ Each session can have at most one active transaction at a time (note
41
+ that standalone reads and queries use a transaction internally and
42
+ do count towards the one transaction limit). After the active
43
+ transaction is completed, the session can immediately be re-used for
44
+ the next transaction. It is not necessary to create a new session
45
+ for each transaction.
46
+
47
+ Transaction modes:
48
+
49
+ Cloud Spanner supports three transaction modes:
50
+
51
+ 1. Locking read-write. This type of transaction is the only way to
52
+ write data into Cloud Spanner. These transactions rely on
53
+ pessimistic locking and, if necessary, two-phase commit. Locking
54
+ read-write transactions may abort, requiring the application to
55
+ retry.
56
+
57
+ 2. Snapshot read-only. Snapshot read-only transactions provide
58
+ guaranteed consistency across several reads, but do not allow
59
+ writes. Snapshot read-only transactions can be configured to read
60
+ at timestamps in the past, or configured to perform a strong read
61
+ (where Spanner will select a timestamp such that the read is
62
+ guaranteed to see the effects of all transactions that have
63
+ committed before the start of the read). Snapshot read-only
64
+ transactions do not need to be committed.
65
+
66
+ Queries on change streams must be performed with the snapshot
67
+ read-only transaction mode, specifying a strong read. Please see
68
+ [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong]
69
+ for more details.
70
+
71
+ 3. Partitioned DML. This type of transaction is used to execute a
72
+ single Partitioned DML statement. Partitioned DML partitions the
73
+ key space and runs the DML statement over each partition in
74
+ parallel using separate, internal transactions that commit
75
+ independently. Partitioned DML transactions do not need to be
76
+ committed.
77
+
78
+ For transactions that only read, snapshot read-only transactions
79
+ provide simpler semantics and are almost always faster. In
80
+ particular, read-only transactions do not take locks, so they do not
81
+ conflict with read-write transactions. As a consequence of not
82
+ taking locks, they also do not abort, so retry loops are not needed.
83
+
84
+ Transactions may only read-write data in a single database. They
85
+ may, however, read-write data in different tables within that
86
+ database.
87
+
88
+ Locking read-write transactions:
89
+
90
+ Locking transactions may be used to atomically read-modify-write
91
+ data anywhere in a database. This type of transaction is externally
92
+ consistent.
93
+
94
+ Clients should attempt to minimize the amount of time a transaction
95
+ is active. Faster transactions commit with higher probability and
96
+ cause less contention. Cloud Spanner attempts to keep read locks
97
+ active as long as the transaction continues to do reads, and the
98
+ transaction has not been terminated by
99
+ [Commit][google.spanner.v1.Spanner.Commit] or
100
+ [Rollback][google.spanner.v1.Spanner.Rollback]. Long periods of
101
+ inactivity at the client may cause Cloud Spanner to release a
102
+ transaction's locks and abort it.
103
+
104
+ Conceptually, a read-write transaction consists of zero or more
105
+ reads or SQL statements followed by
106
+ [Commit][google.spanner.v1.Spanner.Commit]. At any time before
107
+ [Commit][google.spanner.v1.Spanner.Commit], the client can send a
108
+ [Rollback][google.spanner.v1.Spanner.Rollback] request to abort the
109
+ transaction.
110
+
111
+ Semantics:
112
+
113
+ Cloud Spanner can commit the transaction if all read locks it
114
+ acquired are still valid at commit time, and it is able to acquire
115
+ write locks for all writes. Cloud Spanner can abort the transaction
116
+ for any reason. If a commit attempt returns ``ABORTED``, Cloud
117
+ Spanner guarantees that the transaction has not modified any user
118
+ data in Cloud Spanner.
119
+
120
+ Unless the transaction commits, Cloud Spanner makes no guarantees
121
+ about how long the transaction's locks were held for. It is an error
122
+ to use Cloud Spanner locks for any sort of mutual exclusion other
123
+ than between Cloud Spanner transactions themselves.
124
+
125
+ Retrying aborted transactions:
126
+
127
+ When a transaction aborts, the application can choose to retry the
128
+ whole transaction again. To maximize the chances of successfully
129
+ committing the retry, the client should execute the retry in the
130
+ same session as the original attempt. The original session's lock
131
+ priority increases with each consecutive abort, meaning that each
132
+ attempt has a slightly better chance of success than the previous.
133
+
134
+ Under some circumstances (for example, many transactions attempting
135
+ to modify the same row(s)), a transaction can abort many times in a
136
+ short period before successfully committing. Thus, it is not a good
137
+ idea to cap the number of retries a transaction can attempt;
138
+ instead, it is better to limit the total amount of time spent
139
+ retrying.
140
+
141
+ Idle transactions:
142
+
143
+ A transaction is considered idle if it has no outstanding reads or
144
+ SQL queries and has not started a read or SQL query within the last
145
+ 10 seconds. Idle transactions can be aborted by Cloud Spanner so
146
+ that they don't hold on to locks indefinitely. If an idle
147
+ transaction is aborted, the commit will fail with error ``ABORTED``.
148
+
149
+ If this behavior is undesirable, periodically executing a simple SQL
150
+ query in the transaction (for example, ``SELECT 1``) prevents the
151
+ transaction from becoming idle.
152
+
153
+ Snapshot read-only transactions:
154
+
155
+ Snapshot read-only transactions provides a simpler method than
156
+ locking read-write transactions for doing several consistent reads.
157
+ However, this type of transaction does not support writes.
158
+
159
+ Snapshot transactions do not take locks. Instead, they work by
160
+ choosing a Cloud Spanner timestamp, then executing all reads at that
161
+ timestamp. Since they do not acquire locks, they do not block
162
+ concurrent read-write transactions.
163
+
164
+ Unlike locking read-write transactions, snapshot read-only
165
+ transactions never abort. They can fail if the chosen read timestamp
166
+ is garbage collected; however, the default garbage collection policy
167
+ is generous enough that most applications do not need to worry about
168
+ this in practice.
169
+
170
+ Snapshot read-only transactions do not need to call
171
+ [Commit][google.spanner.v1.Spanner.Commit] or
172
+ [Rollback][google.spanner.v1.Spanner.Rollback] (and in fact are not
173
+ permitted to do so).
174
+
175
+ To execute a snapshot transaction, the client specifies a timestamp
176
+ bound, which tells Cloud Spanner how to choose a read timestamp.
177
+
178
+ The types of timestamp bound are:
179
+
180
+ - Strong (the default).
181
+ - Bounded staleness.
182
+ - Exact staleness.
183
+
184
+ If the Cloud Spanner database to be read is geographically
185
+ distributed, stale read-only transactions can execute more quickly
186
+ than strong or read-write transactions, because they are able to
187
+ execute far from the leader replica.
188
+
189
+ Each type of timestamp bound is discussed in detail below.
190
+
191
+ Strong: Strong reads are guaranteed to see the effects of all
192
+ transactions that have committed before the start of the read.
193
+ Furthermore, all rows yielded by a single read are consistent with
194
+ each other -- if any part of the read observes a transaction, all
195
+ parts of the read see the transaction.
196
+
197
+ Strong reads are not repeatable: two consecutive strong read-only
198
+ transactions might return inconsistent results if there are
199
+ concurrent writes. If consistency across reads is required, the
200
+ reads should be executed within a transaction or at an exact read
201
+ timestamp.
202
+
203
+ Queries on change streams (see below for more details) must also
204
+ specify the strong read timestamp bound.
205
+
206
+ See
207
+ [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong].
208
+
209
+ Exact staleness:
210
+
211
+ These timestamp bounds execute reads at a user-specified timestamp.
212
+ Reads at a timestamp are guaranteed to see a consistent prefix of
213
+ the global transaction history: they observe modifications done by
214
+ all transactions with a commit timestamp less than or equal to the
215
+ read timestamp, and observe none of the modifications done by
216
+ transactions with a larger commit timestamp. They will block until
217
+ all conflicting transactions that may be assigned commit timestamps
218
+ <= the read timestamp have finished.
219
+
220
+ The timestamp can either be expressed as an absolute Cloud Spanner
221
+ commit timestamp or a staleness relative to the current time.
222
+
223
+ These modes do not require a "negotiation phase" to pick a
224
+ timestamp. As a result, they execute slightly faster than the
225
+ equivalent boundedly stale concurrency modes. On the other hand,
226
+ boundedly stale reads usually return fresher results.
227
+
228
+ See
229
+ [TransactionOptions.ReadOnly.read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.read_timestamp]
230
+ and
231
+ [TransactionOptions.ReadOnly.exact_staleness][google.spanner.v1.TransactionOptions.ReadOnly.exact_staleness].
232
+
233
+ Bounded staleness:
234
+
235
+ Bounded staleness modes allow Cloud Spanner to pick the read
236
+ timestamp, subject to a user-provided staleness bound. Cloud Spanner
237
+ chooses the newest timestamp within the staleness bound that allows
238
+ execution of the reads at the closest available replica without
239
+ blocking.
240
+
241
+ All rows yielded are consistent with each other -- if any part of
242
+ the read observes a transaction, all parts of the read see the
243
+ transaction. Boundedly stale reads are not repeatable: two stale
244
+ reads, even if they use the same staleness bound, can execute at
245
+ different timestamps and thus return inconsistent results.
246
+
247
+ Boundedly stale reads execute in two phases: the first phase
248
+ negotiates a timestamp among all replicas needed to serve the read.
249
+ In the second phase, reads are executed at the negotiated timestamp.
250
+
251
+ As a result of the two phase execution, bounded staleness reads are
252
+ usually a little slower than comparable exact staleness reads.
253
+ However, they are typically able to return fresher results, and are
254
+ more likely to execute at the closest replica.
255
+
256
+ Because the timestamp negotiation requires up-front knowledge of
257
+ which rows will be read, it can only be used with single-use
258
+ read-only transactions.
259
+
260
+ See
261
+ [TransactionOptions.ReadOnly.max_staleness][google.spanner.v1.TransactionOptions.ReadOnly.max_staleness]
262
+ and
263
+ [TransactionOptions.ReadOnly.min_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.min_read_timestamp].
264
+
265
+ Old read timestamps and garbage collection:
266
+
267
+ Cloud Spanner continuously garbage collects deleted and overwritten
268
+ data in the background to reclaim storage space. This process is
269
+ known as "version GC". By default, version GC reclaims versions
270
+ after they are one hour old. Because of this, Cloud Spanner cannot
271
+ perform reads at read timestamps more than one hour in the past.
272
+ This restriction also applies to in-progress reads and/or SQL
273
+ queries whose timestamp become too old while executing. Reads and
274
+ SQL queries with too-old read timestamps fail with the error
275
+ ``FAILED_PRECONDITION``.
276
+
277
+ You can configure and extend the ``VERSION_RETENTION_PERIOD`` of a
278
+ database up to a period as long as one week, which allows Cloud
279
+ Spanner to perform reads up to one week in the past.
280
+
281
+ Querying change Streams:
282
+
283
+ A Change Stream is a schema object that can be configured to watch
284
+ data changes on the entire database, a set of tables, or a set of
285
+ columns in a database.
286
+
287
+ When a change stream is created, Spanner automatically defines a
288
+ corresponding SQL Table-Valued Function (TVF) that can be used to
289
+ query the change records in the associated change stream using the
290
+ ExecuteStreamingSql API. The name of the TVF for a change stream is
291
+ generated from the name of the change stream:
292
+ READ_<change_stream_name>.
293
+
294
+ All queries on change stream TVFs must be executed using the
295
+ ExecuteStreamingSql API with a single-use read-only transaction with
296
+ a strong read-only timestamp_bound. The change stream TVF allows
297
+ users to specify the start_timestamp and end_timestamp for the time
298
+ range of interest. All change records within the retention period is
299
+ accessible using the strong read-only timestamp_bound. All other
300
+ TransactionOptions are invalid for change stream queries.
301
+
302
+ In addition, if TransactionOptions.read_only.return_read_timestamp
303
+ is set to true, a special value of 2^63 - 2 will be returned in the
304
+ [Transaction][google.spanner.v1.Transaction] message that describes
305
+ the transaction, instead of a valid read timestamp. This special
306
+ value should be discarded and not used for any subsequent queries.
307
+
308
+ Please see https://cloud.google.com/spanner/docs/change-streams for
309
+ more details on how to query the change stream TVFs.
310
+
311
+ Partitioned DML transactions:
312
+
313
+ Partitioned DML transactions are used to execute DML statements with
314
+ a different execution strategy that provides different, and often
315
+ better, scalability properties for large, table-wide operations than
316
+ DML in a ReadWrite transaction. Smaller scoped statements, such as
317
+ an OLTP workload, should prefer using ReadWrite transactions.
318
+
319
+ Partitioned DML partitions the keyspace and runs the DML statement
320
+ on each partition in separate, internal transactions. These
321
+ transactions commit automatically when complete, and run
322
+ independently from one another.
323
+
324
+ To reduce lock contention, this execution strategy only acquires
325
+ read locks on rows that match the WHERE clause of the statement.
326
+ Additionally, the smaller per-partition transactions hold locks for
327
+ less time.
328
+
329
+ That said, Partitioned DML is not a drop-in replacement for standard
330
+ DML used in ReadWrite transactions.
331
+
332
+ - The DML statement must be fully-partitionable. Specifically, the
333
+ statement must be expressible as the union of many statements
334
+ which each access only a single row of the table.
335
+
336
+ - The statement is not applied atomically to all rows of the table.
337
+ Rather, the statement is applied atomically to partitions of the
338
+ table, in independent transactions. Secondary index rows are
339
+ updated atomically with the base table rows.
340
+
341
+ - Partitioned DML does not guarantee exactly-once execution
342
+ semantics against a partition. The statement will be applied at
343
+ least once to each partition. It is strongly recommended that the
344
+ DML statement should be idempotent to avoid unexpected results.
345
+ For instance, it is potentially dangerous to run a statement such
346
+ as ``UPDATE table SET column = column + 1`` as it could be run
347
+ multiple times against some rows.
348
+
349
+ - The partitions are committed automatically - there is no support
350
+ for Commit or Rollback. If the call returns an error, or if the
351
+ client issuing the ExecuteSql call dies, it is possible that some
352
+ rows had the statement executed on them successfully. It is also
353
+ possible that statement was never executed against other rows.
354
+
355
+ - Partitioned DML transactions may only contain the execution of a
356
+ single DML statement via ExecuteSql or ExecuteStreamingSql.
357
+
358
+ - If any error is encountered during the execution of the
359
+ partitioned DML operation (for instance, a UNIQUE INDEX
360
+ violation, division by zero, or a value that cannot be stored due
361
+ to schema constraints), then the operation is stopped at that
362
+ point and an error is returned. It is possible that at this
363
+ point, some partitions have been committed (or even committed
364
+ multiple times), and other partitions have not been run at all.
365
+
366
+ Given the above, Partitioned DML is good fit for large,
367
+ database-wide, operations that are idempotent, such as deleting old
368
+ rows from a very large table.
369
+
370
+ This message has `oneof`_ fields (mutually exclusive fields).
371
+ For each oneof, at most one member field can be set at the same time.
372
+ Setting any member of the oneof automatically clears all other
373
+ members.
374
+
375
+ .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
376
+
377
+ Attributes:
378
+ read_write (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite):
379
+ Transaction may write.
380
+
381
+ Authorization to begin a read-write transaction requires
382
+ ``spanner.databases.beginOrRollbackReadWriteTransaction``
383
+ permission on the ``session`` resource.
384
+
385
+ This field is a member of `oneof`_ ``mode``.
386
+ partitioned_dml (google.cloud.spanner_v1.types.TransactionOptions.PartitionedDml):
387
+ Partitioned DML transaction.
388
+
389
+ Authorization to begin a Partitioned DML transaction
390
+ requires
391
+ ``spanner.databases.beginPartitionedDmlTransaction``
392
+ permission on the ``session`` resource.
393
+
394
+ This field is a member of `oneof`_ ``mode``.
395
+ read_only (google.cloud.spanner_v1.types.TransactionOptions.ReadOnly):
396
+ Transaction will not write.
397
+
398
+ Authorization to begin a read-only transaction requires
399
+ ``spanner.databases.beginReadOnlyTransaction`` permission on
400
+ the ``session`` resource.
401
+
402
+ This field is a member of `oneof`_ ``mode``.
403
+ exclude_txn_from_change_streams (bool):
404
+ When ``exclude_txn_from_change_streams`` is set to ``true``:
405
+
406
+ - Mutations from this transaction will not be recorded in
407
+ change streams with DDL option
408
+ ``allow_txn_exclusion=true`` that are tracking columns
409
+ modified by these transactions.
410
+ - Mutations from this transaction will be recorded in
411
+ change streams with DDL option
412
+ ``allow_txn_exclusion=false or not set`` that are
413
+ tracking columns modified by these transactions.
414
+
415
+ When ``exclude_txn_from_change_streams`` is set to ``false``
416
+ or not set, mutations from this transaction will be recorded
417
+ in all change streams that are tracking columns modified by
418
+ these transactions. ``exclude_txn_from_change_streams`` may
419
+ only be specified for read-write or partitioned-dml
420
+ transactions, otherwise the API will return an
421
+ ``INVALID_ARGUMENT`` error.
422
+ isolation_level (google.cloud.spanner_v1.types.TransactionOptions.IsolationLevel):
423
+ Isolation level for the transaction.
424
+ """
425
+
426
+ class IsolationLevel(proto.Enum):
427
+ r"""``IsolationLevel`` is used when setting ``isolation_level`` for a
428
+ transaction.
429
+
430
+ Values:
431
+ ISOLATION_LEVEL_UNSPECIFIED (0):
432
+ Default value.
433
+
434
+ If the value is not specified, the ``SERIALIZABLE``
435
+ isolation level is used.
436
+ SERIALIZABLE (1):
437
+ All transactions appear as if they executed
438
+ in a serial order, even if some of the reads,
439
+ writes, and other operations of distinct
440
+ transactions actually occurred in parallel.
441
+ Spanner assigns commit timestamps that reflect
442
+ the order of committed transactions to implement
443
+ this property. Spanner offers a stronger
444
+ guarantee than serializability called external
445
+ consistency. For further details, please refer
446
+ to
447
+ https://cloud.google.com/spanner/docs/true-time-external-consistency#serializability.
448
+ REPEATABLE_READ (2):
449
+ All reads performed during the transaction observe a
450
+ consistent snapshot of the database, and the transaction
451
+ will only successfully commit in the absence of conflicts
452
+ between its updates and any concurrent updates that have
453
+ occurred since that snapshot. Consequently, in contrast to
454
+ ``SERIALIZABLE`` transactions, only write-write conflicts
455
+ are detected in snapshot transactions.
456
+
457
+ This isolation level does not support Read-only and
458
+ Partitioned DML transactions.
459
+
460
+ When ``REPEATABLE_READ`` is specified on a read-write
461
+ transaction, the locking semantics default to
462
+ ``OPTIMISTIC``.
463
+ """
464
+ ISOLATION_LEVEL_UNSPECIFIED = 0
465
+ SERIALIZABLE = 1
466
+ REPEATABLE_READ = 2
467
+
468
+ class ReadWrite(proto.Message):
469
+ r"""Message type to initiate a read-write transaction. Currently
470
+ this transaction type has no options.
471
+
472
+ Attributes:
473
+ read_lock_mode (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite.ReadLockMode):
474
+ Read lock mode for the transaction.
475
+ multiplexed_session_previous_transaction_id (bytes):
476
+ Optional. Clients should pass the transaction
477
+ ID of the previous transaction attempt that was
478
+ aborted if this transaction is being executed on
479
+ a multiplexed session.
480
+ This feature is not yet supported and will
481
+ result in an UNIMPLEMENTED error.
482
+ """
483
+
484
+ class ReadLockMode(proto.Enum):
485
+ r"""``ReadLockMode`` is used to set the read lock mode for read-write
486
+ transactions.
487
+
488
+ Values:
489
+ READ_LOCK_MODE_UNSPECIFIED (0):
490
+ Default value.
491
+
492
+ - If isolation level is ``REPEATABLE_READ``, then it is an
493
+ error to specify ``read_lock_mode``. Locking semantics
494
+ default to ``OPTIMISTIC``. No validation checks are done
495
+ for reads, except for:
496
+
497
+ 1. reads done as part of queries that use
498
+ ``SELECT FOR UPDATE``
499
+ 2. reads done as part of statements with a
500
+ ``LOCK_SCANNED_RANGES`` hint
501
+ 3. reads done as part of DML statements to validate that
502
+ the data that was served at the snapshot time is
503
+ unchanged at commit time.
504
+
505
+ - At all other isolation levels, if ``read_lock_mode`` is
506
+ the default value, then pessimistic read lock is used.
507
+ PESSIMISTIC (1):
508
+ Pessimistic lock mode.
509
+
510
+ Read locks are acquired immediately on read. Semantics
511
+ described only applies to ``SERIALIZABLE`` isolation.
512
+ OPTIMISTIC (2):
513
+ Optimistic lock mode.
514
+
515
+ Locks for reads within the transaction are not acquired on
516
+ read. Instead the locks are acquired on a commit to validate
517
+ that read/queried data has not changed since the transaction
518
+ started. Semantics described only applies to
519
+ ``SERIALIZABLE`` isolation.
520
+ """
521
+ READ_LOCK_MODE_UNSPECIFIED = 0
522
+ PESSIMISTIC = 1
523
+ OPTIMISTIC = 2
524
+
525
+ read_lock_mode: "TransactionOptions.ReadWrite.ReadLockMode" = proto.Field(
526
+ proto.ENUM,
527
+ number=1,
528
+ enum="TransactionOptions.ReadWrite.ReadLockMode",
529
+ )
530
+ multiplexed_session_previous_transaction_id: bytes = proto.Field(
531
+ proto.BYTES,
532
+ number=2,
533
+ )
534
+
535
+ class PartitionedDml(proto.Message):
536
+ r"""Message type to initiate a Partitioned DML transaction."""
537
+
538
+ class ReadOnly(proto.Message):
539
+ r"""Message type to initiate a read-only transaction.
540
+
541
+ This message has `oneof`_ fields (mutually exclusive fields).
542
+ For each oneof, at most one member field can be set at the same time.
543
+ Setting any member of the oneof automatically clears all other
544
+ members.
545
+
546
+ .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
547
+
548
+ Attributes:
549
+ strong (bool):
550
+ Read at a timestamp where all previously
551
+ committed transactions are visible.
552
+
553
+ This field is a member of `oneof`_ ``timestamp_bound``.
554
+ min_read_timestamp (google.protobuf.timestamp_pb2.Timestamp):
555
+ Executes all reads at a timestamp >= ``min_read_timestamp``.
556
+
557
+ This is useful for requesting fresher data than some
558
+ previous read, or data that is fresh enough to observe the
559
+ effects of some previously committed transaction whose
560
+ timestamp is known.
561
+
562
+ Note that this option can only be used in single-use
563
+ transactions.
564
+
565
+ A timestamp in RFC3339 UTC "Zulu" format, accurate to
566
+ nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``.
567
+
568
+ This field is a member of `oneof`_ ``timestamp_bound``.
569
+ max_staleness (google.protobuf.duration_pb2.Duration):
570
+ Read data at a timestamp >= ``NOW - max_staleness`` seconds.
571
+ Guarantees that all writes that have committed more than the
572
+ specified number of seconds ago are visible. Because Cloud
573
+ Spanner chooses the exact timestamp, this mode works even if
574
+ the client's local clock is substantially skewed from Cloud
575
+ Spanner commit timestamps.
576
+
577
+ Useful for reading the freshest data available at a nearby
578
+ replica, while bounding the possible staleness if the local
579
+ replica has fallen behind.
580
+
581
+ Note that this option can only be used in single-use
582
+ transactions.
583
+
584
+ This field is a member of `oneof`_ ``timestamp_bound``.
585
+ read_timestamp (google.protobuf.timestamp_pb2.Timestamp):
586
+ Executes all reads at the given timestamp. Unlike other
587
+ modes, reads at a specific timestamp are repeatable; the
588
+ same read at the same timestamp always returns the same
589
+ data. If the timestamp is in the future, the read will block
590
+ until the specified timestamp, modulo the read's deadline.
591
+
592
+ Useful for large scale consistent reads such as mapreduces,
593
+ or for coordinating many reads against a consistent snapshot
594
+ of the data.
595
+
596
+ A timestamp in RFC3339 UTC "Zulu" format, accurate to
597
+ nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``.
598
+
599
+ This field is a member of `oneof`_ ``timestamp_bound``.
600
+ exact_staleness (google.protobuf.duration_pb2.Duration):
601
+ Executes all reads at a timestamp that is
602
+ ``exact_staleness`` old. The timestamp is chosen soon after
603
+ the read is started.
604
+
605
+ Guarantees that all writes that have committed more than the
606
+ specified number of seconds ago are visible. Because Cloud
607
+ Spanner chooses the exact timestamp, this mode works even if
608
+ the client's local clock is substantially skewed from Cloud
609
+ Spanner commit timestamps.
610
+
611
+ Useful for reading at nearby replicas without the
612
+ distributed timestamp negotiation overhead of
613
+ ``max_staleness``.
614
+
615
+ This field is a member of `oneof`_ ``timestamp_bound``.
616
+ return_read_timestamp (bool):
617
+ If true, the Cloud Spanner-selected read timestamp is
618
+ included in the [Transaction][google.spanner.v1.Transaction]
619
+ message that describes the transaction.
620
+ """
621
+
622
+ strong: bool = proto.Field(
623
+ proto.BOOL,
624
+ number=1,
625
+ oneof="timestamp_bound",
626
+ )
627
+ min_read_timestamp: timestamp_pb2.Timestamp = proto.Field(
628
+ proto.MESSAGE,
629
+ number=2,
630
+ oneof="timestamp_bound",
631
+ message=timestamp_pb2.Timestamp,
632
+ )
633
+ max_staleness: duration_pb2.Duration = proto.Field(
634
+ proto.MESSAGE,
635
+ number=3,
636
+ oneof="timestamp_bound",
637
+ message=duration_pb2.Duration,
638
+ )
639
+ read_timestamp: timestamp_pb2.Timestamp = proto.Field(
640
+ proto.MESSAGE,
641
+ number=4,
642
+ oneof="timestamp_bound",
643
+ message=timestamp_pb2.Timestamp,
644
+ )
645
+ exact_staleness: duration_pb2.Duration = proto.Field(
646
+ proto.MESSAGE,
647
+ number=5,
648
+ oneof="timestamp_bound",
649
+ message=duration_pb2.Duration,
650
+ )
651
+ return_read_timestamp: bool = proto.Field(
652
+ proto.BOOL,
653
+ number=6,
654
+ )
655
+
656
+ read_write: ReadWrite = proto.Field(
657
+ proto.MESSAGE,
658
+ number=1,
659
+ oneof="mode",
660
+ message=ReadWrite,
661
+ )
662
+ partitioned_dml: PartitionedDml = proto.Field(
663
+ proto.MESSAGE,
664
+ number=3,
665
+ oneof="mode",
666
+ message=PartitionedDml,
667
+ )
668
+ read_only: ReadOnly = proto.Field(
669
+ proto.MESSAGE,
670
+ number=2,
671
+ oneof="mode",
672
+ message=ReadOnly,
673
+ )
674
+ exclude_txn_from_change_streams: bool = proto.Field(
675
+ proto.BOOL,
676
+ number=5,
677
+ )
678
+ isolation_level: IsolationLevel = proto.Field(
679
+ proto.ENUM,
680
+ number=6,
681
+ enum=IsolationLevel,
682
+ )
683
+
684
+
685
+ class Transaction(proto.Message):
686
+ r"""A transaction.
687
+
688
+ Attributes:
689
+ id (bytes):
690
+ ``id`` may be used to identify the transaction in subsequent
691
+ [Read][google.spanner.v1.Spanner.Read],
692
+ [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql],
693
+ [Commit][google.spanner.v1.Spanner.Commit], or
694
+ [Rollback][google.spanner.v1.Spanner.Rollback] calls.
695
+
696
+ Single-use read-only transactions do not have IDs, because
697
+ single-use transactions do not support multiple requests.
698
+ read_timestamp (google.protobuf.timestamp_pb2.Timestamp):
699
+ For snapshot read-only transactions, the read timestamp
700
+ chosen for the transaction. Not returned by default: see
701
+ [TransactionOptions.ReadOnly.return_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.return_read_timestamp].
702
+
703
+ A timestamp in RFC3339 UTC "Zulu" format, accurate to
704
+ nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``.
705
+ precommit_token (google.cloud.spanner_v1.types.MultiplexedSessionPrecommitToken):
706
+ A precommit token will be included in the response of a
707
+ BeginTransaction request if the read-write transaction is on
708
+ a multiplexed session and a mutation_key was specified in
709
+ the
710
+ [BeginTransaction][google.spanner.v1.BeginTransactionRequest].
711
+ The precommit token with the highest sequence number from
712
+ this transaction attempt should be passed to the
713
+ [Commit][google.spanner.v1.Spanner.Commit] request for this
714
+ transaction. This feature is not yet supported and will
715
+ result in an UNIMPLEMENTED error.
716
+ """
717
+
718
+ id: bytes = proto.Field(
719
+ proto.BYTES,
720
+ number=1,
721
+ )
722
+ read_timestamp: timestamp_pb2.Timestamp = proto.Field(
723
+ proto.MESSAGE,
724
+ number=2,
725
+ message=timestamp_pb2.Timestamp,
726
+ )
727
+ precommit_token: "MultiplexedSessionPrecommitToken" = proto.Field(
728
+ proto.MESSAGE,
729
+ number=3,
730
+ message="MultiplexedSessionPrecommitToken",
731
+ )
732
+
733
+
734
+ class TransactionSelector(proto.Message):
735
+ r"""This message is used to select the transaction in which a
736
+ [Read][google.spanner.v1.Spanner.Read] or
737
+ [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] call runs.
738
+
739
+ See [TransactionOptions][google.spanner.v1.TransactionOptions] for
740
+ more information about transactions.
741
+
742
+ This message has `oneof`_ fields (mutually exclusive fields).
743
+ For each oneof, at most one member field can be set at the same time.
744
+ Setting any member of the oneof automatically clears all other
745
+ members.
746
+
747
+ .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
748
+
749
+ Attributes:
750
+ single_use (google.cloud.spanner_v1.types.TransactionOptions):
751
+ Execute the read or SQL query in a temporary
752
+ transaction. This is the most efficient way to
753
+ execute a transaction that consists of a single
754
+ SQL query.
755
+
756
+ This field is a member of `oneof`_ ``selector``.
757
+ id (bytes):
758
+ Execute the read or SQL query in a
759
+ previously-started transaction.
760
+
761
+ This field is a member of `oneof`_ ``selector``.
762
+ begin (google.cloud.spanner_v1.types.TransactionOptions):
763
+ Begin a new transaction and execute this read or SQL query
764
+ in it. The transaction ID of the new transaction is returned
765
+ in
766
+ [ResultSetMetadata.transaction][google.spanner.v1.ResultSetMetadata.transaction],
767
+ which is a [Transaction][google.spanner.v1.Transaction].
768
+
769
+ This field is a member of `oneof`_ ``selector``.
770
+ """
771
+
772
+ single_use: "TransactionOptions" = proto.Field(
773
+ proto.MESSAGE,
774
+ number=1,
775
+ oneof="selector",
776
+ message="TransactionOptions",
777
+ )
778
+ id: bytes = proto.Field(
779
+ proto.BYTES,
780
+ number=2,
781
+ oneof="selector",
782
+ )
783
+ begin: "TransactionOptions" = proto.Field(
784
+ proto.MESSAGE,
785
+ number=3,
786
+ oneof="selector",
787
+ message="TransactionOptions",
788
+ )
789
+
790
+
791
+ class MultiplexedSessionPrecommitToken(proto.Message):
792
+ r"""When a read-write transaction is executed on a multiplexed session,
793
+ this precommit token is sent back to the client as a part of the
794
+ [Transaction] message in the BeginTransaction response and also as a
795
+ part of the [ResultSet] and [PartialResultSet] responses.
796
+
797
+ Attributes:
798
+ precommit_token (bytes):
799
+ Opaque precommit token.
800
+ seq_num (int):
801
+ An incrementing seq number is generated on
802
+ every precommit token that is returned. Clients
803
+ should remember the precommit token with the
804
+ highest sequence number from the current
805
+ transaction attempt.
806
+ """
807
+
808
+ precommit_token: bytes = proto.Field(
809
+ proto.BYTES,
810
+ number=1,
811
+ )
812
+ seq_num: int = proto.Field(
813
+ proto.INT32,
814
+ number=2,
815
+ )
816
+
817
+
818
+ __all__ = tuple(sorted(__protobuf__.manifest))