google-cloud-spanner 2.6.0 → 2.9.0
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.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +43 -0
- data/OVERVIEW.md +1 -1
- data/lib/google-cloud-spanner.rb +2 -0
- data/lib/google/cloud/spanner/batch_snapshot.rb +9 -2
- data/lib/google/cloud/spanner/client.rb +506 -66
- data/lib/google/cloud/spanner/commit.rb +4 -0
- data/lib/google/cloud/spanner/convert.rb +19 -0
- data/lib/google/cloud/spanner/database.rb +7 -0
- data/lib/google/cloud/spanner/fields.rb +2 -1
- data/lib/google/cloud/spanner/instance.rb +61 -1
- data/lib/google/cloud/spanner/project.rb +33 -3
- data/lib/google/cloud/spanner/results.rb +7 -3
- data/lib/google/cloud/spanner/service.rb +33 -17
- data/lib/google/cloud/spanner/session.rb +186 -10
- data/lib/google/cloud/spanner/snapshot.rb +10 -2
- data/lib/google/cloud/spanner/transaction.rb +98 -7
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +3 -3
@@ -69,6 +69,7 @@ module Google
|
|
69
69
|
# | `BOOL` | `true`/`false` | |
|
70
70
|
# | `INT64` | `Integer` | |
|
71
71
|
# | `FLOAT64` | `Float` | |
|
72
|
+
# | `NUMERIC` | `BigDecimal` | |
|
72
73
|
# | `STRING` | `String` | |
|
73
74
|
# | `DATE` | `Date` | |
|
74
75
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -127,6 +128,7 @@ module Google
|
|
127
128
|
# | `BOOL` | `true`/`false` | |
|
128
129
|
# | `INT64` | `Integer` | |
|
129
130
|
# | `FLOAT64` | `Float` | |
|
131
|
+
# | `NUMERIC` | `BigDecimal` | |
|
130
132
|
# | `STRING` | `String` | |
|
131
133
|
# | `DATE` | `Date` | |
|
132
134
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -184,6 +186,7 @@ module Google
|
|
184
186
|
# | `BOOL` | `true`/`false` | |
|
185
187
|
# | `INT64` | `Integer` | |
|
186
188
|
# | `FLOAT64` | `Float` | |
|
189
|
+
# | `NUMERIC` | `BigDecimal` | |
|
187
190
|
# | `STRING` | `String` | |
|
188
191
|
# | `DATE` | `Date` | |
|
189
192
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -243,6 +246,7 @@ module Google
|
|
243
246
|
# | `BOOL` | `true`/`false` | |
|
244
247
|
# | `INT64` | `Integer` | |
|
245
248
|
# | `FLOAT64` | `Float` | |
|
249
|
+
# | `NUMERIC` | `BigDecimal` | |
|
246
250
|
# | `STRING` | `String` | |
|
247
251
|
# | `DATE` | `Date` | |
|
248
252
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -324,6 +324,25 @@ module Google
|
|
324
324
|
|
325
325
|
[input_params, input_param_types]
|
326
326
|
end
|
327
|
+
|
328
|
+
##
|
329
|
+
# Build request options by replacing tag to respecitve statistics
|
330
|
+
# collection tag type.
|
331
|
+
#
|
332
|
+
# @param [Hash] options Common request options.
|
333
|
+
# * `:tag` (String) A tag used for statistics collection.
|
334
|
+
#
|
335
|
+
# @param [Symbol] tag_type Request tag type.
|
336
|
+
# Possible values are `request_tag`, `transaction_tag`
|
337
|
+
# @return [Hash, nil]
|
338
|
+
#
|
339
|
+
def to_request_options options, tag_type: nil
|
340
|
+
return unless options
|
341
|
+
|
342
|
+
return options unless options.key? :tag
|
343
|
+
|
344
|
+
options.transform_keys { |k| k == :tag ? tag_type : k }
|
345
|
+
end
|
327
346
|
end
|
328
347
|
|
329
348
|
# rubocop:enable all
|
@@ -113,6 +113,13 @@ module Google
|
|
113
113
|
@grpc.state
|
114
114
|
end
|
115
115
|
|
116
|
+
##
|
117
|
+
# Time at which the database creation started.
|
118
|
+
# @return [Time]
|
119
|
+
def create_time
|
120
|
+
Convert.timestamp_to_time @grpc.create_time
|
121
|
+
end
|
122
|
+
|
116
123
|
# An encryption configuration describing the encryption type and key
|
117
124
|
# resources in Cloud KMS.
|
118
125
|
#
|
@@ -57,12 +57,13 @@ module Google
|
|
57
57
|
# Hash values must contain the type value. If a Hash is used the
|
58
58
|
# fields will be created using the same order as the Hash keys.
|
59
59
|
#
|
60
|
-
# Supported type values
|
60
|
+
# Supported type values include:
|
61
61
|
#
|
62
62
|
# * `:BOOL`
|
63
63
|
# * `:BYTES`
|
64
64
|
# * `:DATE`
|
65
65
|
# * `:FLOAT64`
|
66
|
+
# * `:NUMERIC`
|
66
67
|
# * `:INT64`
|
67
68
|
# * `:STRING`
|
68
69
|
# * `:TIMESTAMP`
|
@@ -68,6 +68,7 @@ module Google
|
|
68
68
|
def initialize grpc, service
|
69
69
|
@grpc = grpc
|
70
70
|
@service = service
|
71
|
+
@current_values = grpc.to_h
|
71
72
|
end
|
72
73
|
|
73
74
|
# The unique identifier for the project.
|
@@ -134,6 +135,23 @@ module Google
|
|
134
135
|
end
|
135
136
|
alias node_count= nodes=
|
136
137
|
|
138
|
+
##
|
139
|
+
# The number of processing units allocated to this instance.
|
140
|
+
#
|
141
|
+
# @return [Integer]
|
142
|
+
def processing_units
|
143
|
+
@grpc.processing_units
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Updates number of processing units allocated to this instance.
|
148
|
+
#
|
149
|
+
# @param units [Integer] The number of processing units allocated
|
150
|
+
# to this instance.
|
151
|
+
def processing_units= units
|
152
|
+
@grpc.processing_units = units
|
153
|
+
end
|
154
|
+
|
137
155
|
##
|
138
156
|
# The current instance state. Possible values are `:CREATING` and
|
139
157
|
# `:READY`.
|
@@ -188,8 +206,50 @@ module Google
|
|
188
206
|
)
|
189
207
|
end
|
190
208
|
|
209
|
+
##
|
210
|
+
# Update changes.
|
211
|
+
# `display_name`, `labels`, `nodes`, `processing_units` can be
|
212
|
+
# updated. `processing_units` and `nodes` can be used interchangeably
|
213
|
+
# to update.
|
214
|
+
#
|
215
|
+
# @return [Instance::Job] The job representing the long-running,
|
216
|
+
# asynchronous processing of an instance update operation.
|
217
|
+
# @raise [ArgumentError] if both processing_units or nodes are specified.
|
218
|
+
#
|
219
|
+
# @example
|
220
|
+
# require "google/cloud/spanner"
|
221
|
+
#
|
222
|
+
# spanner = Google::Cloud::Spanner.new
|
223
|
+
#
|
224
|
+
# instance = spanner.instance "my-instance"
|
225
|
+
# instance.display_name = "prod-instance"
|
226
|
+
# instance.labels = { env: "prod", app: "api" }
|
227
|
+
# instance.nodes = 2
|
228
|
+
# # OR
|
229
|
+
# # instance.processing_units = 500
|
230
|
+
#
|
231
|
+
# job = instance.save
|
232
|
+
#
|
233
|
+
# job.done? #=> false
|
234
|
+
# job.reload! # API call
|
235
|
+
# job.done? #=> true
|
236
|
+
#
|
237
|
+
# if job.error?
|
238
|
+
# status = job.error
|
239
|
+
# else
|
240
|
+
# instance = job.instance
|
241
|
+
# end
|
242
|
+
#
|
191
243
|
def save
|
192
|
-
|
244
|
+
ensure_service!
|
245
|
+
|
246
|
+
field_mask = []
|
247
|
+
@current_values.each do |field, value|
|
248
|
+
field_mask << field unless @grpc[field.to_s] == value
|
249
|
+
end
|
250
|
+
|
251
|
+
job_grpc = service.update_instance @grpc, field_mask: field_mask
|
252
|
+
@current_values = @grpc.to_h
|
193
253
|
Instance::Job.from_grpc job_grpc, service
|
194
254
|
end
|
195
255
|
alias update save
|
@@ -177,7 +177,10 @@ module Google
|
|
177
177
|
# configuration. Values can be the `instance_config_id`, the full
|
178
178
|
# path, or an {Instance::Config} object. Required.
|
179
179
|
# @param [Integer] nodes The number of nodes allocated to this instance.
|
180
|
-
#
|
180
|
+
# Optional. Specify either `nodes` or `processing_units`
|
181
|
+
# @param [Integer] processing_units The number of processing units
|
182
|
+
# allocated to this instance. Optional. Specify either `nodes`
|
183
|
+
# or `processing_units`
|
181
184
|
# @param [Hash] labels Cloud Labels are a flexible and lightweight
|
182
185
|
# mechanism for organizing cloud resources into groups that reflect a
|
183
186
|
# customer's organizational needs and deployment strategies. Cloud
|
@@ -195,6 +198,7 @@ module Google
|
|
195
198
|
#
|
196
199
|
# @return [Instance::Job] The job representing the long-running,
|
197
200
|
# asynchronous processing of an instance create operation.
|
201
|
+
# @raise [ArgumentError] if both processing_units or nodes are specified.
|
198
202
|
#
|
199
203
|
# @example
|
200
204
|
# require "google/cloud/spanner"
|
@@ -217,14 +221,36 @@ module Google
|
|
217
221
|
# instance = job.instance
|
218
222
|
# end
|
219
223
|
#
|
224
|
+
# @example Create instance using processsing units
|
225
|
+
# require "google/cloud/spanner"
|
226
|
+
#
|
227
|
+
# spanner = Google::Cloud::Spanner.new
|
228
|
+
#
|
229
|
+
# job = spanner.create_instance "my-new-instance",
|
230
|
+
# name: "My New Instance",
|
231
|
+
# config: "regional-us-central1",
|
232
|
+
# processing_units: 500,
|
233
|
+
# labels: { production: :env }
|
234
|
+
#
|
235
|
+
# job.done? #=> false
|
236
|
+
# job.reload! # API call
|
237
|
+
# job.done? #=> true
|
238
|
+
#
|
239
|
+
# if job.error?
|
240
|
+
# status = job.error
|
241
|
+
# else
|
242
|
+
# instance = job.instance
|
243
|
+
# end
|
244
|
+
#
|
220
245
|
def create_instance instance_id, name: nil, config: nil, nodes: nil,
|
221
|
-
labels: nil
|
246
|
+
processing_units: nil, labels: nil
|
222
247
|
config = config.path if config.respond_to? :path
|
248
|
+
|
223
249
|
# Convert from possible Google::Protobuf::Map
|
224
250
|
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
225
251
|
grpc = service.create_instance \
|
226
252
|
instance_id, name: name, config: config, nodes: nodes,
|
227
|
-
labels: labels
|
253
|
+
processing_units: processing_units, labels: labels
|
228
254
|
Instance::Job.from_grpc grpc, service
|
229
255
|
end
|
230
256
|
|
@@ -490,6 +516,8 @@ module Google
|
|
490
516
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
491
517
|
# Empty to use database default. "latest" to use the latest
|
492
518
|
# available optimizer version.
|
519
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
520
|
+
# use. Empty to use the database default.
|
493
521
|
#
|
494
522
|
# @return [Client] The newly created client.
|
495
523
|
#
|
@@ -554,6 +582,8 @@ module Google
|
|
554
582
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
555
583
|
# Empty to use database default. "latest" to use the latest
|
556
584
|
# available optimizer version.
|
585
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
586
|
+
# use. Empty to use the database default.
|
557
587
|
#
|
558
588
|
# @return [Client] The newly created client.
|
559
589
|
#
|
@@ -319,11 +319,13 @@ module Google
|
|
319
319
|
def self.execute_query service, session_path, sql, params: nil,
|
320
320
|
types: nil, transaction: nil,
|
321
321
|
partition_token: nil, seqno: nil,
|
322
|
-
query_options: nil,
|
322
|
+
query_options: nil, request_options: nil,
|
323
|
+
call_options: nil
|
323
324
|
execute_query_options = {
|
324
325
|
transaction: transaction, params: params, types: types,
|
325
326
|
partition_token: partition_token, seqno: seqno,
|
326
|
-
query_options: query_options,
|
327
|
+
query_options: query_options, request_options: request_options,
|
328
|
+
call_options: call_options
|
327
329
|
}
|
328
330
|
enum = service.execute_streaming_sql session_path, sql,
|
329
331
|
**execute_query_options
|
@@ -338,11 +340,13 @@ module Google
|
|
338
340
|
# @private
|
339
341
|
def self.read service, session_path, table, columns, keys: nil,
|
340
342
|
index: nil, limit: nil, transaction: nil,
|
341
|
-
partition_token: nil,
|
343
|
+
partition_token: nil, request_options: nil,
|
344
|
+
call_options: nil
|
342
345
|
read_options = {
|
343
346
|
keys: keys, index: index, limit: limit,
|
344
347
|
transaction: transaction,
|
345
348
|
partition_token: partition_token,
|
349
|
+
request_options: request_options,
|
346
350
|
call_options: call_options
|
347
351
|
}
|
348
352
|
enum = service.streaming_read_table \
|
@@ -127,13 +127,15 @@ module Google
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def create_instance instance_id, name: nil, config: nil, nodes: nil,
|
130
|
-
|
130
|
+
processing_units: nil, labels: nil,
|
131
|
+
call_options: nil
|
131
132
|
opts = default_options call_options: call_options
|
132
133
|
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
133
134
|
|
134
135
|
create_obj = Admin::Instance::V1::Instance.new({
|
135
136
|
display_name: name, config: instance_config_path(config),
|
136
|
-
node_count: nodes,
|
137
|
+
node_count: nodes, processing_units: processing_units,
|
138
|
+
labels: labels
|
137
139
|
}.delete_if { |_, v| v.nil? })
|
138
140
|
|
139
141
|
request = {
|
@@ -144,12 +146,17 @@ module Google
|
|
144
146
|
instances.create_instance request, opts
|
145
147
|
end
|
146
148
|
|
147
|
-
def update_instance instance, call_options: nil
|
149
|
+
def update_instance instance, field_mask: nil, call_options: nil
|
148
150
|
opts = default_options call_options: call_options
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
|
152
|
+
if field_mask.nil? || field_mask.empty?
|
153
|
+
field_mask = %w[display_name node_count labels]
|
154
|
+
end
|
155
|
+
|
156
|
+
request = {
|
157
|
+
instance: instance,
|
158
|
+
field_mask: Google::Protobuf::FieldMask.new(paths: field_mask)
|
159
|
+
}
|
153
160
|
instances.update_instance request, opts
|
154
161
|
end
|
155
162
|
|
@@ -313,7 +320,8 @@ module Google
|
|
313
320
|
def execute_streaming_sql session_name, sql, transaction: nil,
|
314
321
|
params: nil, types: nil, resume_token: nil,
|
315
322
|
partition_token: nil, seqno: nil,
|
316
|
-
query_options: nil,
|
323
|
+
query_options: nil, request_options: nil,
|
324
|
+
call_options: nil
|
317
325
|
opts = default_options session_name: session_name,
|
318
326
|
call_options: call_options
|
319
327
|
request = {
|
@@ -325,13 +333,14 @@ module Google
|
|
325
333
|
resume_token: resume_token,
|
326
334
|
partition_token: partition_token,
|
327
335
|
seqno: seqno,
|
328
|
-
query_options: query_options
|
336
|
+
query_options: query_options,
|
337
|
+
request_options: request_options
|
329
338
|
}
|
330
339
|
service.execute_streaming_sql request, opts
|
331
340
|
end
|
332
341
|
|
333
342
|
def execute_batch_dml session_name, transaction, statements, seqno,
|
334
|
-
call_options: nil
|
343
|
+
request_options: nil, call_options: nil
|
335
344
|
opts = default_options session_name: session_name,
|
336
345
|
call_options: call_options
|
337
346
|
statements = statements.map(&:to_grpc)
|
@@ -339,7 +348,8 @@ module Google
|
|
339
348
|
session: session_name,
|
340
349
|
transaction: transaction,
|
341
350
|
statements: statements,
|
342
|
-
seqno: seqno
|
351
|
+
seqno: seqno,
|
352
|
+
request_options: request_options
|
343
353
|
}
|
344
354
|
results = service.execute_batch_dml request, opts
|
345
355
|
|
@@ -357,14 +367,14 @@ module Google
|
|
357
367
|
def streaming_read_table session_name, table_name, columns, keys: nil,
|
358
368
|
index: nil, transaction: nil, limit: nil,
|
359
369
|
resume_token: nil, partition_token: nil,
|
360
|
-
call_options: nil
|
370
|
+
request_options: nil, call_options: nil
|
361
371
|
opts = default_options session_name: session_name,
|
362
372
|
call_options: call_options
|
363
373
|
request = {
|
364
374
|
session: session_name, table: table_name, columns: columns,
|
365
375
|
key_set: keys, transaction: transaction, index: index,
|
366
376
|
limit: limit, resume_token: resume_token,
|
367
|
-
partition_token: partition_token
|
377
|
+
partition_token: partition_token, request_options: request_options
|
368
378
|
}
|
369
379
|
service.streaming_read request, opts
|
370
380
|
end
|
@@ -402,7 +412,7 @@ module Google
|
|
402
412
|
end
|
403
413
|
|
404
414
|
def commit session_name, mutations = [], transaction_id: nil,
|
405
|
-
commit_options: nil, call_options: nil
|
415
|
+
commit_options: nil, request_options: nil, call_options: nil
|
406
416
|
tx_opts = nil
|
407
417
|
if transaction_id.nil?
|
408
418
|
tx_opts = V1::TransactionOptions.new(
|
@@ -413,7 +423,8 @@ module Google
|
|
413
423
|
call_options: call_options
|
414
424
|
request = {
|
415
425
|
session: session_name, transaction_id: transaction_id,
|
416
|
-
single_use_transaction: tx_opts, mutations: mutations
|
426
|
+
single_use_transaction: tx_opts, mutations: mutations,
|
427
|
+
request_options: request_options
|
417
428
|
}
|
418
429
|
|
419
430
|
if commit_options
|
@@ -430,13 +441,18 @@ module Google
|
|
430
441
|
service.rollback request, opts
|
431
442
|
end
|
432
443
|
|
433
|
-
def begin_transaction session_name,
|
444
|
+
def begin_transaction session_name, request_options: nil,
|
445
|
+
call_options: nil
|
434
446
|
tx_opts = V1::TransactionOptions.new(
|
435
447
|
read_write: V1::TransactionOptions::ReadWrite.new
|
436
448
|
)
|
437
449
|
opts = default_options session_name: session_name,
|
438
450
|
call_options: call_options
|
439
|
-
request = {
|
451
|
+
request = {
|
452
|
+
session: session_name,
|
453
|
+
options: tx_opts,
|
454
|
+
request_options: request_options
|
455
|
+
}
|
440
456
|
service.begin_transaction request, opts
|
441
457
|
end
|
442
458
|
|
@@ -116,6 +116,7 @@ module Google
|
|
116
116
|
# | `BOOL` | `true`/`false` | |
|
117
117
|
# | `INT64` | `Integer` | |
|
118
118
|
# | `FLOAT64` | `Float` | |
|
119
|
+
# | `NUMERIC` | `BigDecimal` | |
|
119
120
|
# | `STRING` | `String` | |
|
120
121
|
# | `DATE` | `Date` | |
|
121
122
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -141,6 +142,7 @@ module Google
|
|
141
142
|
# * `:BYTES`
|
142
143
|
# * `:DATE`
|
143
144
|
# * `:FLOAT64`
|
145
|
+
# * `:NUMERIC`
|
144
146
|
# * `:INT64`
|
145
147
|
# * `:STRING`
|
146
148
|
# * `:TIMESTAMP`
|
@@ -163,6 +165,25 @@ module Google
|
|
163
165
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
164
166
|
# Empty to use database default. "latest" to use the latest
|
165
167
|
# available optimizer version.
|
168
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
169
|
+
# use. Empty to use the database default.
|
170
|
+
# @param [Hash] request_options Common request options.
|
171
|
+
#
|
172
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
173
|
+
# to queries or reads, used for statistics collection. Both
|
174
|
+
# request_tag and transaction_tag can be specified for a read or
|
175
|
+
# query that belongs to a transaction. This field is ignored for
|
176
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
177
|
+
# `request_tag` must be a valid identifier of the form:
|
178
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
179
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
180
|
+
# about this transaction. Both request_tag and transaction_tag can
|
181
|
+
# be specified for a read or query that belongs to a transaction.
|
182
|
+
# The value of transaction_tag should be the same for all requests
|
183
|
+
# belonging to the same transaction. If this request doesn't belong
|
184
|
+
# to any transaction, transaction_tag will be ignored.
|
185
|
+
# `transaction_tag` must be a valid identifier of the format:
|
186
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
166
187
|
# @param [Hash] call_options A hash of values to specify the custom
|
167
188
|
# call options, e.g., timeout, retries, etc. Call options are
|
168
189
|
# optional. The following settings can be provided:
|
@@ -283,7 +304,10 @@ module Google
|
|
283
304
|
# db = spanner.client "my-instance", "my-database"
|
284
305
|
#
|
285
306
|
# results = db.execute_query \
|
286
|
-
# "SELECT * FROM users", query_options: {
|
307
|
+
# "SELECT * FROM users", query_options: {
|
308
|
+
# optimizer_version: "1",
|
309
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
310
|
+
# }
|
287
311
|
#
|
288
312
|
# results.rows.each do |row|
|
289
313
|
# puts "User #{row[:id]} is #{row[:name]}"
|
@@ -314,7 +338,7 @@ module Google
|
|
314
338
|
#
|
315
339
|
def execute_query sql, params: nil, types: nil, transaction: nil,
|
316
340
|
partition_token: nil, seqno: nil, query_options: nil,
|
317
|
-
call_options: nil
|
341
|
+
request_options: nil, call_options: nil
|
318
342
|
ensure_service!
|
319
343
|
if query_options.nil?
|
320
344
|
query_options = @query_options
|
@@ -328,6 +352,7 @@ module Google
|
|
328
352
|
partition_token: partition_token,
|
329
353
|
seqno: seqno,
|
330
354
|
query_options: query_options,
|
355
|
+
request_options: request_options,
|
331
356
|
call_options: call_options
|
332
357
|
@last_updated_at = Time.now
|
333
358
|
results
|
@@ -341,6 +366,23 @@ module Google
|
|
341
366
|
# transactions.
|
342
367
|
# @param [Integer] seqno A per-transaction sequence number used to
|
343
368
|
# identify this request.
|
369
|
+
# @param [Hash] request_options Common request options.
|
370
|
+
#
|
371
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
372
|
+
# to queries or reads, used for statistics collection. Both
|
373
|
+
# request_tag and transaction_tag can be specified for a read or
|
374
|
+
# query that belongs to a transaction. This field is ignored for
|
375
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
376
|
+
# `request_tag` must be a valid identifier of the form:
|
377
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
378
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
379
|
+
# about this transaction. Both request_tag and transaction_tag can
|
380
|
+
# be specified for a read or query that belongs to a transaction.
|
381
|
+
# The value of transaction_tag should be the same for all requests
|
382
|
+
# belonging to the same transaction. If this request doesn't belong
|
383
|
+
# to any transaction, transaction_tag will be ignored.
|
384
|
+
# `transaction_tag` must be a valid identifier of the format:
|
385
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
344
386
|
# @param [Hash] call_options A hash of values to specify the custom
|
345
387
|
# call options, e.g., timeout, retries, etc. Call options are
|
346
388
|
# optional. The following settings can be provided:
|
@@ -369,7 +411,8 @@ module Google
|
|
369
411
|
# @return [Array<Integer>] A list with the exact number of rows that
|
370
412
|
# were modified for each DML statement.
|
371
413
|
#
|
372
|
-
def batch_update transaction, seqno,
|
414
|
+
def batch_update transaction, seqno, request_options: nil,
|
415
|
+
call_options: nil
|
373
416
|
ensure_service!
|
374
417
|
|
375
418
|
raise ArgumentError, "block is required" unless block_given?
|
@@ -379,6 +422,7 @@ module Google
|
|
379
422
|
|
380
423
|
results = service.execute_batch_dml path, transaction,
|
381
424
|
batch.statements, seqno,
|
425
|
+
request_options: request_options,
|
382
426
|
call_options: call_options
|
383
427
|
@last_updated_at = Time.now
|
384
428
|
results
|
@@ -403,6 +447,23 @@ module Google
|
|
403
447
|
# @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
|
404
448
|
# transaction selector value to send. Only used for single-use
|
405
449
|
# transactions.
|
450
|
+
# @param [Hash] request_options Common request options.
|
451
|
+
#
|
452
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
453
|
+
# to queries or reads, used for statistics collection. Both
|
454
|
+
# request_tag and transaction_tag can be specified for a read or
|
455
|
+
# query that belongs to a transaction. This field is ignored for
|
456
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
457
|
+
# `request_tag` must be a valid identifier of the form:
|
458
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
459
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
460
|
+
# about this transaction. Both request_tag and transaction_tag can
|
461
|
+
# be specified for a read or query that belongs to a transaction.
|
462
|
+
# The value of transaction_tag should be the same for all requests
|
463
|
+
# belonging to the same transaction. If this request doesn't belong
|
464
|
+
# to any transaction, transaction_tag will be ignored.
|
465
|
+
# `transaction_tag` must be a valid identifier of the format:
|
466
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
406
467
|
# @param [Hash] call_options A hash of values to specify the custom
|
407
468
|
# call options, e.g., timeout, retries, etc. Call options are
|
408
469
|
# optional. The following settings can be provided:
|
@@ -434,13 +495,15 @@ module Google
|
|
434
495
|
# end
|
435
496
|
#
|
436
497
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
437
|
-
transaction: nil, partition_token: nil,
|
498
|
+
transaction: nil, partition_token: nil, request_options: nil,
|
499
|
+
call_options: nil
|
438
500
|
ensure_service!
|
439
501
|
|
440
502
|
results = Results.read service, path, table, columns,
|
441
503
|
keys: keys, index: index, limit: limit,
|
442
504
|
transaction: transaction,
|
443
505
|
partition_token: partition_token,
|
506
|
+
request_options: request_options,
|
444
507
|
call_options: call_options
|
445
508
|
@last_updated_at = Time.now
|
446
509
|
results
|
@@ -494,6 +557,23 @@ module Google
|
|
494
557
|
# {CommitResponse}. Default value is `false`
|
495
558
|
#
|
496
559
|
# transaction. Default it is `false`.
|
560
|
+
# @param [Hash] request_options Common request options.
|
561
|
+
#
|
562
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
563
|
+
# to queries or reads, used for statistics collection. Both
|
564
|
+
# request_tag and transaction_tag can be specified for a read or
|
565
|
+
# query that belongs to a transaction. This field is ignored for
|
566
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
567
|
+
# `request_tag` must be a valid identifier of the form:
|
568
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
569
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
570
|
+
# about this transaction. Both request_tag and transaction_tag can
|
571
|
+
# be specified for a read or query that belongs to a transaction.
|
572
|
+
# The value of transaction_tag should be the same for all requests
|
573
|
+
# belonging to the same transaction. If this request doesn't belong
|
574
|
+
# to any transaction, transaction_tag will be ignored.
|
575
|
+
# `transaction_tag` must be a valid identifier of the format:
|
576
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
497
577
|
# @param [Hash] call_options A hash of values to specify the custom
|
498
578
|
# call options, e.g., timeout, retries, etc. Call options are
|
499
579
|
# optional. The following settings can be provided:
|
@@ -542,13 +622,15 @@ module Google
|
|
542
622
|
# puts commit_resp.timestamp
|
543
623
|
# puts commit_resp.stats.mutation_count
|
544
624
|
#
|
545
|
-
def commit transaction_id: nil, commit_options: nil,
|
625
|
+
def commit transaction_id: nil, commit_options: nil,
|
626
|
+
request_options: nil, call_options: nil
|
546
627
|
ensure_service!
|
547
628
|
commit = Commit.new
|
548
629
|
yield commit
|
549
630
|
commit_resp = service.commit path, commit.mutations,
|
550
631
|
transaction_id: transaction_id,
|
551
632
|
commit_options: commit_options,
|
633
|
+
request_options: request_options,
|
552
634
|
call_options: call_options
|
553
635
|
@last_updated_at = Time.now
|
554
636
|
resp = CommitResponse.from_grpc commit_resp
|
@@ -573,6 +655,7 @@ module Google
|
|
573
655
|
# | `BOOL` | `true`/`false` | |
|
574
656
|
# | `INT64` | `Integer` | |
|
575
657
|
# | `FLOAT64` | `Float` | |
|
658
|
+
# | `NUMERIC` | `BigDecimal` | |
|
576
659
|
# | `STRING` | `String` | |
|
577
660
|
# | `DATE` | `Date` | |
|
578
661
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -590,6 +673,23 @@ module Google
|
|
590
673
|
# then statistics related to the transaction will be included in
|
591
674
|
# {CommitResponse}. Default value is `false`
|
592
675
|
#
|
676
|
+
# @param [Hash] request_options Common request options.
|
677
|
+
#
|
678
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
679
|
+
# to queries or reads, used for statistics collection. Both
|
680
|
+
# request_tag and transaction_tag can be specified for a read or
|
681
|
+
# query that belongs to a transaction. This field is ignored for
|
682
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
683
|
+
# `request_tag` must be a valid identifier of the form:
|
684
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
685
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
686
|
+
# about this transaction. Both request_tag and transaction_tag can
|
687
|
+
# be specified for a read or query that belongs to a transaction.
|
688
|
+
# The value of transaction_tag should be the same for all requests
|
689
|
+
# belonging to the same transaction. If this request doesn't belong
|
690
|
+
# to any transaction, transaction_tag will be ignored.
|
691
|
+
# `transaction_tag` must be a valid identifier of the format:
|
692
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
593
693
|
# @param [Hash] call_options A hash of values to specify the custom
|
594
694
|
# call options, e.g., timeout, retries, etc. Call options are
|
595
695
|
# optional. The following settings can be provided:
|
@@ -633,10 +733,11 @@ module Google
|
|
633
733
|
# puts commit_resp.stats.mutation_count
|
634
734
|
#
|
635
735
|
def upsert table, *rows, transaction_id: nil, commit_options: nil,
|
636
|
-
call_options: nil
|
736
|
+
request_options: nil, call_options: nil
|
637
737
|
opts = {
|
638
738
|
transaction_id: transaction_id,
|
639
739
|
commit_options: commit_options,
|
740
|
+
request_options: request_options,
|
640
741
|
call_options: call_options
|
641
742
|
}
|
642
743
|
commit(**opts) do |c|
|
@@ -662,6 +763,7 @@ module Google
|
|
662
763
|
# | `BOOL` | `true`/`false` | |
|
663
764
|
# | `INT64` | `Integer` | |
|
664
765
|
# | `FLOAT64` | `Float` | |
|
766
|
+
# | `NUMERIC` | `BigDecimal` | |
|
665
767
|
# | `STRING` | `String` | |
|
666
768
|
# | `DATE` | `Date` | |
|
667
769
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -679,6 +781,23 @@ module Google
|
|
679
781
|
# then statistics related to the transaction will be included in
|
680
782
|
# {CommitResponse}. Default value is `false`
|
681
783
|
#
|
784
|
+
# @param [Hash] request_options Common request options.
|
785
|
+
#
|
786
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
787
|
+
# to queries or reads, used for statistics collection. Both
|
788
|
+
# request_tag and transaction_tag can be specified for a read or
|
789
|
+
# query that belongs to a transaction. This field is ignored for
|
790
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
791
|
+
# `request_tag` must be a valid identifier of the form:
|
792
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
793
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
794
|
+
# about this transaction. Both request_tag and transaction_tag can
|
795
|
+
# be specified for a read or query that belongs to a transaction.
|
796
|
+
# The value of transaction_tag should be the same for all requests
|
797
|
+
# belonging to the same transaction. If this request doesn't belong
|
798
|
+
# to any transaction, transaction_tag will be ignored.
|
799
|
+
# `transaction_tag` must be a valid identifier of the format:
|
800
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
682
801
|
# @param [Hash] call_options A hash of values to specify the custom
|
683
802
|
# call options, e.g., timeout, retries, etc. Call options are
|
684
803
|
# optional. The following settings can be provided:
|
@@ -722,10 +841,11 @@ module Google
|
|
722
841
|
# puts commit_resp.stats.mutation_count
|
723
842
|
#
|
724
843
|
def insert table, *rows, transaction_id: nil, commit_options: nil,
|
725
|
-
call_options: nil
|
844
|
+
request_options: nil, call_options: nil
|
726
845
|
opts = {
|
727
846
|
transaction_id: transaction_id,
|
728
847
|
commit_options: commit_options,
|
848
|
+
request_options: request_options,
|
729
849
|
call_options: call_options
|
730
850
|
}
|
731
851
|
commit(**opts) do |c|
|
@@ -750,6 +870,7 @@ module Google
|
|
750
870
|
# | `BOOL` | `true`/`false` | |
|
751
871
|
# | `INT64` | `Integer` | |
|
752
872
|
# | `FLOAT64` | `Float` | |
|
873
|
+
# | `NUMERIC` | `BigDecimal` | |
|
753
874
|
# | `STRING` | `String` | |
|
754
875
|
# | `DATE` | `Date` | |
|
755
876
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -767,6 +888,23 @@ module Google
|
|
767
888
|
# then statistics related to the transaction will be included in
|
768
889
|
# {CommitResponse}. Default value is `false`
|
769
890
|
#
|
891
|
+
# @param [Hash] request_options Common request options.
|
892
|
+
#
|
893
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
894
|
+
# to queries or reads, used for statistics collection. Both
|
895
|
+
# request_tag and transaction_tag can be specified for a read or
|
896
|
+
# query that belongs to a transaction. This field is ignored for
|
897
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
898
|
+
# `request_tag` must be a valid identifier of the form:
|
899
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
900
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
901
|
+
# about this transaction. Both request_tag and transaction_tag can
|
902
|
+
# be specified for a read or query that belongs to a transaction.
|
903
|
+
# The value of transaction_tag should be the same for all requests
|
904
|
+
# belonging to the same transaction. If this request doesn't belong
|
905
|
+
# to any transaction, transaction_tag will be ignored.
|
906
|
+
# `transaction_tag` must be a valid identifier of the format:
|
907
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
770
908
|
# @param [Hash] call_options A hash of values to specify the custom
|
771
909
|
# call options, e.g., timeout, retries, etc. Call options are
|
772
910
|
# optional. The following settings can be provided:
|
@@ -810,10 +948,11 @@ module Google
|
|
810
948
|
# puts commit_resp.stats.mutation_count
|
811
949
|
#
|
812
950
|
def update table, *rows, transaction_id: nil, commit_options: nil,
|
813
|
-
call_options: nil
|
951
|
+
request_options: nil, call_options: nil
|
814
952
|
opts = {
|
815
953
|
transaction_id: transaction_id,
|
816
954
|
commit_options: commit_options,
|
955
|
+
request_options: request_options,
|
817
956
|
call_options: call_options
|
818
957
|
}
|
819
958
|
commit(**opts) do |c|
|
@@ -840,6 +979,7 @@ module Google
|
|
840
979
|
# | `BOOL` | `true`/`false` | |
|
841
980
|
# | `INT64` | `Integer` | |
|
842
981
|
# | `FLOAT64` | `Float` | |
|
982
|
+
# | `NUMERIC` | `BigDecimal` | |
|
843
983
|
# | `STRING` | `String` | |
|
844
984
|
# | `DATE` | `Date` | |
|
845
985
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -857,6 +997,23 @@ module Google
|
|
857
997
|
# then statistics related to the transaction will be included in
|
858
998
|
# {CommitResponse}. Default value is `false`.
|
859
999
|
#
|
1000
|
+
# @param [Hash] request_options Common request options.
|
1001
|
+
#
|
1002
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
1003
|
+
# to queries or reads, used for statistics collection. Both
|
1004
|
+
# request_tag and transaction_tag can be specified for a read or
|
1005
|
+
# query that belongs to a transaction. This field is ignored for
|
1006
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
1007
|
+
# `request_tag` must be a valid identifier of the form:
|
1008
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
1009
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
1010
|
+
# about this transaction. Both request_tag and transaction_tag can
|
1011
|
+
# be specified for a read or query that belongs to a transaction.
|
1012
|
+
# The value of transaction_tag should be the same for all requests
|
1013
|
+
# belonging to the same transaction. If this request doesn't belong
|
1014
|
+
# to any transaction, transaction_tag will be ignored.
|
1015
|
+
# `transaction_tag` must be a valid identifier of the format:
|
1016
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
860
1017
|
# @param [Hash] call_options A hash of values to specify the custom
|
861
1018
|
# call options, e.g., timeout, retries, etc. Call options are
|
862
1019
|
# optional. The following settings can be provided:
|
@@ -900,10 +1057,11 @@ module Google
|
|
900
1057
|
# puts commit_resp.stats.mutation_count
|
901
1058
|
#
|
902
1059
|
def replace table, *rows, transaction_id: nil, commit_options: nil,
|
903
|
-
call_options: nil
|
1060
|
+
request_options: nil, call_options: nil
|
904
1061
|
opts = {
|
905
1062
|
transaction_id: transaction_id,
|
906
1063
|
commit_options: commit_options,
|
1064
|
+
request_options: request_options,
|
907
1065
|
call_options: call_options
|
908
1066
|
}
|
909
1067
|
commit(**opts) do |c|
|
@@ -928,6 +1086,23 @@ module Google
|
|
928
1086
|
# then statistics related to the transaction will be included in
|
929
1087
|
# {CommitResponse}. Default value is `false`
|
930
1088
|
#
|
1089
|
+
# @param [Hash] request_options Common request options.
|
1090
|
+
#
|
1091
|
+
# * `:request_tag` (String) A per-request tag which can be applied
|
1092
|
+
# to queries or reads, used for statistics collection. Both
|
1093
|
+
# request_tag and transaction_tag can be specified for a read or
|
1094
|
+
# query that belongs to a transaction. This field is ignored for
|
1095
|
+
# requests where it's not applicable (e.g. CommitRequest).
|
1096
|
+
# `request_tag` must be a valid identifier of the form:
|
1097
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
|
1098
|
+
# * `:transaction_tag` (String) A tag used for statistics collection
|
1099
|
+
# about this transaction. Both request_tag and transaction_tag can
|
1100
|
+
# be specified for a read or query that belongs to a transaction.
|
1101
|
+
# The value of transaction_tag should be the same for all requests
|
1102
|
+
# belonging to the same transaction. If this request doesn't belong
|
1103
|
+
# to any transaction, transaction_tag will be ignored.
|
1104
|
+
# `transaction_tag` must be a valid identifier of the format:
|
1105
|
+
# [a-zA-Z][a-zA-Z0-9_\-]{0,49}
|
931
1106
|
# @param [Hash] call_options A hash of values to specify the custom
|
932
1107
|
# call options, e.g., timeout, retries, etc. Call options are
|
933
1108
|
# optional. The following settings can be provided:
|
@@ -968,10 +1143,11 @@ module Google
|
|
968
1143
|
# puts commit_resp.stats.mutation_count
|
969
1144
|
#
|
970
1145
|
def delete table, keys = [], transaction_id: nil, commit_options: nil,
|
971
|
-
call_options: nil
|
1146
|
+
request_options: nil, call_options: nil
|
972
1147
|
opts = {
|
973
1148
|
transaction_id: transaction_id,
|
974
1149
|
commit_options: commit_options,
|
1150
|
+
request_options: request_options,
|
975
1151
|
call_options: call_options
|
976
1152
|
}
|
977
1153
|
commit(**opts) do |c|
|