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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39a33a615e75cde66aa1d0ebf4631f34d5b139fa0a5c9fe203a20a4f157c5534
|
4
|
+
data.tar.gz: 415409aa55971910e5c337a6d88a2ee0e78671a3cde9ab0ebf3170edab8151ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a83fc9125b21861b192099c025596c0224eb3b2d4c7904809a52062358c35d621510ef0e8d2b9ecd583609514d440e19927130fcdf56242ea2a6765a5ce83a03
|
7
|
+
data.tar.gz: 0e5a053289cb6393d62533836eda651217e60388d43931613245ac3b55ddb3d17b8c98cbb866fc0efec703bba398ccb7f18b38fb6129c11b03306bb8419f823f
|
data/AUTHENTICATION.md
CHANGED
@@ -95,7 +95,8 @@ client = Google::Cloud::Spanner.new
|
|
95
95
|
|
96
96
|
### Configuration
|
97
97
|
|
98
|
-
The **Project ID** and **Credentials JSON** can be configured
|
98
|
+
The **Project ID** and the path to the **Credentials JSON** file can be configured
|
99
|
+
instead of placing them in environment variables or providing them as arguments.
|
99
100
|
|
100
101
|
```ruby
|
101
102
|
require "google/cloud/spanner"
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,48 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.9.0 / 2021-07-26
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* support request tagging ([#8163](https://www.github.com/googleapis/google-cloud-ruby/issues/8163))
|
8
|
+
|
9
|
+
### 2.8.1 / 2021-07-08
|
10
|
+
|
11
|
+
#### Documentation
|
12
|
+
|
13
|
+
* Update AUTHENTICATION.md in handwritten packages
|
14
|
+
|
15
|
+
### 2.8.0 / 2021-06-17
|
16
|
+
|
17
|
+
#### Features
|
18
|
+
|
19
|
+
* create instance using processing units/node count ([#11379](https://www.github.com/googleapis/google-cloud-ruby/issues/11379))
|
20
|
+
* create instance using processing units/node count
|
21
|
+
* fix typo
|
22
|
+
* removed node count and processing unit validations
|
23
|
+
* update orignal value on instance save
|
24
|
+
* remove orignal_values to current_valuess
|
25
|
+
|
26
|
+
### 2.7.0 / 2021-06-09
|
27
|
+
|
28
|
+
#### Features
|
29
|
+
|
30
|
+
* add the support of optimizer statistics package ([#7591](https://www.github.com/googleapis/google-cloud-ruby/issues/7591))
|
31
|
+
* feat(spanner): add the support of optimizer statistics package
|
32
|
+
* Fix rubocop issues.
|
33
|
+
* Fix the env issue.
|
34
|
+
* database create time access method ([#11617](https://www.github.com/googleapis/google-cloud-ruby/issues/11617))
|
35
|
+
* added database create time method
|
36
|
+
* remove assert for databse create time
|
37
|
+
* RPC priority request option. ([#11258](https://www.github.com/googleapis/google-cloud-ruby/issues/11258))
|
38
|
+
|
39
|
+
#### Bug Fixes
|
40
|
+
|
41
|
+
* extract binary retry info from error ([#11656](https://www.github.com/googleapis/google-cloud-ruby/issues/11656))
|
42
|
+
* fix: extract binary retry info from error
|
43
|
+
* fix: remove unrelated frozen_string_literal change
|
44
|
+
* fix: remove unnecessary parentheses
|
45
|
+
|
3
46
|
### 2.6.0 / 2021-03-31
|
4
47
|
|
5
48
|
#### Features
|
data/OVERVIEW.md
CHANGED
data/lib/google-cloud-spanner.rb
CHANGED
@@ -156,7 +156,9 @@ Google::Cloud.configure.add_config! :spanner do |config|
|
|
156
156
|
default_query_options = Google::Cloud::Config.deferred do
|
157
157
|
query_options = {}
|
158
158
|
optimizer_version = ENV["SPANNER_OPTIMIZER_VERSION"]
|
159
|
+
optimizer_stats_pkg = ENV["SPANNER_OPTIMIZER_STATISTICS_PACKAGE"]
|
159
160
|
query_options[:optimizer_version] = optimizer_version if optimizer_version
|
161
|
+
query_options[:optimizer_statistics_package] = optimizer_stats_pkg if optimizer_stats_pkg
|
160
162
|
query_options = nil if query_options.empty?
|
161
163
|
query_options
|
162
164
|
end
|
@@ -173,6 +173,8 @@ module Google
|
|
173
173
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
174
174
|
# Empty to use database default. "latest" to use the latest
|
175
175
|
# available optimizer version.
|
176
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
177
|
+
# use. Empty to use the database default.
|
176
178
|
# @param [Hash] call_options A hash of values to specify the custom
|
177
179
|
# call options, e.g., timeout, retries, etc. Call options are
|
178
180
|
# optional. The following settings can be provided:
|
@@ -473,6 +475,8 @@ module Google
|
|
473
475
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
474
476
|
# Empty to use database default. "latest" to use the latest
|
475
477
|
# available optimizer version.
|
478
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
479
|
+
# use. Empty to use the database default.
|
476
480
|
# @param [Hash] call_options A hash of values to specify the custom
|
477
481
|
# call options, e.g., timeout, retries, etc. Call options are
|
478
482
|
# optional. The following settings can be provided:
|
@@ -598,8 +602,11 @@ module Google
|
|
598
602
|
# batch_snapshot = batch_client.batch_snapshot
|
599
603
|
#
|
600
604
|
# results = batch_snapshot.execute_query \
|
601
|
-
#
|
602
|
-
#
|
605
|
+
# "SELECT * FROM users",
|
606
|
+
# query_options: {
|
607
|
+
# optimizer_version: "1",
|
608
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
609
|
+
# }
|
603
610
|
#
|
604
611
|
# results.rows.each do |row|
|
605
612
|
# puts "User #{row[:id]} is #{row[:name]}"
|
@@ -42,12 +42,10 @@ module Google
|
|
42
42
|
#
|
43
43
|
# db = spanner.client "my-instance", "my-database"
|
44
44
|
#
|
45
|
-
# db.
|
46
|
-
# results = tx.execute_query "SELECT * FROM users"
|
45
|
+
# results = db.execute_query "SELECT * FROM users"
|
47
46
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# end
|
47
|
+
# results.rows.each do |row|
|
48
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
51
49
|
# end
|
52
50
|
#
|
53
51
|
class Client
|
@@ -129,6 +127,7 @@ module Google
|
|
129
127
|
# | `BOOL` | `true`/`false` | |
|
130
128
|
# | `INT64` | `Integer` | |
|
131
129
|
# | `FLOAT64` | `Float` | |
|
130
|
+
# | `NUMERIC` | `BigDecimal` | |
|
132
131
|
# | `STRING` | `String` | |
|
133
132
|
# | `DATE` | `Date` | |
|
134
133
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -154,6 +153,7 @@ module Google
|
|
154
153
|
# * `:BYTES`
|
155
154
|
# * `:DATE`
|
156
155
|
# * `:FLOAT64`
|
156
|
+
# * `:NUMERIC`
|
157
157
|
# * `:INT64`
|
158
158
|
# * `:STRING`
|
159
159
|
# * `:TIMESTAMP`
|
@@ -167,6 +167,9 @@ module Google
|
|
167
167
|
# @param [Hash] single_use Perform the read with a single-use snapshot
|
168
168
|
# (read-only transaction). (See
|
169
169
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
170
|
+
# If no value is specified for this parameter, Cloud Spanner will use
|
171
|
+
# a single use read-only transaction with strong timestamp bound as
|
172
|
+
# default.
|
170
173
|
# The snapshot can be created by providing exactly one of the
|
171
174
|
# following options in the hash:
|
172
175
|
#
|
@@ -223,6 +226,20 @@ module Google
|
|
223
226
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
224
227
|
# Empty to use database default. "latest" to use the latest
|
225
228
|
# available optimizer version.
|
229
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
230
|
+
# use. Empty to use the database default.
|
231
|
+
# @param [Hash] request_options Common request options.
|
232
|
+
#
|
233
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
234
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
235
|
+
# and does not guarantee priority or order of execution.
|
236
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
237
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
238
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
239
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
240
|
+
# queries or reads, used for statistics collection. Tag must be a
|
241
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
242
|
+
# and 64 characters in length.
|
226
243
|
# @param [Hash] call_options A hash of values to specify the custom
|
227
244
|
# call options, e.g., timeout, retries, etc. Call options are
|
228
245
|
# optional. The following settings can be provided:
|
@@ -343,7 +360,10 @@ module Google
|
|
343
360
|
# db = spanner.client "my-instance", "my-database"
|
344
361
|
#
|
345
362
|
# results = db.execute_query \
|
346
|
-
# "SELECT * FROM users", query_options: {
|
363
|
+
# "SELECT * FROM users", query_options: {
|
364
|
+
# optimizer_version: "1",
|
365
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
366
|
+
# }
|
347
367
|
#
|
348
368
|
# results.rows.each do |row|
|
349
369
|
# puts "User #{row[:id]} is #{row[:name]}"
|
@@ -372,19 +392,52 @@ module Google
|
|
372
392
|
# puts "User #{row[:id]} is #{row[:name]}"
|
373
393
|
# end
|
374
394
|
#
|
395
|
+
# @example Using request options.
|
396
|
+
# require "google/cloud/spanner"
|
397
|
+
#
|
398
|
+
# spanner = Google::Cloud::Spanner.new
|
399
|
+
#
|
400
|
+
# db = spanner.client "my-instance", "my-database"
|
401
|
+
#
|
402
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
403
|
+
# results = db.execute_query "SELECT * FROM users",
|
404
|
+
# request_options: request_options
|
405
|
+
#
|
406
|
+
# results.rows.each do |row|
|
407
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
408
|
+
# end
|
409
|
+
#
|
410
|
+
# @example Query using tag for request query statistics collection.
|
411
|
+
# require "google/cloud/spanner"
|
412
|
+
#
|
413
|
+
# spanner = Google::Cloud::Spanner.new
|
414
|
+
#
|
415
|
+
# db = spanner.client "my-instance", "my-database"
|
416
|
+
#
|
417
|
+
# request_options = { tag: "Read-Users" }
|
418
|
+
# results = db.execute_query "SELECT * FROM users",
|
419
|
+
# request_options: request_options
|
420
|
+
#
|
421
|
+
# results.rows.each do |row|
|
422
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
423
|
+
# end
|
424
|
+
#
|
375
425
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
376
|
-
query_options: nil,
|
426
|
+
query_options: nil, request_options: nil,
|
427
|
+
call_options: nil
|
377
428
|
validate_single_use_args! single_use
|
378
429
|
ensure_service!
|
379
430
|
|
380
431
|
params, types = Convert.to_input_params_and_types params, types
|
381
|
-
|
432
|
+
request_options = Convert.to_request_options request_options,
|
433
|
+
tag_type: :request_tag
|
382
434
|
single_use_tx = single_use_transaction single_use
|
383
435
|
results = nil
|
384
436
|
@pool.with_session do |session|
|
385
437
|
results = session.execute_query \
|
386
438
|
sql, params: params, types: types, transaction: single_use_tx,
|
387
|
-
query_options: query_options,
|
439
|
+
query_options: query_options, request_options: request_options,
|
440
|
+
call_options: call_options
|
388
441
|
end
|
389
442
|
results
|
390
443
|
end
|
@@ -408,7 +461,7 @@ module Google
|
|
408
461
|
# once" semantics.
|
409
462
|
#
|
410
463
|
# Where DML statements must be executed using Transaction (see
|
411
|
-
# {Transaction#execute_update}),
|
464
|
+
# {Transaction#execute_update}), Partitioned DML statements are executed
|
412
465
|
# outside of a read/write transaction.
|
413
466
|
#
|
414
467
|
# Not all DML statements can be executed in the Partitioned DML mode and
|
@@ -494,6 +547,7 @@ module Google
|
|
494
547
|
# | `BOOL` | `true`/`false` | |
|
495
548
|
# | `INT64` | `Integer` | |
|
496
549
|
# | `FLOAT64` | `Float` | |
|
550
|
+
# | `NUMERIC` | `BigDecimal` | |
|
497
551
|
# | `STRING` | `String` | |
|
498
552
|
# | `DATE` | `Date` | |
|
499
553
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -520,6 +574,7 @@ module Google
|
|
520
574
|
# * `:BYTES`
|
521
575
|
# * `:DATE`
|
522
576
|
# * `:FLOAT64`
|
577
|
+
# * `:NUMERIC`
|
523
578
|
# * `:INT64`
|
524
579
|
# * `:STRING`
|
525
580
|
# * `:TIMESTAMP`
|
@@ -535,6 +590,20 @@ module Google
|
|
535
590
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
536
591
|
# Empty to use database default. "latest" to use the latest
|
537
592
|
# available optimizer version.
|
593
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
594
|
+
# use. Empty to use the database default.
|
595
|
+
# @param [Hash] request_options Common request options.
|
596
|
+
#
|
597
|
+
# * `:priority` (String) The relative priority for requests.
|
598
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
599
|
+
# and does not guarantee priority or order of execution.
|
600
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
601
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
602
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
603
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
604
|
+
# queries or reads, used for statistics collection. Tag must be a
|
605
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
606
|
+
# and 64 characters in length.
|
538
607
|
# @param [Hash] call_options A hash of values to specify the custom
|
539
608
|
# call options, e.g., timeout, retries, etc. Call options are
|
540
609
|
# optional. The following settings can be provided:
|
@@ -577,7 +646,10 @@ module Google
|
|
577
646
|
#
|
578
647
|
# row_count = db.execute_partition_update \
|
579
648
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
580
|
-
# query_options: {
|
649
|
+
# query_options: {
|
650
|
+
# optimizer_version: "1",
|
651
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
652
|
+
# }
|
581
653
|
#
|
582
654
|
# @example Query using custom timeout and retry policy:
|
583
655
|
# require "google/cloud/spanner"
|
@@ -598,17 +670,45 @@ module Google
|
|
598
670
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
599
671
|
# call_options: call_options
|
600
672
|
#
|
673
|
+
# @example Using request options.
|
674
|
+
# require "google/cloud/spanner"
|
675
|
+
#
|
676
|
+
# spanner = Google::Cloud::Spanner.new
|
677
|
+
# db = spanner.client "my-instance", "my-database"
|
678
|
+
#
|
679
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
680
|
+
# row_count = db.execute_partition_update \
|
681
|
+
# "UPDATE users SET friends = NULL WHERE active = @active",
|
682
|
+
# params: { active: false }, request_options: request_options
|
683
|
+
#
|
684
|
+
# @example Query using tag for request query statistics collection.
|
685
|
+
#
|
686
|
+
# require "google/cloud/spanner"
|
687
|
+
#
|
688
|
+
# spanner = Google::Cloud::Spanner.new
|
689
|
+
# db = spanner.client "my-instance", "my-database"
|
690
|
+
#
|
691
|
+
# request_options = { tag: "Update-Users" }
|
692
|
+
# row_count = db.execute_partition_update \
|
693
|
+
# "UPDATE users SET friends = NULL WHERE active = false",
|
694
|
+
# request_options: request_options
|
695
|
+
#
|
601
696
|
def execute_partition_update sql, params: nil, types: nil,
|
602
|
-
query_options: nil,
|
697
|
+
query_options: nil, request_options: nil,
|
698
|
+
call_options: nil
|
603
699
|
ensure_service!
|
604
700
|
|
605
701
|
params, types = Convert.to_input_params_and_types params, types
|
702
|
+
request_options = Convert.to_request_options request_options,
|
703
|
+
tag_type: :request_tag
|
704
|
+
|
606
705
|
results = nil
|
607
706
|
@pool.with_session do |session|
|
608
707
|
results = session.execute_query \
|
609
708
|
sql, params: params, types: types,
|
610
709
|
transaction: pdml_transaction(session),
|
611
|
-
query_options: query_options,
|
710
|
+
query_options: query_options, request_options: request_options,
|
711
|
+
call_options: call_options
|
612
712
|
end
|
613
713
|
# Stream all PartialResultSet to get ResultSetStats
|
614
714
|
results.rows.to_a
|
@@ -640,6 +740,9 @@ module Google
|
|
640
740
|
# @param [Hash] single_use Perform the read with a single-use snapshot
|
641
741
|
# (read-only transaction). (See
|
642
742
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
743
|
+
# If no value is specified for this parameter, Cloud Spanner will use
|
744
|
+
# a single use read-only transaction with strong timestamp bound as
|
745
|
+
# default.
|
643
746
|
# The snapshot can be created by providing exactly one of the
|
644
747
|
# following options in the hash:
|
645
748
|
#
|
@@ -689,6 +792,18 @@ module Google
|
|
689
792
|
# Useful for reading the freshest data available at a nearby
|
690
793
|
# replica, while bounding the possible staleness if the local
|
691
794
|
# replica has fallen behind.
|
795
|
+
# @param [Hash] request_options Common request options.
|
796
|
+
#
|
797
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
798
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
799
|
+
# and does not guarantee priority or order of execution.
|
800
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
801
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
802
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
803
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
804
|
+
# queries or reads, used for statistics collection. Tag must be a
|
805
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
806
|
+
# and 64 characters in length.
|
692
807
|
# @param [Hash] call_options A hash of values to specify the custom
|
693
808
|
# call options, e.g., timeout, retries, etc. Call options are
|
694
809
|
# optional. The following settings can be provided:
|
@@ -753,20 +868,54 @@ module Google
|
|
753
868
|
# puts "User #{row[:id]} is #{row[:name]}"
|
754
869
|
# end
|
755
870
|
#
|
871
|
+
# @example Using request options.
|
872
|
+
# require "google/cloud/spanner"
|
873
|
+
#
|
874
|
+
# spanner = Google::Cloud::Spanner.new
|
875
|
+
#
|
876
|
+
# db = spanner.client "my-instance", "my-database"
|
877
|
+
#
|
878
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
879
|
+
# results = db.read "users", [:id, :name],
|
880
|
+
# request_options: request_options
|
881
|
+
#
|
882
|
+
# results.rows.each do |row|
|
883
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
884
|
+
# end
|
885
|
+
#
|
886
|
+
# @example Read using tag for read statistics collection.
|
887
|
+
#
|
888
|
+
# require "google/cloud/spanner"
|
889
|
+
#
|
890
|
+
# spanner = Google::Cloud::Spanner.new
|
891
|
+
#
|
892
|
+
# db = spanner.client "my-instance", "my-database"
|
893
|
+
#
|
894
|
+
# request_options = { tag: "Read-Users-All" }
|
895
|
+
# results = db.read "users", [:id, :name],
|
896
|
+
# request_options: request_options
|
897
|
+
#
|
898
|
+
# results.rows.each do |row|
|
899
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
900
|
+
# end
|
901
|
+
#
|
756
902
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
757
|
-
single_use: nil, call_options: nil
|
903
|
+
single_use: nil, request_options: nil, call_options: nil
|
758
904
|
validate_single_use_args! single_use
|
759
905
|
ensure_service!
|
760
906
|
|
761
907
|
columns = Array(columns).map(&:to_s)
|
762
908
|
keys = Convert.to_key_set keys
|
763
|
-
|
764
909
|
single_use_tx = single_use_transaction single_use
|
910
|
+
request_options = Convert.to_request_options request_options,
|
911
|
+
tag_type: :request_tag
|
912
|
+
|
765
913
|
results = nil
|
766
914
|
@pool.with_session do |session|
|
767
915
|
results = session.read \
|
768
916
|
table, columns, keys: keys, index: index, limit: limit,
|
769
917
|
transaction: single_use_tx,
|
918
|
+
request_options: request_options,
|
770
919
|
call_options: call_options
|
771
920
|
end
|
772
921
|
results
|
@@ -801,6 +950,7 @@ module Google
|
|
801
950
|
# | `BOOL` | `true`/`false` | |
|
802
951
|
# | `INT64` | `Integer` | |
|
803
952
|
# | `FLOAT64` | `Float` | |
|
953
|
+
# | `NUMERIC` | `BigDecimal` | |
|
804
954
|
# | `STRING` | `String` | |
|
805
955
|
# | `DATE` | `Date` | |
|
806
956
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -817,6 +967,17 @@ module Google
|
|
817
967
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
818
968
|
# then statistics related to the transaction will be included in
|
819
969
|
# {CommitResponse}. Default value is `false`
|
970
|
+
# @param [Hash] request_options Common request options.
|
971
|
+
#
|
972
|
+
# * `:priority` (String) The relative priority for requests.
|
973
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
974
|
+
# and does not guarantee priority or order of execution.
|
975
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
976
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
977
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
978
|
+
# * `:tag` (String) A tag used for statistics collection
|
979
|
+
# about transaction. A tag must be a valid identifier of the format:
|
980
|
+
# `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
820
981
|
#
|
821
982
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
822
983
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -846,9 +1007,37 @@ module Google
|
|
846
1007
|
# puts commit_resp.timestamp
|
847
1008
|
# puts commit_resp.stats.mutation_count
|
848
1009
|
#
|
849
|
-
|
1010
|
+
# @example Using request options.
|
1011
|
+
# require "google/cloud/spanner"
|
1012
|
+
#
|
1013
|
+
# spanner = Google::Cloud::Spanner.new
|
1014
|
+
#
|
1015
|
+
# db = spanner.client "my-instance", "my-database"
|
1016
|
+
#
|
1017
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1018
|
+
# db.upsert "users", [{ id: 1, name: "Charlie", active: false }],
|
1019
|
+
# request_options: request_options
|
1020
|
+
#
|
1021
|
+
# @example Upsert using tag for transaction statistics collection.
|
1022
|
+
#
|
1023
|
+
# require "google/cloud/spanner"
|
1024
|
+
#
|
1025
|
+
# spanner = Google::Cloud::Spanner.new
|
1026
|
+
#
|
1027
|
+
# db = spanner.client "my-instance", "my-database"
|
1028
|
+
#
|
1029
|
+
# request_options = { tag: "Bulk-Upsert" }
|
1030
|
+
# db.upsert "users", [{ id: 1, name: "Charlie", active: false },
|
1031
|
+
# { id: 2, name: "Harvey", active: true }],
|
1032
|
+
# request_options: request_options
|
1033
|
+
#
|
1034
|
+
def upsert table, rows, commit_options: nil, request_options: nil
|
1035
|
+
request_options = Convert.to_request_options \
|
1036
|
+
request_options, tag_type: :transaction_tag
|
1037
|
+
|
850
1038
|
@pool.with_session do |session|
|
851
|
-
session.upsert table, rows, commit_options: commit_options
|
1039
|
+
session.upsert table, rows, commit_options: commit_options,
|
1040
|
+
request_options: request_options
|
852
1041
|
end
|
853
1042
|
end
|
854
1043
|
alias save upsert
|
@@ -881,6 +1070,7 @@ module Google
|
|
881
1070
|
# | `BOOL` | `true`/`false` | |
|
882
1071
|
# | `INT64` | `Integer` | |
|
883
1072
|
# | `FLOAT64` | `Float` | |
|
1073
|
+
# | `NUMERIC` | `BigDecimal` | |
|
884
1074
|
# | `STRING` | `String` | |
|
885
1075
|
# | `DATE` | `Date` | |
|
886
1076
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -889,7 +1079,6 @@ module Google
|
|
889
1079
|
#
|
890
1080
|
# See [Data
|
891
1081
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
892
|
-
#
|
893
1082
|
# @param [Hash] commit_options A hash of commit options.
|
894
1083
|
# e.g., return_commit_stats. Commit options are optional.
|
895
1084
|
# The following options can be provided:
|
@@ -897,6 +1086,17 @@ module Google
|
|
897
1086
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
898
1087
|
# then statistics related to the transaction will be included in
|
899
1088
|
# {CommitResponse}. Default value is `false`
|
1089
|
+
# @param [Hash] request_options Common request options.
|
1090
|
+
#
|
1091
|
+
# * `:priority` (String) The relative priority for requests.
|
1092
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1093
|
+
# and does not guarantee priority or order of execution.
|
1094
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1095
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1096
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1097
|
+
# * `:tag` (String) A tag used for statistics collection
|
1098
|
+
# about transaction. A tag must be a valid identifier of the
|
1099
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
900
1100
|
#
|
901
1101
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
902
1102
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -926,9 +1126,37 @@ module Google
|
|
926
1126
|
# puts commit_resp.timestamp
|
927
1127
|
# puts commit_resp.stats.mutation_count
|
928
1128
|
#
|
929
|
-
|
1129
|
+
# @example Using request options.
|
1130
|
+
# require "google/cloud/spanner"
|
1131
|
+
#
|
1132
|
+
# spanner = Google::Cloud::Spanner.new
|
1133
|
+
#
|
1134
|
+
# db = spanner.client "my-instance", "my-database"
|
1135
|
+
#
|
1136
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1137
|
+
# db.insert "users", [{ id: 1, name: "Charlie", active: false }],
|
1138
|
+
# request_options: request_options
|
1139
|
+
#
|
1140
|
+
# @example Insert using tag for transaction statistics collection.
|
1141
|
+
#
|
1142
|
+
# require "google/cloud/spanner"
|
1143
|
+
#
|
1144
|
+
# spanner = Google::Cloud::Spanner.new
|
1145
|
+
#
|
1146
|
+
# db = spanner.client "my-instance", "my-database"
|
1147
|
+
#
|
1148
|
+
# request_options = { tag: "BulkInsert-Users" }
|
1149
|
+
# db.insert "users", [{ id: 1, name: "Charlie", active: false },
|
1150
|
+
# { id: 2, name: "Harvey", active: true }],
|
1151
|
+
# request_options: request_options
|
1152
|
+
#
|
1153
|
+
def insert table, rows, commit_options: nil, request_options: nil
|
1154
|
+
request_options = Convert.to_request_options \
|
1155
|
+
request_options, tag_type: :transaction_tag
|
1156
|
+
|
930
1157
|
@pool.with_session do |session|
|
931
|
-
session.insert table, rows, commit_options: commit_options
|
1158
|
+
session.insert table, rows, commit_options: commit_options,
|
1159
|
+
request_options: request_options
|
932
1160
|
end
|
933
1161
|
end
|
934
1162
|
|
@@ -960,6 +1188,7 @@ module Google
|
|
960
1188
|
# | `BOOL` | `true`/`false` | |
|
961
1189
|
# | `INT64` | `Integer` | |
|
962
1190
|
# | `FLOAT64` | `Float` | |
|
1191
|
+
# | `NUMERIC` | `BigDecimal` | |
|
963
1192
|
# | `STRING` | `String` | |
|
964
1193
|
# | `DATE` | `Date` | |
|
965
1194
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -968,7 +1197,6 @@ module Google
|
|
968
1197
|
#
|
969
1198
|
# See [Data
|
970
1199
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
971
|
-
#
|
972
1200
|
# @param [Hash] commit_options A hash of commit options.
|
973
1201
|
# e.g., return_commit_stats. Commit options are optional.
|
974
1202
|
# The following options can be provided:
|
@@ -976,6 +1204,17 @@ module Google
|
|
976
1204
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
977
1205
|
# then statistics related to the transaction will be included in
|
978
1206
|
# {CommitResponse}. Default value is `false`
|
1207
|
+
# @param [Hash] request_options Common request options.
|
1208
|
+
#
|
1209
|
+
# * `:priority` (String) The relative priority for requests.
|
1210
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1211
|
+
# and does not guarantee priority or order of execution.
|
1212
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1213
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1214
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1215
|
+
# * `:tag` (String) A tag used for statistics collection
|
1216
|
+
# about transaction. A tag must be a valid identifier of the
|
1217
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
979
1218
|
#
|
980
1219
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
981
1220
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1005,9 +1244,36 @@ module Google
|
|
1005
1244
|
# puts commit_resp.timestamp
|
1006
1245
|
# puts commit_resp.stats.mutation_count
|
1007
1246
|
#
|
1008
|
-
|
1247
|
+
# @example Using request options.
|
1248
|
+
# require "google/cloud/spanner"
|
1249
|
+
#
|
1250
|
+
# spanner = Google::Cloud::Spanner.new
|
1251
|
+
#
|
1252
|
+
# db = spanner.client "my-instance", "my-database"
|
1253
|
+
#
|
1254
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1255
|
+
# db.update "users", [{ id: 1, name: "Charlie", active: false }],
|
1256
|
+
# request_options: request_options
|
1257
|
+
#
|
1258
|
+
# @example Updte using tag for transaction statistics collection.
|
1259
|
+
# require "google/cloud/spanner"
|
1260
|
+
#
|
1261
|
+
# spanner = Google::Cloud::Spanner.new
|
1262
|
+
#
|
1263
|
+
# db = spanner.client "my-instance", "my-database"
|
1264
|
+
#
|
1265
|
+
# request_options = { tag: "BulkUpdate-Users" }
|
1266
|
+
# db.update "users", [{ id: 1, name: "Charlie", active: false },
|
1267
|
+
# { id: 2, name: "Harvey", active: true }],
|
1268
|
+
# request_options: request_options
|
1269
|
+
#
|
1270
|
+
def update table, rows, commit_options: nil, request_options: nil
|
1271
|
+
request_options = Convert.to_request_options \
|
1272
|
+
request_options, tag_type: :transaction_tag
|
1273
|
+
|
1009
1274
|
@pool.with_session do |session|
|
1010
|
-
session.update table, rows, commit_options: commit_options
|
1275
|
+
session.update table, rows, commit_options: commit_options,
|
1276
|
+
request_options: request_options
|
1011
1277
|
end
|
1012
1278
|
end
|
1013
1279
|
|
@@ -1041,6 +1307,7 @@ module Google
|
|
1041
1307
|
# | `BOOL` | `true`/`false` | |
|
1042
1308
|
# | `INT64` | `Integer` | |
|
1043
1309
|
# | `FLOAT64` | `Float` | |
|
1310
|
+
# | `NUMERIC` | `BigDecimal` | |
|
1044
1311
|
# | `STRING` | `String` | |
|
1045
1312
|
# | `DATE` | `Date` | |
|
1046
1313
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -1049,7 +1316,6 @@ module Google
|
|
1049
1316
|
#
|
1050
1317
|
# See [Data
|
1051
1318
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
1052
|
-
#
|
1053
1319
|
# @param [Hash] commit_options A hash of commit options.
|
1054
1320
|
# e.g., return_commit_stats. Commit options are optional.
|
1055
1321
|
# The following options can be provided:
|
@@ -1057,6 +1323,17 @@ module Google
|
|
1057
1323
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1058
1324
|
# then statistics related to the transaction will be included in
|
1059
1325
|
# {CommitResponse}. Default value is `false`
|
1326
|
+
# @param [Hash] request_options Common request options.
|
1327
|
+
#
|
1328
|
+
# * `:priority` (String) The relative priority for requests.
|
1329
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1330
|
+
# and does not guarantee priority or order of execution.
|
1331
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1332
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1333
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1334
|
+
# * `:tag` (String) A tag used for statistics collection
|
1335
|
+
# about transaction. A tag must be a valid identifier of the
|
1336
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1060
1337
|
#
|
1061
1338
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1062
1339
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1086,9 +1363,33 @@ module Google
|
|
1086
1363
|
# puts commit_resp.timestamp
|
1087
1364
|
# puts commit_resp.stats.mutation_count
|
1088
1365
|
#
|
1089
|
-
|
1366
|
+
# @example Using request options.
|
1367
|
+
# require "google/cloud/spanner"
|
1368
|
+
#
|
1369
|
+
# spanner = Google::Cloud::Spanner.new
|
1370
|
+
#
|
1371
|
+
# db = spanner.client "my-instance", "my-database"
|
1372
|
+
#
|
1373
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1374
|
+
# db.replace "users", [{ id: 1, name: "Charlie", active: false }],
|
1375
|
+
# request_options: request_options
|
1376
|
+
#
|
1377
|
+
# @example Replace using tag for transaction statistics collection.
|
1378
|
+
# require "google/cloud/spanner"
|
1379
|
+
#
|
1380
|
+
# spanner = Google::Cloud::Spanner.new
|
1381
|
+
#
|
1382
|
+
# db = spanner.client "my-instance", "my-database"
|
1383
|
+
#
|
1384
|
+
# request_options = { tag: "BulkReplace-Users" }
|
1385
|
+
# db.replace "users", [{ id: 1, name: "Charlie", active: false },
|
1386
|
+
# { id: 2, name: "Harvey", active: true }],
|
1387
|
+
# request_options: request_options
|
1388
|
+
#
|
1389
|
+
def replace table, rows, commit_options: nil, request_options: nil
|
1090
1390
|
@pool.with_session do |session|
|
1091
|
-
session.replace table, rows, commit_options: commit_options
|
1391
|
+
session.replace table, rows, commit_options: commit_options,
|
1392
|
+
request_options: request_options
|
1092
1393
|
end
|
1093
1394
|
end
|
1094
1395
|
|
@@ -1119,7 +1420,17 @@ module Google
|
|
1119
1420
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1120
1421
|
# then statistics related to the transaction will be included in
|
1121
1422
|
# {CommitResponse}. Default value is `false`
|
1122
|
-
#
|
1423
|
+
# @param [Hash] request_options Common request options.
|
1424
|
+
#
|
1425
|
+
# * `:priority` (String) The relative priority for requests.
|
1426
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1427
|
+
# and does not guarantee priority or order of execution.
|
1428
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1429
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1430
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1431
|
+
# * `:tag` (String) A tag used for statistics collection
|
1432
|
+
# about transaction. A tag must be a valid identifier of the
|
1433
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1123
1434
|
# @param [Hash] call_options A hash of values to specify the custom
|
1124
1435
|
# call options, e.g., timeout, retries, etc. Call options are
|
1125
1436
|
# optional. The following settings can be provided:
|
@@ -1159,9 +1470,34 @@ module Google
|
|
1159
1470
|
# puts commit_resp.timestamp
|
1160
1471
|
# puts commit_resp.stats.mutation_count
|
1161
1472
|
#
|
1162
|
-
|
1473
|
+
# @example With request optinos
|
1474
|
+
# require "google/cloud/spanner"
|
1475
|
+
#
|
1476
|
+
# spanner = Google::Cloud::Spanner.new
|
1477
|
+
#
|
1478
|
+
# db = spanner.client "my-instance", "my-database"
|
1479
|
+
#
|
1480
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1481
|
+
# db.delete "users", [1, 2, 3], request_options: request_options
|
1482
|
+
#
|
1483
|
+
# @example Delete using tag for transaction statistics collection.
|
1484
|
+
# require "google/cloud/spanner"
|
1485
|
+
#
|
1486
|
+
# spanner = Google::Cloud::Spanner.new
|
1487
|
+
#
|
1488
|
+
# db = spanner.client "my-instance", "my-database"
|
1489
|
+
#
|
1490
|
+
# request_options = { tag: "BulkDelete-Users" }
|
1491
|
+
# db.delete "users", [1, 2, 3], request_options: request_options
|
1492
|
+
#
|
1493
|
+
def delete table, keys = [], commit_options: nil, request_options: nil,
|
1494
|
+
call_options: nil
|
1495
|
+
request_options = Convert.to_request_options \
|
1496
|
+
request_options, tag_type: :transaction_tag
|
1497
|
+
|
1163
1498
|
@pool.with_session do |session|
|
1164
1499
|
session.delete table, keys, commit_options: commit_options,
|
1500
|
+
request_options: request_options,
|
1165
1501
|
call_options: call_options
|
1166
1502
|
end
|
1167
1503
|
end
|
@@ -1188,7 +1524,17 @@ module Google
|
|
1188
1524
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1189
1525
|
# then statistics related to the transaction will be included in
|
1190
1526
|
# {CommitResponse}. Default value is `false`
|
1191
|
-
#
|
1527
|
+
# @param [Hash] request_options Common request options.
|
1528
|
+
#
|
1529
|
+
# * `:priority` (String) The relative priority for requests.
|
1530
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1531
|
+
# and does not guarantee priority or order of execution.
|
1532
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1533
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1534
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1535
|
+
# * `:tag` (String) A tag used for statistics collection
|
1536
|
+
# about transaction. A tag must be a valid identifier of the
|
1537
|
+
# format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
|
1192
1538
|
# @param [Hash] call_options A hash of values to specify the custom
|
1193
1539
|
# call options, e.g., timeout, retries, etc. Call options are
|
1194
1540
|
# optional. The following settings can be provided:
|
@@ -1237,18 +1583,49 @@ module Google
|
|
1237
1583
|
# puts commit_resp.timestamp
|
1238
1584
|
# puts commit_resp.stats.mutation_count
|
1239
1585
|
#
|
1240
|
-
|
1586
|
+
# @example With request options
|
1587
|
+
# require "google/cloud/spanner"
|
1588
|
+
#
|
1589
|
+
# spanner = Google::Cloud::Spanner.new
|
1590
|
+
#
|
1591
|
+
# db = spanner.client "my-instance", "my-database"
|
1592
|
+
#
|
1593
|
+
# db.commit request_options: { priority: :PRIORITY_MEDIUM } do |c|
|
1594
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1595
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1596
|
+
# end
|
1597
|
+
#
|
1598
|
+
# @example Commit using tag for transaction statistics collection.
|
1599
|
+
# require "google/cloud/spanner"
|
1600
|
+
#
|
1601
|
+
# spanner = Google::Cloud::Spanner.new
|
1602
|
+
#
|
1603
|
+
# db = spanner.client "my-instance", "my-database"
|
1604
|
+
#
|
1605
|
+
# request_options = { tag: "BulkManipulate-Users" }
|
1606
|
+
# db.commit request_options: request_options do |c|
|
1607
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1608
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1609
|
+
# end
|
1610
|
+
#
|
1611
|
+
def commit commit_options: nil, request_options: nil,
|
1612
|
+
call_options: nil, &block
|
1241
1613
|
raise ArgumentError, "Must provide a block" unless block_given?
|
1242
1614
|
|
1615
|
+
request_options = Convert.to_request_options \
|
1616
|
+
request_options, tag_type: :transaction_tag
|
1617
|
+
|
1243
1618
|
@pool.with_session do |session|
|
1244
1619
|
session.commit(
|
1245
|
-
commit_options: commit_options,
|
1620
|
+
commit_options: commit_options, request_options: request_options,
|
1621
|
+
call_options: call_options, &block
|
1246
1622
|
)
|
1247
1623
|
end
|
1248
1624
|
end
|
1249
1625
|
|
1250
1626
|
# rubocop:disable Metrics/AbcSize
|
1251
1627
|
# rubocop:disable Metrics/MethodLength
|
1628
|
+
# rubocop:disable Metrics/BlockLength
|
1252
1629
|
|
1253
1630
|
##
|
1254
1631
|
# Creates a transaction for reads and writes that execute atomically at
|
@@ -1273,6 +1650,18 @@ module Google
|
|
1273
1650
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1274
1651
|
# then statistics related to the transaction will be included in
|
1275
1652
|
# {CommitResponse}. Default value is `false`
|
1653
|
+
# @param [Hash] request_options Common request options.
|
1654
|
+
#
|
1655
|
+
# * `:priority` (String) The relative priority for requests.
|
1656
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1657
|
+
# and does not guarantee priority or order of execution.
|
1658
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1659
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1660
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1661
|
+
# * `:tag` (String)A tag used for statistics collection
|
1662
|
+
# about transaction. The value of a transaction tag should be the
|
1663
|
+
# same for all requests belonging to the same transaction. A tag must
|
1664
|
+
# be a valid identifier of the format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`
|
1276
1665
|
#
|
1277
1666
|
# @param [Hash] call_options A hash of values to specify the custom
|
1278
1667
|
# call options, e.g., timeout, retries, etc. Call options are
|
@@ -1350,7 +1739,47 @@ module Google
|
|
1350
1739
|
# puts commit_resp.timestamp
|
1351
1740
|
# puts commit_resp.stats.mutation_count
|
1352
1741
|
#
|
1353
|
-
|
1742
|
+
# @example Using request options.
|
1743
|
+
# require "google/cloud/spanner"
|
1744
|
+
#
|
1745
|
+
# spanner = Google::Cloud::Spanner.new
|
1746
|
+
# db = spanner.client "my-instance", "my-database"
|
1747
|
+
#
|
1748
|
+
# db.transaction request_options: { priority: :PRIORITY_MEDIUM } do |tx|
|
1749
|
+
# tx.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1750
|
+
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1751
|
+
#
|
1752
|
+
# request_options = { priority: :PRIORITY_LOW }
|
1753
|
+
# results = tx.execute_query "SELECT * FROM users",
|
1754
|
+
# request_options: request_options
|
1755
|
+
# end
|
1756
|
+
#
|
1757
|
+
# @example Tags for request and transaction statistics collection.
|
1758
|
+
#
|
1759
|
+
# require "google/cloud/spanner"
|
1760
|
+
#
|
1761
|
+
# spanner = Google::Cloud::Spanner.new
|
1762
|
+
# db = spanner.client "my-instance", "my-database"
|
1763
|
+
#
|
1764
|
+
# # Transaction tag will be set to "Users-Txn"
|
1765
|
+
# db.transaction request_options: { tag: "Users-Txn" } do |tx|
|
1766
|
+
# # The transaction tag set as "Users-Txn"
|
1767
|
+
# # The request tag set as "Users-Txn-1"
|
1768
|
+
# request_options = { tag: "Users-Txn-1" }
|
1769
|
+
# results = tx.execute_query "SELECT * FROM users",
|
1770
|
+
# request_options: request_options
|
1771
|
+
#
|
1772
|
+
# results.rows.each do |row|
|
1773
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
1774
|
+
# end
|
1775
|
+
#
|
1776
|
+
# # The transaction tag set as "Users-Txn"
|
1777
|
+
# tx.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1778
|
+
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1779
|
+
# end
|
1780
|
+
#
|
1781
|
+
def transaction deadline: 120, commit_options: nil,
|
1782
|
+
request_options: nil, call_options: nil
|
1354
1783
|
ensure_service!
|
1355
1784
|
unless Thread.current[:transaction_id].nil?
|
1356
1785
|
raise "Nested transactions are not allowed"
|
@@ -1360,43 +1789,54 @@ module Google
|
|
1360
1789
|
backoff = 1.0
|
1361
1790
|
start_time = current_time
|
1362
1791
|
|
1792
|
+
request_options = Convert.to_request_options \
|
1793
|
+
request_options, tag_type: :transaction_tag
|
1794
|
+
|
1363
1795
|
@pool.with_transaction do |tx|
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1796
|
+
if request_options
|
1797
|
+
tx.transaction_tag = request_options[:transaction_tag]
|
1798
|
+
end
|
1799
|
+
|
1800
|
+
begin
|
1801
|
+
Thread.current[:transaction_id] = tx.transaction_id
|
1802
|
+
yield tx
|
1803
|
+
commit_resp = @project.service.commit \
|
1804
|
+
tx.session.path, tx.mutations,
|
1805
|
+
transaction_id: tx.transaction_id,
|
1806
|
+
commit_options: commit_options,
|
1807
|
+
request_options: request_options,
|
1808
|
+
call_options: call_options
|
1809
|
+
resp = CommitResponse.from_grpc commit_resp
|
1810
|
+
commit_options ? resp : resp.timestamp
|
1811
|
+
rescue GRPC::Aborted, Google::Cloud::AbortedError => e
|
1812
|
+
# Re-raise if deadline has passed
|
1813
|
+
if current_time - start_time > deadline
|
1814
|
+
if e.is_a? GRPC::BadStatus
|
1815
|
+
e = Google::Cloud::Error.from_error e
|
1816
|
+
end
|
1817
|
+
raise e
|
1378
1818
|
end
|
1819
|
+
# Sleep the amount from RetryDelay, or incremental backoff
|
1820
|
+
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1821
|
+
# Create new transaction on the session and retry the block
|
1822
|
+
tx = tx.session.create_transaction
|
1823
|
+
retry
|
1824
|
+
rescue StandardError => e
|
1825
|
+
# Rollback transaction when handling unexpected error
|
1826
|
+
tx.session.rollback tx.transaction_id
|
1827
|
+
# Return nil if raised with rollback.
|
1828
|
+
return nil if e.is_a? Rollback
|
1829
|
+
# Re-raise error.
|
1379
1830
|
raise e
|
1831
|
+
ensure
|
1832
|
+
Thread.current[:transaction_id] = nil
|
1380
1833
|
end
|
1381
|
-
# Sleep the amount from RetryDelay, or incremental backoff
|
1382
|
-
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1383
|
-
# Create new transaction on the session and retry the block
|
1384
|
-
tx = tx.session.create_transaction
|
1385
|
-
retry
|
1386
|
-
rescue StandardError => e
|
1387
|
-
# Rollback transaction when handling unexpected error
|
1388
|
-
tx.session.rollback tx.transaction_id
|
1389
|
-
# Return nil if raised with rollback.
|
1390
|
-
return nil if e.is_a? Rollback
|
1391
|
-
# Re-raise error.
|
1392
|
-
raise e
|
1393
|
-
ensure
|
1394
|
-
Thread.current[:transaction_id] = nil
|
1395
1834
|
end
|
1396
1835
|
end
|
1397
1836
|
|
1398
1837
|
# rubocop:enable Metrics/AbcSize
|
1399
1838
|
# rubocop:enable Metrics/MethodLength
|
1839
|
+
# rubocop:enable Metrics/BlockLength
|
1400
1840
|
|
1401
1841
|
##
|
1402
1842
|
# Creates a snapshot read-only transaction for reads that execute
|
@@ -1508,12 +1948,13 @@ module Google
|
|
1508
1948
|
# Hash values must contain the type value. If a Hash is used the
|
1509
1949
|
# fields will be created using the same order as the Hash keys.
|
1510
1950
|
#
|
1511
|
-
# Supported type values
|
1951
|
+
# Supported type values include:
|
1512
1952
|
#
|
1513
1953
|
# * `:BOOL`
|
1514
1954
|
# * `:BYTES`
|
1515
1955
|
# * `:DATE`
|
1516
1956
|
# * `:FLOAT64`
|
1957
|
+
# * `:NUMERIC`
|
1517
1958
|
# * `:INT64`
|
1518
1959
|
# * `:STRING`
|
1519
1960
|
# * `:TIMESTAMP`
|
@@ -1804,11 +2245,10 @@ module Google
|
|
1804
2245
|
# GRPC::Aborted
|
1805
2246
|
def delay_from_aborted err
|
1806
2247
|
return nil if err.nil?
|
1807
|
-
if err.respond_to?(:metadata) && err.metadata["
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
nanos = err.metadata["retryDelay"]["nanos"].to_i
|
2248
|
+
if err.respond_to?(:metadata) && err.metadata["google.rpc.retryinfo-bin"]
|
2249
|
+
retry_info = Google::Rpc::RetryInfo.decode err.metadata["google.rpc.retryinfo-bin"]
|
2250
|
+
seconds = retry_info["retry_delay"].seconds
|
2251
|
+
nanos = retry_info["retry_delay"].nanos
|
1812
2252
|
return seconds if nanos.zero?
|
1813
2253
|
return seconds + (nanos / 1_000_000_000.0)
|
1814
2254
|
end
|