google-cloud-spanner 2.7.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65d994b98b82ef3397a11c418a6b46f54d76eca91c79dd02c024ad4761dcf0c0
4
- data.tar.gz: 805fb5c52d24d20902c609b83d9afd7aafa1ff6bd4bc8a35485bc04db2441322
3
+ metadata.gz: 507e92dd7d005df48967afbdabd4df9df518bca1cd0da416742bf21de28afa76
4
+ data.tar.gz: 14560745cbe0a401d6c5f7c82b9c67c739083e851177c0cbdcdc9006b4acb24e
5
5
  SHA512:
6
- metadata.gz: f624455464b4ec987fde529f018f6b1e88b5a9ad5e769cd7bcb034980af1ebae5cde7c7567e92f9e5bc35226e0ade6be852e63d601b1d83420d75c0c35c3f1ba
7
- data.tar.gz: 8baa9252146c458bb5f48aa7043c97584a4295d7afee72e21691e9a4be623d9fc8d9c62cc6f0a8b9c3b8ad0d4b34209a0ee48d88e98b9bd695153ea7024a5a8d
6
+ metadata.gz: 4b21e91bbe78fc964d9ab3c38209857d434ea9c3c3773298a6531527d60d882eb5cd805d6d4acc860454844dde411e9b08b595c1e3d742b759362eb6b9b8644c
7
+ data.tar.gz: ee18b40a314dc71b3b58f42af1bb761d2fd36ce5d349bdb9425635e61051399400644faa1e5f43be4a3db6a01591242bfcd8077d051e5f7e00d50f8e766b575d
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 instead of placing them in environment variables or providing them as arguments.
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,36 +1,46 @@
1
1
  # Release History
2
2
 
3
+ ### 2.10.0 / 2021-08-24
4
+
5
+ #### Features
6
+
7
+ * add field JSON type support
8
+
9
+ ### 2.9.0 / 2021-07-26
10
+
11
+ #### Features
12
+
13
+ * support request tagging
14
+
15
+ ### 2.8.1 / 2021-07-08
16
+
17
+ #### Documentation
18
+
19
+ * Update AUTHENTICATION.md in handwritten packages
20
+
21
+ ### 2.8.0 / 2021-06-17
22
+
23
+ #### Features
24
+
25
+ * create instance using processing units/node count
26
+
3
27
  ### 2.7.0 / 2021-06-09
4
28
 
5
29
  #### Features
6
30
 
