google-cloud-spanner 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/google-cloud-spanner.rb +106 -0
- data/lib/google/cloud/spanner.rb +382 -0
- data/lib/google/cloud/spanner/admin/database/v1.rb +17 -0
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +703 -0
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +73 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +139 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +114 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +188 -0
- data/lib/google/cloud/spanner/admin/instance/v1.rb +17 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +139 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +114 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +223 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +268 -0
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +868 -0
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +78 -0
- data/lib/google/cloud/spanner/client.rb +1034 -0
- data/lib/google/cloud/spanner/commit.rb +351 -0
- data/lib/google/cloud/spanner/convert.rb +311 -0
- data/lib/google/cloud/spanner/credentials.rb +32 -0
- data/lib/google/cloud/spanner/data.rb +199 -0
- data/lib/google/cloud/spanner/database.rb +377 -0
- data/lib/google/cloud/spanner/database/job.rb +179 -0
- data/lib/google/cloud/spanner/database/list.rb +171 -0
- data/lib/google/cloud/spanner/errors.rb +73 -0
- data/lib/google/cloud/spanner/fields.rb +252 -0
- data/lib/google/cloud/spanner/instance.rb +472 -0
- data/lib/google/cloud/spanner/instance/config.rb +99 -0
- data/lib/google/cloud/spanner/instance/config/list.rb +171 -0
- data/lib/google/cloud/spanner/instance/job.rb +197 -0
- data/lib/google/cloud/spanner/instance/list.rb +167 -0
- data/lib/google/cloud/spanner/policy.rb +201 -0
- data/lib/google/cloud/spanner/pool.rb +279 -0
- data/lib/google/cloud/spanner/project.rb +480 -0
- data/lib/google/cloud/spanner/range.rb +99 -0
- data/lib/google/cloud/spanner/results.rb +280 -0
- data/lib/google/cloud/spanner/service.rb +458 -0
- data/lib/google/cloud/spanner/session.rb +565 -0
- data/lib/google/cloud/spanner/snapshot.rb +260 -0
- data/lib/google/cloud/spanner/transaction.rb +533 -0
- data/lib/google/cloud/spanner/v1.rb +17 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +77 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +73 -0
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +81 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +148 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +80 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +120 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +175 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +206 -0
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +351 -0
- data/lib/google/cloud/spanner/v1/spanner_client.rb +850 -0
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +78 -0
- data/lib/google/cloud/spanner/version.rb +22 -0
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +85 -0
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +95 -0
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +106 -0
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +180 -0
- data/lib/google/spanner/v1/keys_pb.rb +33 -0
- data/lib/google/spanner/v1/mutation_pb.rb +38 -0
- data/lib/google/spanner/v1/query_plan_pb.rb +47 -0
- data/lib/google/spanner/v1/result_set_pb.rb +43 -0
- data/lib/google/spanner/v1/spanner_pb.rb +90 -0
- data/lib/google/spanner/v1/spanner_services_pb.rb +131 -0
- data/lib/google/spanner/v1/transaction_pb.rb +51 -0
- data/lib/google/spanner/v1/type_pb.rb +43 -0
- metadata +309 -0
@@ -0,0 +1,351 @@
|
|
1
|
+
# Copyright 2017, Google Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Google
|
16
|
+
module Spanner
|
17
|
+
module V1
|
18
|
+
# = Transactions
|
19
|
+
#
|
20
|
+
# Each session can have at most one active transaction at a time. After the
|
21
|
+
# active transaction is completed, the session can immediately be
|
22
|
+
# re-used for the next transaction. It is not necessary to create a
|
23
|
+
# new session for each transaction.
|
24
|
+
#
|
25
|
+
# = Transaction Modes
|
26
|
+
#
|
27
|
+
# Cloud Spanner supports two transaction modes:
|
28
|
+
#
|
29
|
+
# 1. Locking read-write. This type of transaction is the only way
|
30
|
+
# to write data into Cloud Spanner. These transactions rely on
|
31
|
+
# pessimistic locking and, if necessary, two-phase commit.
|
32
|
+
# Locking read-write transactions may abort, requiring the
|
33
|
+
# application to retry.
|
34
|
+
#
|
35
|
+
# 2. Snapshot read-only. This transaction type provides guaranteed
|
36
|
+
# consistency across several reads, but does not allow
|
37
|
+
# writes. Snapshot read-only transactions can be configured to
|
38
|
+
# read at timestamps in the past. Snapshot read-only
|
39
|
+
# transactions do not need to be committed.
|
40
|
+
#
|
41
|
+
# For transactions that only read, snapshot read-only transactions
|
42
|
+
# provide simpler semantics and are almost always faster. In
|
43
|
+
# particular, read-only transactions do not take locks, so they do
|
44
|
+
# not conflict with read-write transactions. As a consequence of not
|
45
|
+
# taking locks, they also do not abort, so retry loops are not needed.
|
46
|
+
#
|
47
|
+
# Transactions may only read/write data in a single database. They
|
48
|
+
# may, however, read/write data in different tables within that
|
49
|
+
# database.
|
50
|
+
#
|
51
|
+
# == Locking Read-Write Transactions
|
52
|
+
#
|
53
|
+
# Locking transactions may be used to atomically read-modify-write
|
54
|
+
# data anywhere in a database. This type of transaction is externally
|
55
|
+
# consistent.
|
56
|
+
#
|
57
|
+
# Clients should attempt to minimize the amount of time a transaction
|
58
|
+
# is active. Faster transactions commit with higher probability
|
59
|
+
# and cause less contention. Cloud Spanner attempts to keep read locks
|
60
|
+
# active as long as the transaction continues to do reads, and the
|
61
|
+
# transaction has not been terminated by
|
62
|
+
# Commit or
|
63
|
+
# Rollback. Long periods of
|
64
|
+
# inactivity at the client may cause Cloud Spanner to release a
|
65
|
+
# transaction's locks and abort it.
|
66
|
+
#
|
67
|
+
# Reads performed within a transaction acquire locks on the data
|
68
|
+
# being read. Writes can only be done at commit time, after all reads
|
69
|
+
# have been completed.
|
70
|
+
# Conceptually, a read-write transaction consists of zero or more
|
71
|
+
# reads or SQL queries followed by
|
72
|
+
# Commit. At any time before
|
73
|
+
# Commit, the client can send a
|
74
|
+
# Rollback request to abort the
|
75
|
+
# transaction.
|
76
|
+
#
|
77
|
+
# === Semantics
|
78
|
+
#
|
79
|
+
# Cloud Spanner can commit the transaction if all read locks it acquired
|
80
|
+
# are still valid at commit time, and it is able to acquire write
|
81
|
+
# locks for all writes. Cloud Spanner can abort the transaction for any
|
82
|
+
# reason. If a commit attempt returns +ABORTED+, Cloud Spanner guarantees
|
83
|
+
# that the transaction has not modified any user data in Cloud Spanner.
|
84
|
+
#
|
85
|
+
# Unless the transaction commits, Cloud Spanner makes no guarantees about
|
86
|
+
# how long the transaction's locks were held for. It is an error to
|
87
|
+
# use Cloud Spanner locks for any sort of mutual exclusion other than
|
88
|
+
# between Cloud Spanner transactions themselves.
|
89
|
+
#
|
90
|
+
# === Retrying Aborted Transactions
|
91
|
+
#
|
92
|
+
# When a transaction aborts, the application can choose to retry the
|
93
|
+
# whole transaction again. To maximize the chances of successfully
|
94
|
+
# committing the retry, the client should execute the retry in the
|
95
|
+
# same session as the original attempt. The original session's lock
|
96
|
+
# priority increases with each consecutive abort, meaning that each
|
97
|
+
# attempt has a slightly better chance of success than the previous.
|
98
|
+
#
|
99
|
+
# Under some circumstances (e.g., many transactions attempting to
|
100
|
+
# modify the same row(s)), a transaction can abort many times in a
|
101
|
+
# short period before successfully committing. Thus, it is not a good
|
102
|
+
# idea to cap the number of retries a transaction can attempt;
|
103
|
+
# instead, it is better to limit the total amount of wall time spent
|
104
|
+
# retrying.
|
105
|
+
#
|
106
|
+
# === Idle Transactions
|
107
|
+
#
|
108
|
+
# A transaction is considered idle if it has no outstanding reads or
|
109
|
+
# SQL queries and has not started a read or SQL query within the last 10
|
110
|
+
# seconds. Idle transactions can be aborted by Cloud Spanner so that they
|
111
|
+
# don't hold on to locks indefinitely. In that case, the commit will
|
112
|
+
# fail with error +ABORTED+.
|
113
|
+
#
|
114
|
+
# If this behavior is undesirable, periodically executing a simple
|
115
|
+
# SQL query in the transaction (e.g., +SELECT 1+) prevents the
|
116
|
+
# transaction from becoming idle.
|
117
|
+
#
|
118
|
+
# == Snapshot Read-Only Transactions
|
119
|
+
#
|
120
|
+
# Snapshot read-only transactions provides a simpler method than
|
121
|
+
# locking read-write transactions for doing several consistent
|
122
|
+
# reads. However, this type of transaction does not support writes.
|
123
|
+
#
|
124
|
+
# Snapshot transactions do not take locks. Instead, they work by
|
125
|
+
# choosing a Cloud Spanner timestamp, then executing all reads at that
|
126
|
+
# timestamp. Since they do not acquire locks, they do not block
|
127
|
+
# concurrent read-write transactions.
|
128
|
+
#
|
129
|
+
# Unlike locking read-write transactions, snapshot read-only
|
130
|
+
# transactions never abort. They can fail if the chosen read
|
131
|
+
# timestamp is garbage collected; however, the default garbage
|
132
|
+
# collection policy is generous enough that most applications do not
|
133
|
+
# need to worry about this in practice.
|
134
|
+
#
|
135
|
+
# Snapshot read-only transactions do not need to call
|
136
|
+
# Commit or
|
137
|
+
# Rollback (and in fact are not
|
138
|
+
# permitted to do so).
|
139
|
+
#
|
140
|
+
# To execute a snapshot transaction, the client specifies a timestamp
|
141
|
+
# bound, which tells Cloud Spanner how to choose a read timestamp.
|
142
|
+
#
|
143
|
+
# The types of timestamp bound are:
|
144
|
+
#
|
145
|
+
# - Strong (the default).
|
146
|
+
# - Bounded staleness.
|
147
|
+
# - Exact staleness.
|
148
|
+
#
|
149
|
+
# If the Cloud Spanner database to be read is geographically distributed,
|
150
|
+
# stale read-only transactions can execute more quickly than strong
|
151
|
+
# or read-write transaction, because they are able to execute far
|
152
|
+
# from the leader replica.
|
153
|
+
#
|
154
|
+
# Each type of timestamp bound is discussed in detail below.
|
155
|
+
#
|
156
|
+
# === Strong
|
157
|
+
#
|
158
|
+
# Strong reads are guaranteed to see the effects of all transactions
|
159
|
+
# that have committed before the start of the read. Furthermore, all
|
160
|
+
# rows yielded by a single read are consistent with each other -- if
|
161
|
+
# any part of the read observes a transaction, all parts of the read
|
162
|
+
# see the transaction.
|
163
|
+
#
|
164
|
+
# Strong reads are not repeatable: two consecutive strong read-only
|
165
|
+
# transactions might return inconsistent results if there are
|
166
|
+
# concurrent writes. If consistency across reads is required, the
|
167
|
+
# reads should be executed within a transaction or at an exact read
|
168
|
+
# timestamp.
|
169
|
+
#
|
170
|
+
# See TransactionOptions::ReadOnly#strong.
|
171
|
+
#
|
172
|
+
# === Exact Staleness
|
173
|
+
#
|
174
|
+
# These timestamp bounds execute reads at a user-specified
|
175
|
+
# timestamp. Reads at a timestamp are guaranteed to see a consistent
|
176
|
+
# prefix of the global transaction history: they observe
|
177
|
+
# modifications done by all transactions with a commit timestamp <=
|
178
|
+
# the read timestamp, and observe none of the modifications done by
|
179
|
+
# transactions with a larger commit timestamp. They will block until
|
180
|
+
# all conflicting transactions that may be assigned commit timestamps
|
181
|
+
# <= the read timestamp have finished.
|
182
|
+
#
|
183
|
+
# The timestamp can either be expressed as an absolute Cloud Spanner commit
|
184
|
+
# timestamp or a staleness relative to the current time.
|
185
|
+
#
|
186
|
+
# These modes do not require a "negotiation phase" to pick a
|
187
|
+
# timestamp. As a result, they execute slightly faster than the
|
188
|
+
# equivalent boundedly stale concurrency modes. On the other hand,
|
189
|
+
# boundedly stale reads usually return fresher results.
|
190
|
+
#
|
191
|
+
# See TransactionOptions::ReadOnly#read_timestamp and
|
192
|
+
# TransactionOptions::ReadOnly#exact_staleness.
|
193
|
+
#
|
194
|
+
# === Bounded Staleness
|
195
|
+
#
|
196
|
+
# Bounded staleness modes allow Cloud Spanner to pick the read timestamp,
|
197
|
+
# subject to a user-provided staleness bound. Cloud Spanner chooses the
|
198
|
+
# newest timestamp within the staleness bound that allows execution
|
199
|
+
# of the reads at the closest available replica without blocking.
|
200
|
+
#
|
201
|
+
# All rows yielded are consistent with each other -- if any part of
|
202
|
+
# the read observes a transaction, all parts of the read see the
|
203
|
+
# transaction. Boundedly stale reads are not repeatable: two stale
|
204
|
+
# reads, even if they use the same staleness bound, can execute at
|
205
|
+
# different timestamps and thus return inconsistent results.
|
206
|
+
#
|
207
|
+
# Boundedly stale reads execute in two phases: the first phase
|
208
|
+
# negotiates a timestamp among all replicas needed to serve the
|
209
|
+
# read. In the second phase, reads are executed at the negotiated
|
210
|
+
# timestamp.
|
211
|
+
#
|
212
|
+
# As a result of the two phase execution, bounded staleness reads are
|
213
|
+
# usually a little slower than comparable exact staleness
|
214
|
+
# reads. However, they are typically able to return fresher
|
215
|
+
# results, and are more likely to execute at the closest replica.
|
216
|
+
#
|
217
|
+
# Because the timestamp negotiation requires up-front knowledge of
|
218
|
+
# which rows will be read, it can only be used with single-use
|
219
|
+
# read-only transactions.
|
220
|
+
#
|
221
|
+
# See TransactionOptions::ReadOnly#max_staleness and
|
222
|
+
# TransactionOptions::ReadOnly#min_read_timestamp.
|
223
|
+
#
|
224
|
+
# === Old Read Timestamps and Garbage Collection
|
225
|
+
#
|
226
|
+
# Cloud Spanner continuously garbage collects deleted and overwritten data
|
227
|
+
# in the background to reclaim storage space. This process is known
|
228
|
+
# as "version GC". By default, version GC reclaims versions after they
|
229
|
+
# are one hour old. Because of this, Cloud Spanner cannot perform reads
|
230
|
+
# at read timestamps more than one hour in the past. This
|
231
|
+
# restriction also applies to in-progress reads and/or SQL queries whose
|
232
|
+
# timestamp become too old while executing. Reads and SQL queries with
|
233
|
+
# too-old read timestamps fail with the error +FAILED_PRECONDITION+.
|
234
|
+
# @!attribute [rw] read_write
|
235
|
+
# @return [Google::Spanner::V1::TransactionOptions::ReadWrite]
|
236
|
+
# Transaction may write.
|
237
|
+
#
|
238
|
+
# Authorization to begin a read-write transaction requires
|
239
|
+
# +spanner.databases.beginOrRollbackReadWriteTransaction+ permission
|
240
|
+
# on the +session+ resource.
|
241
|
+
# @!attribute [rw] read_only
|
242
|
+
# @return [Google::Spanner::V1::TransactionOptions::ReadOnly]
|
243
|
+
# Transaction will not write.
|
244
|
+
#
|
245
|
+
# Authorization to begin a read-only transaction requires
|
246
|
+
# +spanner.databases.beginReadOnlyTransaction+ permission
|
247
|
+
# on the +session+ resource.
|
248
|
+
class TransactionOptions
|
249
|
+
# Options for read-write transactions.
|
250
|
+
class ReadWrite; end
|
251
|
+
|
252
|
+
# Options for read-only transactions.
|
253
|
+
# @!attribute [rw] strong
|
254
|
+
# @return [true, false]
|
255
|
+
# Read at a timestamp where all previously committed transactions
|
256
|
+
# are visible.
|
257
|
+
# @!attribute [rw] min_read_timestamp
|
258
|
+
# @return [Google::Protobuf::Timestamp]
|
259
|
+
# Executes all reads at a timestamp >= +min_read_timestamp+.
|
260
|
+
#
|
261
|
+
# This is useful for requesting fresher data than some previous
|
262
|
+
# read, or data that is fresh enough to observe the effects of some
|
263
|
+
# previously committed transaction whose timestamp is known.
|
264
|
+
#
|
265
|
+
# Note that this option can only be used in single-use transactions.
|
266
|
+
# @!attribute [rw] max_staleness
|
267
|
+
# @return [Google::Protobuf::Duration]
|
268
|
+
# Read data at a timestamp >= +NOW - max_staleness+
|
269
|
+
# seconds. Guarantees that all writes that have committed more
|
270
|
+
# than the specified number of seconds ago are visible. Because
|
271
|
+
# Cloud Spanner chooses the exact timestamp, this mode works even if
|
272
|
+
# the client's local clock is substantially skewed from Cloud Spanner
|
273
|
+
# commit timestamps.
|
274
|
+
#
|
275
|
+
# Useful for reading the freshest data available at a nearby
|
276
|
+
# replica, while bounding the possible staleness if the local
|
277
|
+
# replica has fallen behind.
|
278
|
+
#
|
279
|
+
# Note that this option can only be used in single-use
|
280
|
+
# transactions.
|
281
|
+
# @!attribute [rw] read_timestamp
|
282
|
+
# @return [Google::Protobuf::Timestamp]
|
283
|
+
# Executes all reads at the given timestamp. Unlike other modes,
|
284
|
+
# reads at a specific timestamp are repeatable; the same read at
|
285
|
+
# the same timestamp always returns the same data. If the
|
286
|
+
# timestamp is in the future, the read will block until the
|
287
|
+
# specified timestamp, modulo the read's deadline.
|
288
|
+
#
|
289
|
+
# Useful for large scale consistent reads such as mapreduces, or
|
290
|
+
# for coordinating many reads against a consistent snapshot of the
|
291
|
+
# data.
|
292
|
+
# @!attribute [rw] exact_staleness
|
293
|
+
# @return [Google::Protobuf::Duration]
|
294
|
+
# Executes all reads at a timestamp that is +exact_staleness+
|
295
|
+
# old. The timestamp is chosen soon after the read is started.
|
296
|
+
#
|
297
|
+
# Guarantees that all writes that have committed more than the
|
298
|
+
# specified number of seconds ago are visible. Because Cloud Spanner
|
299
|
+
# chooses the exact timestamp, this mode works even if the client's
|
300
|
+
# local clock is substantially skewed from Cloud Spanner commit
|
301
|
+
# timestamps.
|
302
|
+
#
|
303
|
+
# Useful for reading at nearby replicas without the distributed
|
304
|
+
# timestamp negotiation overhead of +max_staleness+.
|
305
|
+
# @!attribute [rw] return_read_timestamp
|
306
|
+
# @return [true, false]
|
307
|
+
# If true, the Cloud Spanner-selected read timestamp is included in
|
308
|
+
# the Transaction message that describes the transaction.
|
309
|
+
class ReadOnly; end
|
310
|
+
end
|
311
|
+
|
312
|
+
# A transaction.
|
313
|
+
# @!attribute [rw] id
|
314
|
+
# @return [String]
|
315
|
+
# +id+ may be used to identify the transaction in subsequent
|
316
|
+
# Read,
|
317
|
+
# ExecuteSql,
|
318
|
+
# Commit, or
|
319
|
+
# Rollback calls.
|
320
|
+
#
|
321
|
+
# Single-use read-only transactions do not have IDs, because
|
322
|
+
# single-use transactions do not support multiple requests.
|
323
|
+
# @!attribute [rw] read_timestamp
|
324
|
+
# @return [Google::Protobuf::Timestamp]
|
325
|
+
# For snapshot read-only transactions, the read timestamp chosen
|
326
|
+
# for the transaction. Not returned by default: see
|
327
|
+
# TransactionOptions::ReadOnly#return_read_timestamp.
|
328
|
+
class Transaction; end
|
329
|
+
|
330
|
+
# This message is used to select the transaction in which a
|
331
|
+
# Read or
|
332
|
+
# ExecuteSql call runs.
|
333
|
+
#
|
334
|
+
# See TransactionOptions for more information about transactions.
|
335
|
+
# @!attribute [rw] single_use
|
336
|
+
# @return [Google::Spanner::V1::TransactionOptions]
|
337
|
+
# Execute the read or SQL query in a temporary transaction.
|
338
|
+
# This is the most efficient way to execute a transaction that
|
339
|
+
# consists of a single SQL query.
|
340
|
+
# @!attribute [rw] id
|
341
|
+
# @return [String]
|
342
|
+
# Execute the read or SQL query in a previously-started transaction.
|
343
|
+
# @!attribute [rw] begin
|
344
|
+
# @return [Google::Spanner::V1::TransactionOptions]
|
345
|
+
# Begin a new transaction and execute this read or SQL query in
|
346
|
+
# it. The transaction ID of the new transaction is returned in
|
347
|
+
# ResultSetMetadata#transaction, which is a Transaction.
|
348
|
+
class TransactionSelector; end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
@@ -0,0 +1,850 @@
|
|
1
|
+
# Copyright 2017, Google Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# EDITING INSTRUCTIONS
|
16
|
+
# This file was generated from the file
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/spanner.proto,
|
18
|
+
# and updates to that file get reflected here through a refresh process.
|
19
|
+
# For the short term, the refresh process will only be runnable by Google
|
20
|
+
# engineers.
|
21
|
+
#
|
22
|
+
# The only allowed edits are to method and file documentation. A 3-way
|
23
|
+
# merge preserves those additions if the generated source changes.
|
24
|
+
|
25
|
+
require "json"
|
26
|
+
require "pathname"
|
27
|
+
|
28
|
+
require "google/gax"
|
29
|
+
|
30
|
+
require "google/spanner/v1/spanner_pb"
|
31
|
+
|
32
|
+
module Google
|
33
|
+
module Cloud
|
34
|
+
module Spanner
|
35
|
+
module V1
|
36
|
+
# Cloud Spanner API
|
37
|
+
#
|
38
|
+
# The Cloud Spanner API can be used to manage sessions and execute
|
39
|
+
# transactions on data stored in Cloud Spanner databases.
|
40
|
+
#
|
41
|
+
# @!attribute [r] spanner_stub
|
42
|
+
# @return [Google::Spanner::V1::Spanner::Stub]
|
43
|
+
class SpannerClient
|
44
|
+
attr_reader :spanner_stub
|
45
|
+
|
46
|
+
# The default address of the service.
|
47
|
+
SERVICE_ADDRESS = "spanner.googleapis.com".freeze
|
48
|
+
|
49
|
+
# The default port of the service.
|
50
|
+
DEFAULT_SERVICE_PORT = 443
|
51
|
+
|
52
|
+
DEFAULT_TIMEOUT = 30
|
53
|
+
|
54
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
55
|
+
# this service.
|
56
|
+
ALL_SCOPES = [
|
57
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
58
|
+
"https://www.googleapis.com/auth/spanner.data"
|
59
|
+
].freeze
|
60
|
+
|
61
|
+
DATABASE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
62
|
+
"projects/{project}/instances/{instance}/databases/{database}"
|
63
|
+
)
|
64
|
+
|
65
|
+
private_constant :DATABASE_PATH_TEMPLATE
|
66
|
+
|
67
|
+
SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
68
|
+
"projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
|
69
|
+
)
|
70
|
+
|
71
|
+
private_constant :SESSION_PATH_TEMPLATE
|
72
|
+
|
73
|
+
# Returns a fully-qualified database resource name string.
|
74
|
+
# @param project [String]
|
75
|
+
# @param instance [String]
|
76
|
+
# @param database [String]
|
77
|
+
# @return [String]
|
78
|
+
def self.database_path project, instance, database
|
79
|
+
DATABASE_PATH_TEMPLATE.render(
|
80
|
+
:"project" => project,
|
81
|
+
:"instance" => instance,
|
82
|
+
:"database" => database
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns a fully-qualified session resource name string.
|
87
|
+
# @param project [String]
|
88
|
+
# @param instance [String]
|
89
|
+
# @param database [String]
|
90
|
+
# @param session [String]
|
91
|
+
# @return [String]
|
92
|
+
def self.session_path project, instance, database, session
|
93
|
+
SESSION_PATH_TEMPLATE.render(
|
94
|
+
:"project" => project,
|
95
|
+
:"instance" => instance,
|
96
|
+
:"database" => database,
|
97
|
+
:"session" => session
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Parses the project from a database resource.
|
102
|
+
# @param database_name [String]
|
103
|
+
# @return [String]
|
104
|
+
def self.match_project_from_database_name database_name
|
105
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["project"]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Parses the instance from a database resource.
|
109
|
+
# @param database_name [String]
|
110
|
+
# @return [String]
|
111
|
+
def self.match_instance_from_database_name database_name
|
112
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["instance"]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Parses the database from a database resource.
|
116
|
+
# @param database_name [String]
|
117
|
+
# @return [String]
|
118
|
+
def self.match_database_from_database_name database_name
|
119
|
+
DATABASE_PATH_TEMPLATE.match(database_name)["database"]
|
120
|
+
end
|
121
|
+
|
122
|
+
# Parses the project from a session resource.
|
123
|
+
# @param session_name [String]
|
124
|
+
# @return [String]
|
125
|
+
def self.match_project_from_session_name session_name
|
126
|
+
SESSION_PATH_TEMPLATE.match(session_name)["project"]
|
127
|
+
end
|
128
|
+
|
129
|
+
# Parses the instance from a session resource.
|
130
|
+
# @param session_name [String]
|
131
|
+
# @return [String]
|
132
|
+
def self.match_instance_from_session_name session_name
|
133
|
+
SESSION_PATH_TEMPLATE.match(session_name)["instance"]
|
134
|
+
end
|
135
|
+
|
136
|
+
# Parses the database from a session resource.
|
137
|
+
# @param session_name [String]
|
138
|
+
# @return [String]
|
139
|
+
def self.match_database_from_session_name session_name
|
140
|
+
SESSION_PATH_TEMPLATE.match(session_name)["database"]
|
141
|
+
end
|
142
|
+
|
143
|
+
# Parses the session from a session resource.
|
144
|
+
# @param session_name [String]
|
145
|
+
# @return [String]
|
146
|
+
def self.match_session_from_session_name session_name
|
147
|
+
SESSION_PATH_TEMPLATE.match(session_name)["session"]
|
148
|
+
end
|
149
|
+
|
150
|
+
# @param service_path [String]
|
151
|
+
# The domain name of the API remote host.
|
152
|
+
# @param port [Integer]
|
153
|
+
# The port on which to connect to the remote host.
|
154
|
+
# @param channel [Channel]
|
155
|
+
# A Channel object through which to make calls.
|
156
|
+
# @param chan_creds [Grpc::ChannelCredentials]
|
157
|
+
# A ChannelCredentials for the setting up the RPC client.
|
158
|
+
# @param client_config[Hash]
|
159
|
+
# A Hash for call options for each method. See
|
160
|
+
# Google::Gax#construct_settings for the structure of
|
161
|
+
# this data. Falls back to the default config if not specified
|
162
|
+
# or the specified config is missing data points.
|
163
|
+
# @param timeout [Numeric]
|
164
|
+
# The default timeout, in seconds, for calls made through this client.
|
165
|
+
def initialize \
|
166
|
+
service_path: SERVICE_ADDRESS,
|
167
|
+
port: DEFAULT_SERVICE_PORT,
|
168
|
+
channel: nil,
|
169
|
+
chan_creds: nil,
|
170
|
+
scopes: ALL_SCOPES,
|
171
|
+
client_config: {},
|
172
|
+
timeout: DEFAULT_TIMEOUT,
|
173
|
+
app_name: nil,
|
174
|
+
app_version: nil,
|
175
|
+
lib_name: nil,
|
176
|
+
lib_version: ""
|
177
|
+
# These require statements are intentionally placed here to initialize
|
178
|
+
# the gRPC module only when it's required.
|
179
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
180
|
+
require "google/gax/grpc"
|
181
|
+
require "google/spanner/v1/spanner_services_pb"
|
182
|
+
|
183
|
+
|
184
|
+
if app_name || app_version
|
185
|
+
warn "`app_name` and `app_version` are no longer being used in the request headers."
|
186
|
+
end
|
187
|
+
|
188
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
189
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
190
|
+
google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
|
191
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
192
|
+
google_api_client.freeze
|
193
|
+
|
194
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
195
|
+
client_config_file = Pathname.new(__dir__).join(
|
196
|
+
"spanner_client_config.json"
|
197
|
+
)
|
198
|
+
defaults = client_config_file.open do |f|
|
199
|
+
Google::Gax.construct_settings(
|
200
|
+
"google.spanner.v1.Spanner",
|
201
|
+
JSON.parse(f.read),
|
202
|
+
client_config,
|
203
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
204
|
+
timeout,
|
205
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
206
|
+
kwargs: headers
|
207
|
+
)
|
208
|
+
end
|
209
|
+
@spanner_stub = Google::Gax::Grpc.create_stub(
|
210
|
+
service_path,
|
211
|
+
port,
|
212
|
+
chan_creds: chan_creds,
|
213
|
+
channel: channel,
|
214
|
+
scopes: scopes,
|
215
|
+
&Google::Spanner::V1::Spanner::Stub.method(:new)
|
216
|
+
)
|
217
|
+
|
218
|
+
@create_session = Google::Gax.create_api_call(
|
219
|
+
@spanner_stub.method(:create_session),
|
220
|
+
defaults["create_session"]
|
221
|
+
)
|
222
|
+
@get_session = Google::Gax.create_api_call(
|
223
|
+
@spanner_stub.method(:get_session),
|
224
|
+
defaults["get_session"]
|
225
|
+
)
|
226
|
+
@delete_session = Google::Gax.create_api_call(
|
227
|
+
@spanner_stub.method(:delete_session),
|
228
|
+
defaults["delete_session"]
|
229
|
+
)
|
230
|
+
@execute_sql = Google::Gax.create_api_call(
|
231
|
+
@spanner_stub.method(:execute_sql),
|
232
|
+
defaults["execute_sql"]
|
233
|
+
)
|
234
|
+
@execute_streaming_sql = Google::Gax.create_api_call(
|
235
|
+
@spanner_stub.method(:execute_streaming_sql),
|
236
|
+
defaults["execute_streaming_sql"]
|
237
|
+
)
|
238
|
+
@read = Google::Gax.create_api_call(
|
239
|
+
@spanner_stub.method(:read),
|
240
|
+
defaults["read"]
|
241
|
+
)
|
242
|
+
@streaming_read = Google::Gax.create_api_call(
|
243
|
+
@spanner_stub.method(:streaming_read),
|
244
|
+
defaults["streaming_read"]
|
245
|
+
)
|
246
|
+
@begin_transaction = Google::Gax.create_api_call(
|
247
|
+
@spanner_stub.method(:begin_transaction),
|
248
|
+
defaults["begin_transaction"]
|
249
|
+
)
|
250
|
+
@commit = Google::Gax.create_api_call(
|
251
|
+
@spanner_stub.method(:commit),
|
252
|
+
defaults["commit"]
|
253
|
+
)
|
254
|
+
@rollback = Google::Gax.create_api_call(
|
255
|
+
@spanner_stub.method(:rollback),
|
256
|
+
defaults["rollback"]
|
257
|
+
)
|
258
|
+
end
|
259
|
+
|
260
|
+
# Service calls
|
261
|
+
|
262
|
+
# Creates a new session. A session can be used to perform
|
263
|
+
# transactions that read and/or modify data in a Cloud Spanner database.
|
264
|
+
# Sessions are meant to be reused for many consecutive
|
265
|
+
# transactions.
|
266
|
+
#
|
267
|
+
# Sessions can only execute one transaction at a time. To execute
|
268
|
+
# multiple concurrent read-write/write-only transactions, create
|
269
|
+
# multiple sessions. Note that standalone reads and queries use a
|
270
|
+
# transaction internally, and count toward the one transaction
|
271
|
+
# limit.
|
272
|
+
#
|
273
|
+
# Cloud Spanner limits the number of sessions that can exist at any given
|
274
|
+
# time; thus, it is a good idea to delete idle and/or unneeded sessions.
|
275
|
+
# Aside from explicit deletes, Cloud Spanner can delete sessions for which no
|
276
|
+
# operations are sent for more than an hour. If a session is deleted,
|
277
|
+
# requests to it return +NOT_FOUND+.
|
278
|
+
#
|
279
|
+
# Idle sessions can be kept alive by sending a trivial SQL query
|
280
|
+
# periodically, e.g., +"SELECT 1"+.
|
281
|
+
#
|
282
|
+
# @param database [String]
|
283
|
+
# Required. The database in which the new session is created.
|
284
|
+
# @param options [Google::Gax::CallOptions]
|
285
|
+
# Overrides the default settings for this call, e.g, timeout,
|
286
|
+
# retries, etc.
|
287
|
+
# @return [Google::Spanner::V1::Session]
|
288
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
289
|
+
# @example
|
290
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
291
|
+
#
|
292
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
293
|
+
#
|
294
|
+
# spanner_client = SpannerClient.new
|
295
|
+
# formatted_database = SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
296
|
+
# response = spanner_client.create_session(formatted_database)
|
297
|
+
|
298
|
+
def create_session \
|
299
|
+
database,
|
300
|
+
options: nil
|
301
|
+
req = Google::Spanner::V1::CreateSessionRequest.new({
|
302
|
+
database: database
|
303
|
+
}.delete_if { |_, v| v.nil? })
|
304
|
+
@create_session.call(req, options)
|
305
|
+
end
|
306
|
+
|
307
|
+
# Gets a session. Returns +NOT_FOUND+ if the session does not exist.
|
308
|
+
# This is mainly useful for determining whether a session is still
|
309
|
+
# alive.
|
310
|
+
#
|
311
|
+
# @param name [String]
|
312
|
+
# Required. The name of the session to retrieve.
|
313
|
+
# @param options [Google::Gax::CallOptions]
|
314
|
+
# Overrides the default settings for this call, e.g, timeout,
|
315
|
+
# retries, etc.
|
316
|
+
# @return [Google::Spanner::V1::Session]
|
317
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
318
|
+
# @example
|
319
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
320
|
+
#
|
321
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
322
|
+
#
|
323
|
+
# spanner_client = SpannerClient.new
|
324
|
+
# formatted_name = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
325
|
+
# response = spanner_client.get_session(formatted_name)
|
326
|
+
|
327
|
+
def get_session \
|
328
|
+
name,
|
329
|
+
options: nil
|
330
|
+
req = Google::Spanner::V1::GetSessionRequest.new({
|
331
|
+
name: name
|
332
|
+
}.delete_if { |_, v| v.nil? })
|
333
|
+
@get_session.call(req, options)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Ends a session, releasing server resources associated with it.
|
337
|
+
#
|
338
|
+
# @param name [String]
|
339
|
+
# Required. The name of the session to delete.
|
340
|
+
# @param options [Google::Gax::CallOptions]
|
341
|
+
# Overrides the default settings for this call, e.g, timeout,
|
342
|
+
# retries, etc.
|
343
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
344
|
+
# @example
|
345
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
346
|
+
#
|
347
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
348
|
+
#
|
349
|
+
# spanner_client = SpannerClient.new
|
350
|
+
# formatted_name = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
351
|
+
# spanner_client.delete_session(formatted_name)
|
352
|
+
|
353
|
+
def delete_session \
|
354
|
+
name,
|
355
|
+
options: nil
|
356
|
+
req = Google::Spanner::V1::DeleteSessionRequest.new({
|
357
|
+
name: name
|
358
|
+
}.delete_if { |_, v| v.nil? })
|
359
|
+
@delete_session.call(req, options)
|
360
|
+
nil
|
361
|
+
end
|
362
|
+
|
363
|
+
# Executes an SQL query, returning all rows in a single reply. This
|
364
|
+
# method cannot be used to return a result set larger than 10 MiB;
|
365
|
+
# if the query yields more data than that, the query fails with
|
366
|
+
# a +FAILED_PRECONDITION+ error.
|
367
|
+
#
|
368
|
+
# Queries inside read-write transactions might return +ABORTED+. If
|
369
|
+
# this occurs, the application should restart the transaction from
|
370
|
+
# the beginning. See Transaction for more details.
|
371
|
+
#
|
372
|
+
# Larger result sets can be fetched in streaming fashion by calling
|
373
|
+
# ExecuteStreamingSql instead.
|
374
|
+
#
|
375
|
+
# @param session [String]
|
376
|
+
# Required. The session in which the SQL query should be performed.
|
377
|
+
# @param sql [String]
|
378
|
+
# Required. The SQL query string.
|
379
|
+
# @param transaction [Google::Spanner::V1::TransactionSelector]
|
380
|
+
# The transaction to use. If none is provided, the default is a
|
381
|
+
# temporary read-only transaction with strong concurrency.
|
382
|
+
# @param params [Google::Protobuf::Struct]
|
383
|
+
# The SQL query string can contain parameter placeholders. A parameter
|
384
|
+
# placeholder consists of +'@'+ followed by the parameter
|
385
|
+
# name. Parameter names consist of any combination of letters,
|
386
|
+
# numbers, and underscores.
|
387
|
+
#
|
388
|
+
# Parameters can appear anywhere that a literal value is expected. The same
|
389
|
+
# parameter name can be used more than once, for example:
|
390
|
+
# +"WHERE id > @msg_id AND id < @msg_id + 100"+
|
391
|
+
#
|
392
|
+
# It is an error to execute an SQL query with unbound parameters.
|
393
|
+
#
|
394
|
+
# Parameter values are specified using +params+, which is a JSON
|
395
|
+
# object whose keys are parameter names, and whose values are the
|
396
|
+
# corresponding parameter values.
|
397
|
+
# @param param_types [Hash{String => Google::Spanner::V1::Type}]
|
398
|
+
# It is not always possible for Cloud Spanner to infer the right SQL type
|
399
|
+
# from a JSON value. For example, values of type +BYTES+ and values
|
400
|
+
# of type +STRING+ both appear in Params as JSON strings.
|
401
|
+
#
|
402
|
+
# In these cases, +param_types+ can be used to specify the exact
|
403
|
+
# SQL type for some or all of the SQL query parameters. See the
|
404
|
+
# definition of Type for more information
|
405
|
+
# about SQL types.
|
406
|
+
# @param resume_token [String]
|
407
|
+
# If this request is resuming a previously interrupted SQL query
|
408
|
+
# execution, +resume_token+ should be copied from the last
|
409
|
+
# PartialResultSet yielded before the interruption. Doing this
|
410
|
+
# enables the new SQL query execution to resume where the last one left
|
411
|
+
# off. The rest of the request parameters must exactly match the
|
412
|
+
# request that yielded this token.
|
413
|
+
# @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
|
414
|
+
# Used to control the amount of debugging information returned in
|
415
|
+
# ResultSetStats.
|
416
|
+
# @param options [Google::Gax::CallOptions]
|
417
|
+
# Overrides the default settings for this call, e.g, timeout,
|
418
|
+
# retries, etc.
|
419
|
+
# @return [Google::Spanner::V1::ResultSet]
|
420
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
421
|
+
# @example
|
422
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
423
|
+
#
|
424
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
425
|
+
#
|
426
|
+
# spanner_client = SpannerClient.new
|
427
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
428
|
+
# sql = ''
|
429
|
+
# response = spanner_client.execute_sql(formatted_session, sql)
|
430
|
+
|
431
|
+
def execute_sql \
|
432
|
+
session,
|
433
|
+
sql,
|
434
|
+
transaction: nil,
|
435
|
+
params: nil,
|
436
|
+
param_types: nil,
|
437
|
+
resume_token: nil,
|
438
|
+
query_mode: nil,
|
439
|
+
options: nil
|
440
|
+
req = Google::Spanner::V1::ExecuteSqlRequest.new({
|
441
|
+
session: session,
|
442
|
+
sql: sql,
|
443
|
+
transaction: transaction,
|
444
|
+
params: params,
|
445
|
+
param_types: param_types,
|
446
|
+
resume_token: resume_token,
|
447
|
+
query_mode: query_mode
|
448
|
+
}.delete_if { |_, v| v.nil? })
|
449
|
+
@execute_sql.call(req, options)
|
450
|
+
end
|
451
|
+
|
452
|
+
# Like ExecuteSql, except returns the result
|
453
|
+
# set as a stream. Unlike ExecuteSql, there
|
454
|
+
# is no limit on the size of the returned result set. However, no
|
455
|
+
# individual row in the result set can exceed 100 MiB, and no
|
456
|
+
# column value can exceed 10 MiB.
|
457
|
+
#
|
458
|
+
# @param session [String]
|
459
|
+
# Required. The session in which the SQL query should be performed.
|
460
|
+
# @param sql [String]
|
461
|
+
# Required. The SQL query string.
|
462
|
+
# @param transaction [Google::Spanner::V1::TransactionSelector]
|
463
|
+
# The transaction to use. If none is provided, the default is a
|
464
|
+
# temporary read-only transaction with strong concurrency.
|
465
|
+
# @param params [Google::Protobuf::Struct]
|
466
|
+
# The SQL query string can contain parameter placeholders. A parameter
|
467
|
+
# placeholder consists of +'@'+ followed by the parameter
|
468
|
+
# name. Parameter names consist of any combination of letters,
|
469
|
+
# numbers, and underscores.
|
470
|
+
#
|
471
|
+
# Parameters can appear anywhere that a literal value is expected. The same
|
472
|
+
# parameter name can be used more than once, for example:
|
473
|
+
# +"WHERE id > @msg_id AND id < @msg_id + 100"+
|
474
|
+
#
|
475
|
+
# It is an error to execute an SQL query with unbound parameters.
|
476
|
+
#
|
477
|
+
# Parameter values are specified using +params+, which is a JSON
|
478
|
+
# object whose keys are parameter names, and whose values are the
|
479
|
+
# corresponding parameter values.
|
480
|
+
# @param param_types [Hash{String => Google::Spanner::V1::Type}]
|
481
|
+
# It is not always possible for Cloud Spanner to infer the right SQL type
|
482
|
+
# from a JSON value. For example, values of type +BYTES+ and values
|
483
|
+
# of type +STRING+ both appear in Params as JSON strings.
|
484
|
+
#
|
485
|
+
# In these cases, +param_types+ can be used to specify the exact
|
486
|
+
# SQL type for some or all of the SQL query parameters. See the
|
487
|
+
# definition of Type for more information
|
488
|
+
# about SQL types.
|
489
|
+
# @param resume_token [String]
|
490
|
+
# If this request is resuming a previously interrupted SQL query
|
491
|
+
# execution, +resume_token+ should be copied from the last
|
492
|
+
# PartialResultSet yielded before the interruption. Doing this
|
493
|
+
# enables the new SQL query execution to resume where the last one left
|
494
|
+
# off. The rest of the request parameters must exactly match the
|
495
|
+
# request that yielded this token.
|
496
|
+
# @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
|
497
|
+
# Used to control the amount of debugging information returned in
|
498
|
+
# ResultSetStats.
|
499
|
+
# @param options [Google::Gax::CallOptions]
|
500
|
+
# Overrides the default settings for this call, e.g, timeout,
|
501
|
+
# retries, etc.
|
502
|
+
# @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
|
503
|
+
# An enumerable of Google::Spanner::V1::PartialResultSet instances.
|
504
|
+
#
|
505
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
506
|
+
# @example
|
507
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
508
|
+
#
|
509
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
510
|
+
#
|
511
|
+
# spanner_client = SpannerClient.new
|
512
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
513
|
+
# sql = ''
|
514
|
+
# spanner_client.execute_streaming_sql(formatted_session, sql).each do |element|
|
515
|
+
# # Process element.
|
516
|
+
# end
|
517
|
+
|
518
|
+
def execute_streaming_sql \
|
519
|
+
session,
|
520
|
+
sql,
|
521
|
+
transaction: nil,
|
522
|
+
params: nil,
|
523
|
+
param_types: nil,
|
524
|
+
resume_token: nil,
|
525
|
+
query_mode: nil,
|
526
|
+
options: nil
|
527
|
+
req = Google::Spanner::V1::ExecuteSqlRequest.new({
|
528
|
+
session: session,
|
529
|
+
sql: sql,
|
530
|
+
transaction: transaction,
|
531
|
+
params: params,
|
532
|
+
param_types: param_types,
|
533
|
+
resume_token: resume_token,
|
534
|
+
query_mode: query_mode
|
535
|
+
}.delete_if { |_, v| v.nil? })
|
536
|
+
@execute_streaming_sql.call(req, options)
|
537
|
+
end
|
538
|
+
|
539
|
+
# Reads rows from the database using key lookups and scans, as a
|
540
|
+
# simple key/value style alternative to
|
541
|
+
# ExecuteSql. This method cannot be used to
|
542
|
+
# return a result set larger than 10 MiB; if the read matches more
|
543
|
+
# data than that, the read fails with a +FAILED_PRECONDITION+
|
544
|
+
# error.
|
545
|
+
#
|
546
|
+
# Reads inside read-write transactions might return +ABORTED+. If
|
547
|
+
# this occurs, the application should restart the transaction from
|
548
|
+
# the beginning. See Transaction for more details.
|
549
|
+
#
|
550
|
+
# Larger result sets can be yielded in streaming fashion by calling
|
551
|
+
# StreamingRead instead.
|
552
|
+
#
|
553
|
+
# @param session [String]
|
554
|
+
# Required. The session in which the read should be performed.
|
555
|
+
# @param table [String]
|
556
|
+
# Required. The name of the table in the database to be read.
|
557
|
+
# @param columns [Array<String>]
|
558
|
+
# The columns of Table to be returned for each row matching
|
559
|
+
# this request.
|
560
|
+
# @param key_set [Google::Spanner::V1::KeySet]
|
561
|
+
# Required. +key_set+ identifies the rows to be yielded. +key_set+ names the
|
562
|
+
# primary keys of the rows in Table to be yielded, unless Index
|
563
|
+
# is present. If Index is present, then Key_set instead names
|
564
|
+
# index keys in Index.
|
565
|
+
#
|
566
|
+
# Rows are yielded in table primary key order (if Index is empty)
|
567
|
+
# or index key order (if Index is non-empty).
|
568
|
+
#
|
569
|
+
# It is not an error for the +key_set+ to name rows that do not
|
570
|
+
# exist in the database. Read yields nothing for nonexistent rows.
|
571
|
+
# @param transaction [Google::Spanner::V1::TransactionSelector]
|
572
|
+
# The transaction to use. If none is provided, the default is a
|
573
|
+
# temporary read-only transaction with strong concurrency.
|
574
|
+
# @param index [String]
|
575
|
+
# If non-empty, the name of an index on Table. This index is
|
576
|
+
# used instead of the table primary key when interpreting Key_set
|
577
|
+
# and sorting result rows. See Key_set for further information.
|
578
|
+
# @param limit [Integer]
|
579
|
+
# If greater than zero, only the first +limit+ rows are yielded. If +limit+
|
580
|
+
# is zero, the default is no limit.
|
581
|
+
# @param resume_token [String]
|
582
|
+
# If this request is resuming a previously interrupted read,
|
583
|
+
# +resume_token+ should be copied from the last
|
584
|
+
# PartialResultSet yielded before the interruption. Doing this
|
585
|
+
# enables the new read to resume where the last read left off. The
|
586
|
+
# rest of the request parameters must exactly match the request
|
587
|
+
# that yielded this token.
|
588
|
+
# @param options [Google::Gax::CallOptions]
|
589
|
+
# Overrides the default settings for this call, e.g, timeout,
|
590
|
+
# retries, etc.
|
591
|
+
# @return [Google::Spanner::V1::ResultSet]
|
592
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
593
|
+
# @example
|
594
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
595
|
+
#
|
596
|
+
# KeySet = Google::Spanner::V1::KeySet
|
597
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
598
|
+
#
|
599
|
+
# spanner_client = SpannerClient.new
|
600
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
601
|
+
# table = ''
|
602
|
+
# columns = []
|
603
|
+
# key_set = KeySet.new
|
604
|
+
# response = spanner_client.read(formatted_session, table, columns, key_set)
|
605
|
+
|
606
|
+
def read \
|
607
|
+
session,
|
608
|
+
table,
|
609
|
+
columns,
|
610
|
+
key_set,
|
611
|
+
transaction: nil,
|
612
|
+
index: nil,
|
613
|
+
limit: nil,
|
614
|
+
resume_token: nil,
|
615
|
+
options: nil
|
616
|
+
req = Google::Spanner::V1::ReadRequest.new({
|
617
|
+
session: session,
|
618
|
+
table: table,
|
619
|
+
columns: columns,
|
620
|
+
key_set: key_set,
|
621
|
+
transaction: transaction,
|
622
|
+
index: index,
|
623
|
+
limit: limit,
|
624
|
+
resume_token: resume_token
|
625
|
+
}.delete_if { |_, v| v.nil? })
|
626
|
+
@read.call(req, options)
|
627
|
+
end
|
628
|
+
|
629
|
+
# Like Read, except returns the result set as a
|
630
|
+
# stream. Unlike Read, there is no limit on the
|
631
|
+
# size of the returned result set. However, no individual row in
|
632
|
+
# the result set can exceed 100 MiB, and no column value can exceed
|
633
|
+
# 10 MiB.
|
634
|
+
#
|
635
|
+
# @param session [String]
|
636
|
+
# Required. The session in which the read should be performed.
|
637
|
+
# @param table [String]
|
638
|
+
# Required. The name of the table in the database to be read.
|
639
|
+
# @param columns [Array<String>]
|
640
|
+
# The columns of Table to be returned for each row matching
|
641
|
+
# this request.
|
642
|
+
# @param key_set [Google::Spanner::V1::KeySet]
|
643
|
+
# Required. +key_set+ identifies the rows to be yielded. +key_set+ names the
|
644
|
+
# primary keys of the rows in Table to be yielded, unless Index
|
645
|
+
# is present. If Index is present, then Key_set instead names
|
646
|
+
# index keys in Index.
|
647
|
+
#
|
648
|
+
# Rows are yielded in table primary key order (if Index is empty)
|
649
|
+
# or index key order (if Index is non-empty).
|
650
|
+
#
|
651
|
+
# It is not an error for the +key_set+ to name rows that do not
|
652
|
+
# exist in the database. Read yields nothing for nonexistent rows.
|
653
|
+
# @param transaction [Google::Spanner::V1::TransactionSelector]
|
654
|
+
# The transaction to use. If none is provided, the default is a
|
655
|
+
# temporary read-only transaction with strong concurrency.
|
656
|
+
# @param index [String]
|
657
|
+
# If non-empty, the name of an index on Table. This index is
|
658
|
+
# used instead of the table primary key when interpreting Key_set
|
659
|
+
# and sorting result rows. See Key_set for further information.
|
660
|
+
# @param limit [Integer]
|
661
|
+
# If greater than zero, only the first +limit+ rows are yielded. If +limit+
|
662
|
+
# is zero, the default is no limit.
|
663
|
+
# @param resume_token [String]
|
664
|
+
# If this request is resuming a previously interrupted read,
|
665
|
+
# +resume_token+ should be copied from the last
|
666
|
+
# PartialResultSet yielded before the interruption. Doing this
|
667
|
+
# enables the new read to resume where the last read left off. The
|
668
|
+
# rest of the request parameters must exactly match the request
|
669
|
+
# that yielded this token.
|
670
|
+
# @param options [Google::Gax::CallOptions]
|
671
|
+
# Overrides the default settings for this call, e.g, timeout,
|
672
|
+
# retries, etc.
|
673
|
+
# @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
|
674
|
+
# An enumerable of Google::Spanner::V1::PartialResultSet instances.
|
675
|
+
#
|
676
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
677
|
+
# @example
|
678
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
679
|
+
#
|
680
|
+
# KeySet = Google::Spanner::V1::KeySet
|
681
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
682
|
+
#
|
683
|
+
# spanner_client = SpannerClient.new
|
684
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
685
|
+
# table = ''
|
686
|
+
# columns = []
|
687
|
+
# key_set = KeySet.new
|
688
|
+
# spanner_client.streaming_read(formatted_session, table, columns, key_set).each do |element|
|
689
|
+
# # Process element.
|
690
|
+
# end
|
691
|
+
|
692
|
+
def streaming_read \
|
693
|
+
session,
|
694
|
+
table,
|
695
|
+
columns,
|
696
|
+
key_set,
|
697
|
+
transaction: nil,
|
698
|
+
index: nil,
|
699
|
+
limit: nil,
|
700
|
+
resume_token: nil,
|
701
|
+
options: nil
|
702
|
+
req = Google::Spanner::V1::ReadRequest.new({
|
703
|
+
session: session,
|
704
|
+
table: table,
|
705
|
+
columns: columns,
|
706
|
+
key_set: key_set,
|
707
|
+
transaction: transaction,
|
708
|
+
index: index,
|
709
|
+
limit: limit,
|
710
|
+
resume_token: resume_token
|
711
|
+
}.delete_if { |_, v| v.nil? })
|
712
|
+
@streaming_read.call(req, options)
|
713
|
+
end
|
714
|
+
|
715
|
+
# Begins a new transaction. This step can often be skipped:
|
716
|
+
# Read, ExecuteSql and
|
717
|
+
# Commit can begin a new transaction as a
|
718
|
+
# side-effect.
|
719
|
+
#
|
720
|
+
# @param session [String]
|
721
|
+
# Required. The session in which the transaction runs.
|
722
|
+
# @param options_ [Google::Spanner::V1::TransactionOptions]
|
723
|
+
# Required. Options for the new transaction.
|
724
|
+
# @param options [Google::Gax::CallOptions]
|
725
|
+
# Overrides the default settings for this call, e.g, timeout,
|
726
|
+
# retries, etc.
|
727
|
+
# @return [Google::Spanner::V1::Transaction]
|
728
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
729
|
+
# @example
|
730
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
731
|
+
#
|
732
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
733
|
+
# TransactionOptions = Google::Spanner::V1::TransactionOptions
|
734
|
+
#
|
735
|
+
# spanner_client = SpannerClient.new
|
736
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
737
|
+
# options_ = TransactionOptions.new
|
738
|
+
# response = spanner_client.begin_transaction(formatted_session, options_)
|
739
|
+
|
740
|
+
def begin_transaction \
|
741
|
+
session,
|
742
|
+
options_,
|
743
|
+
options: nil
|
744
|
+
req = Google::Spanner::V1::BeginTransactionRequest.new({
|
745
|
+
session: session,
|
746
|
+
options: options_
|
747
|
+
}.delete_if { |_, v| v.nil? })
|
748
|
+
@begin_transaction.call(req, options)
|
749
|
+
end
|
750
|
+
|
751
|
+
# Commits a transaction. The request includes the mutations to be
|
752
|
+
# applied to rows in the database.
|
753
|
+
#
|
754
|
+
# +Commit+ might return an +ABORTED+ error. This can occur at any time;
|
755
|
+
# commonly, the cause is conflicts with concurrent
|
756
|
+
# transactions. However, it can also happen for a variety of other
|
757
|
+
# reasons. If +Commit+ returns +ABORTED+, the caller should re-attempt
|
758
|
+
# the transaction from the beginning, re-using the same session.
|
759
|
+
#
|
760
|
+
# @param session [String]
|
761
|
+
# Required. The session in which the transaction to be committed is running.
|
762
|
+
# @param mutations [Array<Google::Spanner::V1::Mutation>]
|
763
|
+
# The mutations to be executed when this transaction commits. All
|
764
|
+
# mutations are applied atomically, in the order they appear in
|
765
|
+
# this list.
|
766
|
+
# @param transaction_id [String]
|
767
|
+
# Commit a previously-started transaction.
|
768
|
+
# @param single_use_transaction [Google::Spanner::V1::TransactionOptions]
|
769
|
+
# Execute mutations in a temporary transaction. Note that unlike
|
770
|
+
# commit of a previously-started transaction, commit with a
|
771
|
+
# temporary transaction is non-idempotent. That is, if the
|
772
|
+
# +CommitRequest+ is sent to Cloud Spanner more than once (for
|
773
|
+
# instance, due to retries in the application, or in the
|
774
|
+
# transport library), it is possible that the mutations are
|
775
|
+
# executed more than once. If this is undesirable, use
|
776
|
+
# BeginTransaction and
|
777
|
+
# Commit instead.
|
778
|
+
# @param options [Google::Gax::CallOptions]
|
779
|
+
# Overrides the default settings for this call, e.g, timeout,
|
780
|
+
# retries, etc.
|
781
|
+
# @return [Google::Spanner::V1::CommitResponse]
|
782
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
783
|
+
# @example
|
784
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
785
|
+
#
|
786
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
787
|
+
#
|
788
|
+
# spanner_client = SpannerClient.new
|
789
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
790
|
+
# mutations = []
|
791
|
+
# response = spanner_client.commit(formatted_session, mutations)
|
792
|
+
|
793
|
+
def commit \
|
794
|
+
session,
|
795
|
+
mutations,
|
796
|
+
transaction_id: nil,
|
797
|
+
single_use_transaction: nil,
|
798
|
+
options: nil
|
799
|
+
req = Google::Spanner::V1::CommitRequest.new({
|
800
|
+
session: session,
|
801
|
+
mutations: mutations,
|
802
|
+
transaction_id: transaction_id,
|
803
|
+
single_use_transaction: single_use_transaction
|
804
|
+
}.delete_if { |_, v| v.nil? })
|
805
|
+
@commit.call(req, options)
|
806
|
+
end
|
807
|
+
|
808
|
+
# Rolls back a transaction, releasing any locks it holds. It is a good
|
809
|
+
# idea to call this for any transaction that includes one or more
|
810
|
+
# Read or ExecuteSql requests and
|
811
|
+
# ultimately decides not to commit.
|
812
|
+
#
|
813
|
+
# +Rollback+ returns +OK+ if it successfully aborts the transaction, the
|
814
|
+
# transaction was already aborted, or the transaction is not
|
815
|
+
# found. +Rollback+ never returns +ABORTED+.
|
816
|
+
#
|
817
|
+
# @param session [String]
|
818
|
+
# Required. The session in which the transaction to roll back is running.
|
819
|
+
# @param transaction_id [String]
|
820
|
+
# Required. The transaction to roll back.
|
821
|
+
# @param options [Google::Gax::CallOptions]
|
822
|
+
# Overrides the default settings for this call, e.g, timeout,
|
823
|
+
# retries, etc.
|
824
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
825
|
+
# @example
|
826
|
+
# require "google/cloud/spanner/v1/spanner_client"
|
827
|
+
#
|
828
|
+
# SpannerClient = Google::Cloud::Spanner::V1::SpannerClient
|
829
|
+
#
|
830
|
+
# spanner_client = SpannerClient.new
|
831
|
+
# formatted_session = SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
|
832
|
+
# transaction_id = ''
|
833
|
+
# spanner_client.rollback(formatted_session, transaction_id)
|
834
|
+
|
835
|
+
def rollback \
|
836
|
+
session,
|
837
|
+
transaction_id,
|
838
|
+
options: nil
|
839
|
+
req = Google::Spanner::V1::RollbackRequest.new({
|
840
|
+
session: session,
|
841
|
+
transaction_id: transaction_id
|
842
|
+
}.delete_if { |_, v| v.nil? })
|
843
|
+
@rollback.call(req, options)
|
844
|
+
nil
|
845
|
+
end
|
846
|
+
end
|
847
|
+
end
|
848
|
+
end
|
849
|
+
end
|
850
|
+
end
|