7
- * add the support of optimizer statistics package ([#7591](https://www.github.com/googleapis/google-cloud-ruby/issues/7591))
8
- * feat(spanner): add the support of optimizer statistics package
9
- * Fix rubocop issues.
10
- * Fix the env issue.
11
- * database create time access method ([#11617](https://www.github.com/googleapis/google-cloud-ruby/issues/11617))
12
- * added database create time method
13
- * remove assert for databse create time
14
- * RPC priority request option. ([#11258](https://www.github.com/googleapis/google-cloud-ruby/issues/11258))
31
+ * add the support of optimizer statistics package
32
+ * database create time access method
33
+ * RPC priority request option.
15
34
 
16
35
  #### Bug Fixes
17
36
 
18
- * extract binary retry info from error ([#11656](https://www.github.com/googleapis/google-cloud-ruby/issues/11656))
19
- * fix: extract binary retry info from error
20
- * fix: remove unrelated frozen_string_literal change
21
- * fix: remove unnecessary parentheses
37
+ * extract binary retry info from error
22
38
 
23
39
  ### 2.6.0 / 2021-03-31
24
40
 
25
41
  #### Features
26
42
 
27
- * add cmek backup support - ext of [#8142](https://www.github.com/googleapis/google-cloud-ruby/issues/8142) ([#8168](https://www.github.com/googleapis/google-cloud-ruby/issues/8168))
28
- * feat(spanner): add cmek backup support
29
- * Add encryption_config to restore database.
30
- * doc example for backup create with encryption config
31
- * create backup with encryption type
32
- * backup restore with encryption type changes
33
- * fix typo
43
+ * add cmek backup support
34
44
  * add cmek db support
35
45
 
36
46
  ### 2.5.0 / 2021-03-10
@@ -43,27 +53,14 @@
43
53
 
44
54
  #### Features
45
55
 
46
- * Point In Time Recovery (PITR) ([#8169](https://www.github.com/googleapis/google-cloud-ruby/issues/8169))
47
- * feat(spanner): support pitr-lite
48
- * feature(spanner): adds test for throttled
49
- * feat(spanner): adds version time to backup
50
- * test(spanner): adds unit test for create backup
51
- * feat(spanner): exposes version time in backup
52
- * chore: fixes rubocop violations
53
- * fix: addresses PR comments
54
- * test: adds integration tests for pitr backup
56
+ * Point In Time Recovery (PITR)
55
57
 
56
58
  ### 2.3.0 / 2021-02-09
57
59
 
58
60
  #### Features
59
61
 
60
- * CommitStats in CommitResponse ([#8058](https://www.github.com/googleapis/google-cloud-ruby/issues/8058))
61
- * optionalize `credentials` when using cloud spanner emulator host ([#8416](https://www.github.com/googleapis/google-cloud-ruby/issues/8416))
62
- * Optionalize `credentials` when using Cloud Spanner Emulator
63
- * Remove unnecessary credentials stub for emulator_host in Google::Cloud::Spanner.new
64
- * Add test of explicit project_id in Google::Cloud::Spanner.new
65
- * Update document for `emulator_host` without credentials
66
- * Tidy code according to rubocop settings
62
+ * CommitStats in CommitResponse
63
+ * optionalize `credentials` when using cloud spanner emulator host
67
64
 
68
65
  ### 2.2.0 / 2020-09-15
69
66
 
@@ -123,25 +120,20 @@ please review the docs for the new `google-cloud-spanner-v1` gem. In particular:
123
120
 
124
121
  #### Features
125
122
 
126
- * Added support for backing up and restoring databases ([#5053](https://www.github.com/googleapis/google-cloud-ruby/issues/5053))
123
+ * Added support for backing up and restoring databases
127
124
 
128
125
  ### 1.15.0 / 2020-03-15
129
126
 
130
127
  #### Features
131
128
 
132
- * Added support for query options ([#4907](https://www.github.com/googleapis/google-cloud-ruby/issues/4907))
133
- * Added support for specifying the query optimizer version.
129
+ * Added support for query options
134
130
  * Support separate project setting for quota/billing
135
131
 
136
132
  ### 1.14.0 / 2020-02-18
137
133
 
138
134
  #### Features
139
135
 
140
- * allow custom lib name and version for telemetry purpose ([#4762](https://www.github.com/googleapis/google-cloud-ruby/issues/4762))
141
- * allow custom lib name and version for telemetry purpose
142
- * format docs
143
- * added custom lib name and version prefix
144
- * update test cases for lib name and version
136
+ * allow custom lib name and version for telemetry purpose
145
137
 
146
138
  ### 1.13.1 / 2020-01-22
147
139
 
@@ -236,6 +236,10 @@ module Google
236
236
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
237
237
  # `:PRIORITY_HIGH`. If priority not set then default is
238
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.
239
243
  # @param [Hash] call_options A hash of values to specify the custom
240
244
  # call options, e.g., timeout, retries, etc. Call options are
241
245
  # optional. The following settings can be provided:
@@ -403,6 +407,21 @@ module Google
403
407
  # puts "User #{row[:id]} is #{row[:name]}"
404
408
  # end
405
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
+ #
406
425
  def execute_query sql, params: nil, types: nil, single_use: nil,
407
426
  query_options: nil, request_options: nil,
408
427
  call_options: nil
@@ -410,7 +429,8 @@ module Google
410
429
  ensure_service!
411
430
 
412
431
  params, types = Convert.to_input_params_and_types params, types
413
-
432
+ request_options = Convert.to_request_options request_options,
433
+ tag_type: :request_tag
414
434
  single_use_tx = single_use_transaction single_use
415
435
  results = nil
416
436
  @pool.with_session do |session|
@@ -580,6 +600,10 @@ module Google
580
600
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
581
601
  # `:PRIORITY_HIGH`. If priority not set then default is
582
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.
583
607
  # @param [Hash] call_options A hash of values to specify the custom
584
608
  # call options, e.g., timeout, retries, etc. Call options are
585
609
  # optional. The following settings can be provided:
@@ -657,12 +681,27 @@ module Google
657
681
  # "UPDATE users SET friends = NULL WHERE active = @active",
658
682
  # params: { active: false }, request_options: request_options
659
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
+ #
660
696
  def execute_partition_update sql, params: nil, types: nil,
661
697
  query_options: nil, request_options: nil,
662
698
  call_options: nil
663
699
  ensure_service!
664
700
 
665
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
+
666
705
  results = nil
667
706
  @pool.with_session do |session|
668
707
  results = session.execute_query \
@@ -761,6 +800,10 @@ module Google
761
800
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
762
801
  # `:PRIORITY_HIGH`. If priority not set then default is
763
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.
764
807
  # @param [Hash] call_options A hash of values to specify the custom
765
808
  # call options, e.g., timeout, retries, etc. Call options are
766
809
  # optional. The following settings can be provided:
@@ -840,6 +883,22 @@ module Google
840
883
  # puts "User #{row[:id]} is #{row[:name]}"
841
884
  # end
842
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
+ #
843
902
  def read table, columns, keys: nil, index: nil, limit: nil,
844
903
  single_use: nil, request_options: nil, call_options: nil
845
904
  validate_single_use_args! single_use
@@ -847,8 +906,10 @@ module Google
847
906
 
848
907
  columns = Array(columns).map(&:to_s)
849
908
  keys = Convert.to_key_set keys
850
-
851
909
  single_use_tx = single_use_transaction single_use
910
+ request_options = Convert.to_request_options request_options,
911
+ tag_type: :request_tag
912
+
852
913
  results = nil
853
914
  @pool.with_session do |session|
854
915
  results = session.read \
@@ -914,6 +975,9 @@ module Google
914
975
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
915
976
  # `:PRIORITY_HIGH`. If priority not set then default is
916
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}`.
917
981
  #
918
982
  # @return [Time, CommitResponse] The timestamp at which the operation
919
983
  # committed. If commit options are set it returns {CommitResponse}.
@@ -954,7 +1018,23 @@ module Google
954
1018
  # db.upsert "users", [{ id: 1, name: "Charlie", active: false }],
955
1019
  # request_options: request_options
956
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
+ #
957
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
+
958
1038
  @pool.with_session do |session|
959
1039
  session.upsert table, rows, commit_options: commit_options,
960
1040
  request_options: request_options
@@ -999,7 +1079,6 @@ module Google
999
1079
  #
1000
1080
  # See [Data
1001
1081
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1002
- #
1003
1082
  # @param [Hash] commit_options A hash of commit options.
1004
1083
  # e.g., return_commit_stats. Commit options are optional.
1005
1084
  # The following options can be provided:
@@ -1015,6 +1094,9 @@ module Google
1015
1094
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1016
1095
  # `:PRIORITY_HIGH`. If priority not set then default is
1017
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}`.
1018
1100
  #
1019
1101
  # @return [Time, CommitResponse] The timestamp at which the operation
1020
1102
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1055,7 +1137,23 @@ module Google
1055
1137
  # db.insert "users", [{ id: 1, name: "Charlie", active: false }],
1056
1138
  # request_options: request_options
1057
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
+ #
1058
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
+
1059
1157
  @pool.with_session do |session|
1060
1158
  session.insert table, rows, commit_options: commit_options,
1061
1159
  request_options: request_options
@@ -1099,7 +1197,6 @@ module Google
1099
1197
  #
1100
1198
  # See [Data
1101
1199
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1102
- #
1103
1200
  # @param [Hash] commit_options A hash of commit options.
1104
1201
  # e.g., return_commit_stats. Commit options are optional.
1105
1202
  # The following options can be provided:
@@ -1115,6 +1212,9 @@ module Google
1115
1212
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1116
1213
  # `:PRIORITY_HIGH`. If priority not set then default is
1117
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}`.
1118
1218
  #
1119
1219
  # @return [Time, CommitResponse] The timestamp at which the operation
1120
1220
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1155,7 +1255,22 @@ module Google
1155
1255
  # db.update "users", [{ id: 1, name: "Charlie", active: false }],
1156
1256
  # request_options: request_options
1157
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
+ #
1158
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
+
1159
1274
  @pool.with_session do |session|
1160
1275
  session.update table, rows, commit_options: commit_options,
1161
1276
  request_options: request_options
@@ -1201,7 +1316,6 @@ module Google
1201
1316
  #
1202
1317
  # See [Data
1203
1318
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1204
- #
1205
1319
  # @param [Hash] commit_options A hash of commit options.
1206
1320
  # e.g., return_commit_stats. Commit options are optional.
1207
1321
  # The following options can be provided:
@@ -1217,6 +1331,9 @@ module Google
1217
1331
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1218
1332
  # `:PRIORITY_HIGH`. If priority not set then default is
1219
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}`.
1220
1337
  #
1221
1338
  # @return [Time, CommitResponse] The timestamp at which the operation
1222
1339
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1257,6 +1374,18 @@ module Google
1257
1374
  # db.replace "users", [{ id: 1, name: "Charlie", active: false }],
1258
1375
  # request_options: request_options
1259
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
+ #
1260
1389
  def replace table, rows, commit_options: nil, request_options: nil
1261
1390
  @pool.with_session do |session|
1262
1391
  session.replace table, rows, commit_options: commit_options,
@@ -1299,6 +1428,9 @@ module Google
1299
1428
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1300
1429
  # `:PRIORITY_HIGH`. If priority not set then default is
1301
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}`.
1302
1434
  # @param [Hash] call_options A hash of values to specify the custom
1303
1435
  # call options, e.g., timeout, retries, etc. Call options are
1304
1436
  # optional. The following settings can be provided:
@@ -1348,8 +1480,21 @@ module Google
1348
1480
  # request_options = { priority: :PRIORITY_MEDIUM }
1349
1481
  # db.delete "users", [1, 2, 3], request_options: request_options
1350
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
+ #
1351
1493
  def delete table, keys = [], commit_options: nil, request_options: nil,
1352
1494
  call_options: nil
1495
+ request_options = Convert.to_request_options \
1496
+ request_options, tag_type: :transaction_tag
1497
+
1353
1498
  @pool.with_session do |session|
1354
1499
  session.delete table, keys, commit_options: commit_options,
1355
1500
  request_options: request_options,
@@ -1387,6 +1532,9 @@ module Google
1387
1532
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1388
1533
  # `:PRIORITY_HIGH`. If priority not set then default is
1389
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}`.
1390
1538
  # @param [Hash] call_options A hash of values to specify the custom
1391
1539
  # call options, e.g., timeout, retries, etc. Call options are
1392
1540
  # optional. The following settings can be provided:
@@ -1447,10 +1595,26 @@ module Google
1447
1595
  # c.insert "users", [{ id: 2, name: "Harvey", active: true }]
1448
1596
  # end
1449
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
+ #
1450
1611
  def commit commit_options: nil, request_options: nil,
1451
1612
  call_options: nil, &block
1452
1613
  raise ArgumentError, "Must provide a block" unless block_given?
1453
1614
 
1615
+ request_options = Convert.to_request_options \
1616
+ request_options, tag_type: :transaction_tag
1617
+
1454
1618
  @pool.with_session do |session|
1455
1619
  session.commit(
1456
1620
  commit_options: commit_options, request_options: request_options,
@@ -1494,6 +1658,11 @@ module Google
1494
1658
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1495
1659
  # `:PRIORITY_HIGH`. If priority not set then default is
1496
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}`
1665
+ #
1497
1666
  # @param [Hash] call_options A hash of values to specify the custom
1498
1667
  # call options, e.g., timeout, retries, etc. Call options are
1499
1668
  # optional. The following settings can be provided:
@@ -1585,6 +1754,30 @@ module Google
1585
1754
  # request_options: request_options
1586
1755
  # end
1587
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
+ #
1588
1781
  def transaction deadline: 120, commit_options: nil,
1589
1782
  request_options: nil, call_options: nil
1590
1783
  ensure_service!
@@ -1596,39 +1789,48 @@ module Google
1596
1789
  backoff = 1.0
1597
1790
  start_time = current_time
1598
1791
 
1792
+ request_options = Convert.to_request_options \
1793
+ request_options, tag_type: :transaction_tag
1794
+
1599
1795
  @pool.with_transaction do |tx|
1600
- Thread.current[:transaction_id] = tx.transaction_id
1601
- yield tx
1602
- commit_resp = @project.service.commit \
1603
- tx.session.path, tx.mutations,
1604
- transaction_id: tx.transaction_id,
1605
- commit_options: commit_options,
1606
- request_options: request_options,
1607
- call_options: call_options
1608
- resp = CommitResponse.from_grpc commit_resp
1609
- commit_options ? resp : resp.timestamp
1610
- rescue GRPC::Aborted, Google::Cloud::AbortedError => e
1611
- # Re-raise if deadline has passed
1612
- if current_time - start_time > deadline
1613
- if e.is_a? GRPC::BadStatus
1614
- e = Google::Cloud::Error.from_error e
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
1615
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.
1616
1830
  raise e
1831
+ ensure
1832
+ Thread.current[:transaction_id] = nil
1617
1833
  end
1618
- # Sleep the amount from RetryDelay, or incremental backoff
1619
- sleep(delay_from_aborted(e) || backoff *= 1.3)
1620
- # Create new transaction on the session and retry the block
1621
- tx = tx.session.create_transaction
1622
- retry
1623
- rescue StandardError => e
1624
- # Rollback transaction when handling unexpected error
1625
- tx.session.rollback tx.transaction_id
1626
- # Return nil if raised with rollback.
1627
- return nil if e.is_a? Rollback
1628
- # Re-raise error.
1629
- raise e
1630
- ensure
1631
- Thread.current[:transaction_id] = nil
1632
1834
  end
1633
1835
  end
1634
1836
 
@@ -99,8 +99,7 @@ module Google
99
99
  if field.is_a? Fields
100
100
  field.struct(obj).to_grpc_value
101
101
  else
102
- raise ArgumentError,
103
- "A hash value cannot be set to type #{field}."
102
+ Google::Protobuf::Value.new string_value: obj.to_json
104
103
  end
105
104
  else
106
105
  if obj.respond_to?(:read) && obj.respond_to?(:rewind)
@@ -223,6 +222,8 @@ module Google
223
222
  Data.from_grpc value.list_value.values, type.struct_type.fields
224
223
  when :NUMERIC
225
224
  BigDecimal value.string_value
225
+ when :JSON
226
+ JSON.parse value.string_value
226
227
  end
227
228
  end
228
229
 
@@ -324,6 +325,25 @@ module Google
324
325
 
325
326
  [input_params, input_param_types]
326
327
  end
328
+
329
+ ##
330
+ # Build request options by replacing tag to respecitve statistics
331
+ # collection tag type.
332
+ #
333
+ # @param [Hash] options Common request options.
334
+ # * `:tag` (String) A tag used for statistics collection.
335
+ #
336
+ # @param [Symbol] tag_type Request tag type.
337
+ # Possible values are `request_tag`, `transaction_tag`
338
+ # @return [Hash, nil]
339
+ #
340
+ def to_request_options options, tag_type: nil
341
+ return unless options
342
+
343
+ return options unless options.key? :tag
344
+
345
+ options.transform_keys { |k| k == :tag ? tag_type : k }
346
+ end
327
347
  end
328
348
 
329
349
  # rubocop:enable all
@@ -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
- job_grpc = service.update_instance @grpc
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
- # Required.
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
 
@@ -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
- labels: nil, call_options: nil
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, labels: labels
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
- mask = Google::Protobuf::FieldMask.new(
150
- paths: %w[display_name node_count labels]
151
- )
152
- request = { instance: instance, field_mask: mask }
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
 
@@ -434,13 +441,18 @@ module Google
434
441
  service.rollback request, opts
435
442
  end
436
443
 
437
- def begin_transaction session_name, call_options: nil
444
+ def begin_transaction session_name, request_options: nil,
445
+ call_options: nil
438
446
  tx_opts = V1::TransactionOptions.new(
439
447
  read_write: V1::TransactionOptions::ReadWrite.new
440
448
  )
441
449
  opts = default_options session_name: session_name,
442
450
  call_options: call_options
443
- request = { session: session_name, options: tx_opts }
451
+ request = {
452
+ session: session_name,
453
+ options: tx_opts,
454
+ request_options: request_options
455
+ }
444
456
  service.begin_transaction request, opts
445
457
  end
446
458
 
@@ -167,6 +167,23 @@ module Google
167
167
  # available optimizer version.
168
168
  # * `:optimizer_statistics_package` (String) Statistics package to
169
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}
170
187
  # @param [Hash] call_options A hash of values to specify the custom
171
188
  # call options, e.g., timeout, retries, etc. Call options are
172
189
  # optional. The following settings can be provided:
@@ -349,6 +366,23 @@ module Google
349
366
  # transactions.
350
367
  # @param [Integer] seqno A per-transaction sequence number used to
351
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}
352
386
  # @param [Hash] call_options A hash of values to specify the custom
353
387
  # call options, e.g., timeout, retries, etc. Call options are
354
388
  # optional. The following settings can be provided:
@@ -413,6 +447,23 @@ module Google
413
447
  # @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
414
448
  # transaction selector value to send. Only used for single-use
415
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}
416
467
  # @param [Hash] call_options A hash of values to specify the custom
417
468
  # call options, e.g., timeout, retries, etc. Call options are
418
469
  # optional. The following settings can be provided:
@@ -506,6 +557,23 @@ module Google
506
557
  # {CommitResponse}. Default value is `false`
507
558
  #
508
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}
509
577
  # @param [Hash] call_options A hash of values to specify the custom
510
578
  # call options, e.g., timeout, retries, etc. Call options are
511
579
  # optional. The following settings can be provided:
@@ -605,6 +673,23 @@ module Google
605
673
  # then statistics related to the transaction will be included in
606
674
  # {CommitResponse}. Default value is `false`
607
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}
608
693
  # @param [Hash] call_options A hash of values to specify the custom
609
694
  # call options, e.g., timeout, retries, etc. Call options are
610
695
  # optional. The following settings can be provided:
@@ -696,6 +781,23 @@ module Google
696
781
  # then statistics related to the transaction will be included in
697
782
  # {CommitResponse}. Default value is `false`
698
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}
699
801
  # @param [Hash] call_options A hash of values to specify the custom
700
802
  # call options, e.g., timeout, retries, etc. Call options are
701
803
  # optional. The following settings can be provided:
@@ -786,6 +888,23 @@ module Google
786
888
  # then statistics related to the transaction will be included in
787
889
  # {CommitResponse}. Default value is `false`
788
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}
789
908
  # @param [Hash] call_options A hash of values to specify the custom
790
909
  # call options, e.g., timeout, retries, etc. Call options are
791
910
  # optional. The following settings can be provided:
@@ -878,6 +997,23 @@ module Google
878
997
  # then statistics related to the transaction will be included in
879
998
  # {CommitResponse}. Default value is `false`.
880
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}
881
1017
  # @param [Hash] call_options A hash of values to specify the custom
882
1018
  # call options, e.g., timeout, retries, etc. Call options are
883
1019
  # optional. The following settings can be provided:
@@ -950,6 +1086,23 @@ module Google
950
1086
  # then statistics related to the transaction will be included in
951
1087
  # {CommitResponse}. Default value is `false`
952
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}
953
1106
  # @param [Hash] call_options A hash of values to specify the custom
954
1107
  # call options, e.g., timeout, retries, etc. Call options are
955
1108
  # optional. The following settings can be provided:
@@ -77,6 +77,9 @@ module Google
77
77
  # @private The Session object.
78
78
  attr_accessor :session
79
79
 
80
+ # @private Transaction tag for statistics collection.
81
+ attr_accessor :transaction_tag
82
+
80
83
  def initialize
81
84
  @commit = Commit.new
82
85
  @seqno = 0
@@ -167,6 +170,10 @@ module Google
167
170
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
168
171
  # `:PRIORITY_HIGH`. If priority not set then default is
169
172
  # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
173
+ # * `:tag` (String) A per-request tag which can be applied to
174
+ # queries or reads, used for statistics collection. Tag must be a
175
+ # valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
176
+ # and 64 characters in length.
170
177
  # @param [Hash] call_options A hash of values to specify the custom
171
178
  # call options, e.g., timeout, retries, etc. Call options are
172
179
  # optional. The following settings can be provided:
@@ -333,6 +340,7 @@ module Google
333
340
  @seqno += 1
334
341
 
335
342
  params, types = Convert.to_input_params_and_types params, types
343
+ request_options = build_request_options request_options
336
344
  session.execute_query sql, params: params, types: types,
337
345
  transaction: tx_selector, seqno: @seqno,
338
346
  query_options: query_options,
@@ -419,6 +427,10 @@ module Google
419
427
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
420
428
  # `:PRIORITY_HIGH`. If priority not set then default is
421
429
  # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
430
+ # * `:tag` (String) A per-request tag which can be applied to
431
+ # queries or reads, used for statistics collection. Tag must be a
432
+ # valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
433
+ # and 64 characters in length.
422
434
  # @param [Hash] call_options A hash of values to specify the custom
423
435
  # call options, e.g., timeout, retries, etc. Call options are
424
436
  # optional. The following settings can be provided:
@@ -525,6 +537,10 @@ module Google
525
537
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
526
538
  # `:PRIORITY_HIGH`. If priority not set then default is
527
539
  # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
540
+ # * `:tag` (String) A per-request tag which can be applied to
541
+ # queries or reads, used for statistics collection. Tag must be a
542
+ # valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
543
+ # and 64 characters in length.
528
544
  # @param [Hash] call_options A hash of values to specify the custom
529
545
  # call options, e.g., timeout, retries, etc. Call options are
530
546
  # optional. The following settings can be provided:
@@ -597,6 +613,8 @@ module Google
597
613
  def batch_update request_options: nil, call_options: nil, &block
598
614
  ensure_session!
599
615
  @seqno += 1
616
+
617
+ request_options = build_request_options request_options
600
618
  session.batch_update tx_selector, @seqno,
601
619
  request_options: request_options,
602
620
  call_options: call_options, &block
@@ -626,6 +644,10 @@ module Google
626
644
  # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
627
645
  # `:PRIORITY_HIGH`. If priority not set then default is
628
646
  # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
647
+ # * `:tag` (String) A per-request tag which can be applied to
648
+ # queries or reads, used for statistics collection. Tag must be a
649
+ # valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
650
+ # and 64 characters in length.
629
651
  # @param [Hash] call_options A hash of values to specify the custom
630
652
  # call options, e.g., timeout, retries, etc. Call options are
631
653
  # optional. The following settings can be provided:
@@ -663,7 +685,7 @@ module Google
663
685
 
664
686
  columns = Array(columns).map(&:to_s)
665
687
  keys = Convert.to_key_set keys
666
-
688
+ request_options = build_request_options request_options
667
689
  session.read table, columns, keys: keys, index: index, limit: limit,
668
690
  transaction: tx_selector,
669
691
  request_options: request_options,
@@ -1097,6 +1119,20 @@ module Google
1097
1119
  V1::TransactionSelector.new id: transaction_id
1098
1120
  end
1099
1121
 
1122
+ ##
1123
+ # @private Build request options. If transaction tag is set
1124
+ # then add into request options.
1125
+ def build_request_options options
1126
+ options = Convert.to_request_options options, tag_type: :request_tag
1127
+
1128
+ if transaction_tag
1129
+ options ||= {}
1130
+ options[:transaction_tag] = transaction_tag
1131
+ end
1132
+
1133
+ options
1134
+ end
1135
+
1100
1136
  ##
1101
1137
  # @private Raise an error unless an active connection to the service is
1102
1138
  # available.
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Spanner
19
- VERSION = "2.7.0".freeze
19
+ VERSION = "2.10.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-spanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-06-09 00:00:00.000000000 Z
12
+ date: 2021-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core