google-cloud-spanner 2.6.0 → 2.7.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: 0faea5b1e581fbc3981a52fa5ea8b2f1674f79fc71bc3000639020739747b5ea
4
- data.tar.gz: bd4d345cbf3cefc8dbba31a2d74d4f729e8a5d9e3364277ba3d168d572c2538b
3
+ metadata.gz: 65d994b98b82ef3397a11c418a6b46f54d76eca91c79dd02c024ad4761dcf0c0
4
+ data.tar.gz: 805fb5c52d24d20902c609b83d9afd7aafa1ff6bd4bc8a35485bc04db2441322
5
5
  SHA512:
6
- metadata.gz: 8b315bed1e2a9ef29f956333086d2ad35a77f8d8c305440fea90830b89d074269c8969cb5c6002a33f3f660974defa165eb270d4671338a3f7df43c07015d78f
7
- data.tar.gz: c2807ef7f0f1289a6515114c34aba03dd3959a50467f4c2fa6ef22efd88c2b75db87b40e1ec8b5a3b29a7e334f5c96d2fc07a1196e3100a3a6c518d726da3ecd
6
+ metadata.gz: f624455464b4ec987fde529f018f6b1e88b5a9ad5e769cd7bcb034980af1ebae5cde7c7567e92f9e5bc35226e0ade6be852e63d601b1d83420d75c0c35c3f1ba
7
+ data.tar.gz: 8baa9252146c458bb5f48aa7043c97584a4295d7afee72e21691e9a4be623d9fc8d9c62cc6f0a8b9c3b8ad0d4b34209a0ee48d88e98b9bd695153ea7024a5a8d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Release History
2
2
 
3
+ ### 2.7.0 / 2021-06-09
4
+
5
+ #### Features
6
+
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))
15
+
16
+ #### Bug Fixes
17
+
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
22
+
3
23
  ### 2.6.0 / 2021-03-31
4
24
 
5
25
  #### Features
data/OVERVIEW.md CHANGED
@@ -316,7 +316,7 @@ spanner = Google::Cloud::Spanner.new
316
316
  instance = spanner.instance "my-instance"
317
317
 
318
318
  instance.delete
319
- ````
319
+ ```
320
320
 
321
321
  ## Additional information
322
322
 
@@ -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
- # "SELECT * FROM users",
602
- # query_options: { optimizer_version: "1" }
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.transaction do |tx|
46
- # results = tx.execute_query "SELECT * FROM users"
45
+ # results = db.execute_query "SELECT * FROM users"
47
46
  #
48
- # results.rows.each do |row|
49
- # puts "User #{row[:id]} is #{row[:name]}"
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,16 @@ 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`.
226
239
  # @param [Hash] call_options A hash of values to specify the custom
227
240
  # call options, e.g., timeout, retries, etc. Call options are
228
241
  # optional. The following settings can be provided:
@@ -343,7 +356,10 @@ module Google
343
356
  # db = spanner.client "my-instance", "my-database"
344
357
  #
345
358
  # results = db.execute_query \
346
- # "SELECT * FROM users", query_options: { optimizer_version: "1" }
359
+ # "SELECT * FROM users", query_options: {
360
+ # optimizer_version: "1",
361
+ # optimizer_statistics_package: "auto_20191128_14_47_22UTC"
362
+ # }
347
363
  #
348
364
  # results.rows.each do |row|
349
365
  # puts "User #{row[:id]} is #{row[:name]}"
@@ -372,8 +388,24 @@ module Google
372
388
  # puts "User #{row[:id]} is #{row[:name]}"
373
389
  # end
374
390
  #
391
+ # @example Using request options.
392
+ # require "google/cloud/spanner"
393
+ #
394
+ # spanner = Google::Cloud::Spanner.new
395
+ #
396
+ # db = spanner.client "my-instance", "my-database"
397
+ #
398
+ # request_options = { priority: :PRIORITY_MEDIUM }
399
+ # results = db.execute_query "SELECT * FROM users",
400
+ # request_options: request_options
401
+ #
402
+ # results.rows.each do |row|
403
+ # puts "User #{row[:id]} is #{row[:name]}"
404
+ # end
405
+ #
375
406
  def execute_query sql, params: nil, types: nil, single_use: nil,
376
- query_options: nil, call_options: nil
407
+ query_options: nil, request_options: nil,
408
+ call_options: nil
377
409
  validate_single_use_args! single_use
378
410
  ensure_service!
379
411
 
@@ -384,7 +416,8 @@ module Google
384
416
  @pool.with_session do |session|
385
417
  results = session.execute_query \
386
418
  sql, params: params, types: types, transaction: single_use_tx,
387
- query_options: query_options, call_options: call_options
419
+ query_options: query_options, request_options: request_options,
420
+ call_options: call_options
388
421
  end
389
422
  results
390
423
  end
@@ -408,7 +441,7 @@ module Google
408
441
  # once" semantics.
409
442
  #
410
443
  # Where DML statements must be executed using Transaction (see
411
- # {Transaction#execute_update}), Paritioned DML statements are executed
444
+ # {Transaction#execute_update}), Partitioned DML statements are executed
412
445
  # outside of a read/write transaction.
413
446
  #
414
447
  # Not all DML statements can be executed in the Partitioned DML mode and
@@ -494,6 +527,7 @@ module Google
494
527
  # | `BOOL` | `true`/`false` | |
495
528
  # | `INT64` | `Integer` | |
496
529
  # | `FLOAT64` | `Float` | |
530
+ # | `NUMERIC` | `BigDecimal` | |
497
531
  # | `STRING` | `String` | |
498
532
  # | `DATE` | `Date` | |
499
533
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -520,6 +554,7 @@ module Google
520
554
  # * `:BYTES`
521
555
  # * `:DATE`
522
556
  # * `:FLOAT64`
557
+ # * `:NUMERIC`
523
558
  # * `:INT64`
524
559
  # * `:STRING`
525
560
  # * `:TIMESTAMP`
@@ -535,6 +570,16 @@ module Google
535
570
  # * `:optimizer_version` (String) The version of optimizer to use.
536
571
  # Empty to use database default. "latest" to use the latest
537
572
  # available optimizer version.
573
+ # * `:optimizer_statistics_package` (String) Statistics package to
574
+ # use. Empty to use the database default.
575
+ # @param [Hash] request_options Common request options.
576
+ #
577
+ # * `:priority` (String) The relative priority for requests.
578
+ # The priority acts as a hint to the Cloud Spanner scheduler
579
+ # and does not guarantee priority or order of execution.
580
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
581
+ # `:PRIORITY_HIGH`. If priority not set then default is
582
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
538
583
  # @param [Hash] call_options A hash of values to specify the custom
539
584
  # call options, e.g., timeout, retries, etc. Call options are
540
585
  # optional. The following settings can be provided:
@@ -577,7 +622,10 @@ module Google
577
622
  #
578
623
  # row_count = db.execute_partition_update \
579
624
  # "UPDATE users SET friends = NULL WHERE active = false",
580
- # query_options: { optimizer_version: "1" }
625
+ # query_options: {
626
+ # optimizer_version: "1",
627
+ # optimizer_statistics_package: "auto_20191128_14_47_22UTC"
628
+ # }
581
629
  #
582
630
  # @example Query using custom timeout and retry policy:
583
631
  # require "google/cloud/spanner"
@@ -598,8 +646,20 @@ module Google
598
646
  # "UPDATE users SET friends = NULL WHERE active = false",
599
647
  # call_options: call_options
600
648
  #
649
+ # @example Using request options.
650
+ # require "google/cloud/spanner"
651
+ #
652
+ # spanner = Google::Cloud::Spanner.new
653
+ # db = spanner.client "my-instance", "my-database"
654
+ #
655
+ # request_options = { priority: :PRIORITY_MEDIUM }
656
+ # row_count = db.execute_partition_update \
657
+ # "UPDATE users SET friends = NULL WHERE active = @active",
658
+ # params: { active: false }, request_options: request_options
659
+ #
601
660
  def execute_partition_update sql, params: nil, types: nil,
602
- query_options: nil, call_options: nil
661
+ query_options: nil, request_options: nil,
662
+ call_options: nil
603
663
  ensure_service!
604
664
 
605
665
  params, types = Convert.to_input_params_and_types params, types
@@ -608,7 +668,8 @@ module Google
608
668
  results = session.execute_query \
609
669
  sql, params: params, types: types,
610
670
  transaction: pdml_transaction(session),
611
- query_options: query_options, call_options: call_options
671
+ query_options: query_options, request_options: request_options,
672
+ call_options: call_options
612
673
  end
613
674
  # Stream all PartialResultSet to get ResultSetStats
614
675
  results.rows.to_a
@@ -640,6 +701,9 @@ module Google
640
701
  # @param [Hash] single_use Perform the read with a single-use snapshot
641
702
  # (read-only transaction). (See
642
703
  # [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
704
+ # If no value is specified for this parameter, Cloud Spanner will use
705
+ # a single use read-only transaction with strong timestamp bound as
706
+ # default.
643
707
  # The snapshot can be created by providing exactly one of the
644
708
  # following options in the hash:
645
709
  #
@@ -689,6 +753,14 @@ module Google
689
753
  # Useful for reading the freshest data available at a nearby
690
754
  # replica, while bounding the possible staleness if the local
691
755
  # replica has fallen behind.
756
+ # @param [Hash] request_options Common request options.
757
+ #
758
+ # * `:priority` (Symbol) The relative priority for requests.
759
+ # The priority acts as a hint to the Cloud Spanner scheduler
760
+ # and does not guarantee priority or order of execution.
761
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
762
+ # `:PRIORITY_HIGH`. If priority not set then default is
763
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
692
764
  # @param [Hash] call_options A hash of values to specify the custom
693
765
  # call options, e.g., timeout, retries, etc. Call options are
694
766
  # optional. The following settings can be provided:
@@ -753,8 +825,23 @@ module Google
753
825
  # puts "User #{row[:id]} is #{row[:name]}"
754
826
  # end
755
827
  #
828
+ # @example Using request options.
829
+ # require "google/cloud/spanner"
830
+ #
831
+ # spanner = Google::Cloud::Spanner.new
832
+ #
833
+ # db = spanner.client "my-instance", "my-database"
834
+ #
835
+ # request_options = { priority: :PRIORITY_MEDIUM }
836
+ # results = db.read "users", [:id, :name],
837
+ # request_options: request_options
838
+ #
839
+ # results.rows.each do |row|
840
+ # puts "User #{row[:id]} is #{row[:name]}"
841
+ # end
842
+ #
756
843
  def read table, columns, keys: nil, index: nil, limit: nil,
757
- single_use: nil, call_options: nil
844
+ single_use: nil, request_options: nil, call_options: nil
758
845
  validate_single_use_args! single_use
759
846
  ensure_service!
760
847
 
@@ -767,6 +854,7 @@ module Google
767
854
  results = session.read \
768
855
  table, columns, keys: keys, index: index, limit: limit,
769
856
  transaction: single_use_tx,
857
+ request_options: request_options,
770
858
  call_options: call_options
771
859
  end
772
860
  results
@@ -801,6 +889,7 @@ module Google
801
889
  # | `BOOL` | `true`/`false` | |
802
890
  # | `INT64` | `Integer` | |
803
891
  # | `FLOAT64` | `Float` | |
892
+ # | `NUMERIC` | `BigDecimal` | |
804
893
  # | `STRING` | `String` | |
805
894
  # | `DATE` | `Date` | |
806
895
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -817,6 +906,14 @@ module Google
817
906
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
818
907
  # then statistics related to the transaction will be included in
819
908
  # {CommitResponse}. Default value is `false`
909
+ # @param [Hash] request_options Common request options.
910
+ #
911
+ # * `:priority` (String) The relative priority for requests.
912
+ # The priority acts as a hint to the Cloud Spanner scheduler
913
+ # and does not guarantee priority or order of execution.
914
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
915
+ # `:PRIORITY_HIGH`. If priority not set then default is
916
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
820
917
  #
821
918
  # @return [Time, CommitResponse] The timestamp at which the operation
822
919
  # committed. If commit options are set it returns {CommitResponse}.
@@ -846,9 +943,21 @@ module Google
846
943
  # puts commit_resp.timestamp
847
944
  # puts commit_resp.stats.mutation_count
848
945
  #
849
- def upsert table, rows, commit_options: nil
946
+ # @example Using request options.
947
+ # require "google/cloud/spanner"
948
+ #
949
+ # spanner = Google::Cloud::Spanner.new
950
+ #
951
+ # db = spanner.client "my-instance", "my-database"
952
+ #
953
+ # request_options = { priority: :PRIORITY_MEDIUM }
954
+ # db.upsert "users", [{ id: 1, name: "Charlie", active: false }],
955
+ # request_options: request_options
956
+ #
957
+ def upsert table, rows, commit_options: nil, request_options: nil
850
958
  @pool.with_session do |session|
851
- session.upsert table, rows, commit_options: commit_options
959
+ session.upsert table, rows, commit_options: commit_options,
960
+ request_options: request_options
852
961
  end
853
962
  end
854
963
  alias save upsert
@@ -881,6 +990,7 @@ module Google
881
990
  # | `BOOL` | `true`/`false` | |
882
991
  # | `INT64` | `Integer` | |
883
992
  # | `FLOAT64` | `Float` | |
993
+ # | `NUMERIC` | `BigDecimal` | |
884
994
  # | `STRING` | `String` | |
885
995
  # | `DATE` | `Date` | |
886
996
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -897,6 +1007,14 @@ module Google
897
1007
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
898
1008
  # then statistics related to the transaction will be included in
899
1009
  # {CommitResponse}. Default value is `false`
1010
+ # @param [Hash] request_options Common request options.
1011
+ #
1012
+ # * `:priority` (String) The relative priority for requests.
1013
+ # The priority acts as a hint to the Cloud Spanner scheduler
1014
+ # and does not guarantee priority or order of execution.
1015
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1016
+ # `:PRIORITY_HIGH`. If priority not set then default is
1017
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
900
1018
  #
901
1019
  # @return [Time, CommitResponse] The timestamp at which the operation
902
1020
  # committed. If commit options are set it returns {CommitResponse}.
@@ -926,9 +1044,21 @@ module Google
926
1044
  # puts commit_resp.timestamp
927
1045
  # puts commit_resp.stats.mutation_count
928
1046
  #
929
- def insert table, rows, commit_options: nil
1047
+ # @example Using request options.
1048
+ # require "google/cloud/spanner"
1049
+ #
1050
+ # spanner = Google::Cloud::Spanner.new
1051
+ #
1052
+ # db = spanner.client "my-instance", "my-database"
1053
+ #
1054
+ # request_options = { priority: :PRIORITY_MEDIUM }
1055
+ # db.insert "users", [{ id: 1, name: "Charlie", active: false }],
1056
+ # request_options: request_options
1057
+ #
1058
+ def insert table, rows, commit_options: nil, request_options: nil
930
1059
  @pool.with_session do |session|
931
- session.insert table, rows, commit_options: commit_options
1060
+ session.insert table, rows, commit_options: commit_options,
1061
+ request_options: request_options
932
1062
  end
933
1063
  end
934
1064
 
@@ -960,6 +1090,7 @@ module Google
960
1090
  # | `BOOL` | `true`/`false` | |
961
1091
  # | `INT64` | `Integer` | |
962
1092
  # | `FLOAT64` | `Float` | |
1093
+ # | `NUMERIC` | `BigDecimal` | |
963
1094
  # | `STRING` | `String` | |
964
1095
  # | `DATE` | `Date` | |
965
1096
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -976,6 +1107,14 @@ module Google
976
1107
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
977
1108
  # then statistics related to the transaction will be included in
978
1109
  # {CommitResponse}. Default value is `false`
1110
+ # @param [Hash] request_options Common request options.
1111
+ #
1112
+ # * `:priority` (String) The relative priority for requests.
1113
+ # The priority acts as a hint to the Cloud Spanner scheduler
1114
+ # and does not guarantee priority or order of execution.
1115
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1116
+ # `:PRIORITY_HIGH`. If priority not set then default is
1117
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
979
1118
  #
980
1119
  # @return [Time, CommitResponse] The timestamp at which the operation
981
1120
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1005,9 +1144,21 @@ module Google
1005
1144
  # puts commit_resp.timestamp
1006
1145
  # puts commit_resp.stats.mutation_count
1007
1146
  #
1008
- def update table, rows, commit_options: nil
1147
+ # @example Using request options.
1148
+ # require "google/cloud/spanner"
1149
+ #
1150
+ # spanner = Google::Cloud::Spanner.new
1151
+ #
1152
+ # db = spanner.client "my-instance", "my-database"
1153
+ #
1154
+ # request_options = { priority: :PRIORITY_MEDIUM }
1155
+ # db.update "users", [{ id: 1, name: "Charlie", active: false }],
1156
+ # request_options: request_options
1157
+ #
1158
+ def update table, rows, commit_options: nil, request_options: nil
1009
1159
  @pool.with_session do |session|
1010
- session.update table, rows, commit_options: commit_options
1160
+ session.update table, rows, commit_options: commit_options,
1161
+ request_options: request_options
1011
1162
  end
1012
1163
  end
1013
1164
 
@@ -1041,6 +1192,7 @@ module Google
1041
1192
  # | `BOOL` | `true`/`false` | |
1042
1193
  # | `INT64` | `Integer` | |
1043
1194
  # | `FLOAT64` | `Float` | |
1195
+ # | `NUMERIC` | `BigDecimal` | |
1044
1196
  # | `STRING` | `String` | |
1045
1197
  # | `DATE` | `Date` | |
1046
1198
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -1057,6 +1209,14 @@ module Google
1057
1209
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
1058
1210
  # then statistics related to the transaction will be included in
1059
1211
  # {CommitResponse}. Default value is `false`
1212
+ # @param [Hash] request_options Common request options.
1213
+ #
1214
+ # * `:priority` (String) The relative priority for requests.
1215
+ # The priority acts as a hint to the Cloud Spanner scheduler
1216
+ # and does not guarantee priority or order of execution.
1217
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1218
+ # `:PRIORITY_HIGH`. If priority not set then default is
1219
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
1060
1220
  #
1061
1221
  # @return [Time, CommitResponse] The timestamp at which the operation
1062
1222
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1086,9 +1246,21 @@ module Google
1086
1246
  # puts commit_resp.timestamp
1087
1247
  # puts commit_resp.stats.mutation_count
1088
1248
  #
1089
- def replace table, rows, commit_options: nil
1249
+ # @example Using request options.
1250
+ # require "google/cloud/spanner"
1251
+ #
1252
+ # spanner = Google::Cloud::Spanner.new
1253
+ #
1254
+ # db = spanner.client "my-instance", "my-database"
1255
+ #
1256
+ # request_options = { priority: :PRIORITY_MEDIUM }
1257
+ # db.replace "users", [{ id: 1, name: "Charlie", active: false }],
1258
+ # request_options: request_options
1259
+ #
1260
+ def replace table, rows, commit_options: nil, request_options: nil
1090
1261
  @pool.with_session do |session|
1091
- session.replace table, rows, commit_options: commit_options
1262
+ session.replace table, rows, commit_options: commit_options,
1263
+ request_options: request_options
1092
1264
  end
1093
1265
  end
1094
1266
 
@@ -1119,7 +1291,14 @@ module Google
1119
1291
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
1120
1292
  # then statistics related to the transaction will be included in
1121
1293
  # {CommitResponse}. Default value is `false`
1122
- #
1294
+ # @param [Hash] request_options Common request options.
1295
+ #
1296
+ # * `:priority` (String) The relative priority for requests.
1297
+ # The priority acts as a hint to the Cloud Spanner scheduler
1298
+ # and does not guarantee priority or order of execution.
1299
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1300
+ # `:PRIORITY_HIGH`. If priority not set then default is
1301
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
1123
1302
  # @param [Hash] call_options A hash of values to specify the custom
1124
1303
  # call options, e.g., timeout, retries, etc. Call options are
1125
1304
  # optional. The following settings can be provided:
@@ -1159,9 +1338,21 @@ module Google
1159
1338
  # puts commit_resp.timestamp
1160
1339
  # puts commit_resp.stats.mutation_count
1161
1340
  #
1162
- def delete table, keys = [], commit_options: nil, call_options: nil
1341
+ # @example With request optinos
1342
+ # require "google/cloud/spanner"
1343
+ #
1344
+ # spanner = Google::Cloud::Spanner.new
1345
+ #
1346
+ # db = spanner.client "my-instance", "my-database"
1347
+ #
1348
+ # request_options = { priority: :PRIORITY_MEDIUM }
1349
+ # db.delete "users", [1, 2, 3], request_options: request_options
1350
+ #
1351
+ def delete table, keys = [], commit_options: nil, request_options: nil,
1352
+ call_options: nil
1163
1353
  @pool.with_session do |session|
1164
1354
  session.delete table, keys, commit_options: commit_options,
1355
+ request_options: request_options,
1165
1356
  call_options: call_options
1166
1357
  end
1167
1358
  end
@@ -1188,7 +1379,14 @@ module Google
1188
1379
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
1189
1380
  # then statistics related to the transaction will be included in
1190
1381
  # {CommitResponse}. Default value is `false`
1191
- #
1382
+ # @param [Hash] request_options Common request options.
1383
+ #
1384
+ # * `:priority` (String) The relative priority for requests.
1385
+ # The priority acts as a hint to the Cloud Spanner scheduler
1386
+ # and does not guarantee priority or order of execution.
1387
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1388
+ # `:PRIORITY_HIGH`. If priority not set then default is
1389
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
1192
1390
  # @param [Hash] call_options A hash of values to specify the custom
1193
1391
  # call options, e.g., timeout, retries, etc. Call options are
1194
1392
  # optional. The following settings can be provided:
@@ -1237,18 +1435,33 @@ module Google
1237
1435
  # puts commit_resp.timestamp
1238
1436
  # puts commit_resp.stats.mutation_count
1239
1437
  #
1240
- def commit commit_options: nil, call_options: nil, &block
1438
+ # @example With request options
1439
+ # require "google/cloud/spanner"
1440
+ #
1441
+ # spanner = Google::Cloud::Spanner.new
1442
+ #
1443
+ # db = spanner.client "my-instance", "my-database"
1444
+ #
1445
+ # db.commit request_options: { priority: :PRIORITY_MEDIUM } do |c|
1446
+ # c.update "users", [{ id: 1, name: "Charlie", active: false }]
1447
+ # c.insert "users", [{ id: 2, name: "Harvey", active: true }]
1448
+ # end
1449
+ #
1450
+ def commit commit_options: nil, request_options: nil,
1451
+ call_options: nil, &block
1241
1452
  raise ArgumentError, "Must provide a block" unless block_given?
1242
1453
 
1243
1454
  @pool.with_session do |session|
1244
1455
  session.commit(
1245
- commit_options: commit_options, call_options: call_options, &block
1456
+ commit_options: commit_options, request_options: request_options,
1457
+ call_options: call_options, &block
1246
1458
  )
1247
1459
  end
1248
1460
  end
1249
1461
 
1250
1462
  # rubocop:disable Metrics/AbcSize
1251
1463
  # rubocop:disable Metrics/MethodLength
1464
+ # rubocop:disable Metrics/BlockLength
1252
1465
 
1253
1466
  ##
1254
1467
  # Creates a transaction for reads and writes that execute atomically at
@@ -1273,7 +1486,14 @@ module Google
1273
1486
  # * `:return_commit_stats` (Boolean) A boolean value. If `true`,
1274
1487
  # then statistics related to the transaction will be included in
1275
1488
  # {CommitResponse}. Default value is `false`
1276
- #
1489
+ # @param [Hash] request_options Common request options.
1490
+ #
1491
+ # * `:priority` (String) The relative priority for requests.
1492
+ # The priority acts as a hint to the Cloud Spanner scheduler
1493
+ # and does not guarantee priority or order of execution.
1494
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1495
+ # `:PRIORITY_HIGH`. If priority not set then default is
1496
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
1277
1497
  # @param [Hash] call_options A hash of values to specify the custom
1278
1498
  # call options, e.g., timeout, retries, etc. Call options are
1279
1499
  # optional. The following settings can be provided:
@@ -1350,7 +1570,23 @@ module Google
1350
1570
  # puts commit_resp.timestamp
1351
1571
  # puts commit_resp.stats.mutation_count
1352
1572
  #
1353
- def transaction deadline: 120, commit_options: nil, call_options: nil
1573
+ # @example Using request options.
1574
+ # require "google/cloud/spanner"
1575
+ #
1576
+ # spanner = Google::Cloud::Spanner.new
1577
+ # db = spanner.client "my-instance", "my-database"
1578
+ #
1579
+ # db.transaction request_options: { priority: :PRIORITY_MEDIUM } do |tx|
1580
+ # tx.update "users", [{ id: 1, name: "Charlie", active: false }]
1581
+ # tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
1582
+ #
1583
+ # request_options = { priority: :PRIORITY_LOW }
1584
+ # results = tx.execute_query "SELECT * FROM users",
1585
+ # request_options: request_options
1586
+ # end
1587
+ #
1588
+ def transaction deadline: 120, commit_options: nil,
1589
+ request_options: nil, call_options: nil
1354
1590
  ensure_service!
1355
1591
  unless Thread.current[:transaction_id].nil?
1356
1592
  raise "Nested transactions are not allowed"
@@ -1367,6 +1603,7 @@ module Google
1367
1603
  tx.session.path, tx.mutations,
1368
1604
  transaction_id: tx.transaction_id,
1369
1605
  commit_options: commit_options,
1606
+ request_options: request_options,
1370
1607
  call_options: call_options
1371
1608
  resp = CommitResponse.from_grpc commit_resp
1372
1609
  commit_options ? resp : resp.timestamp
@@ -1397,6 +1634,7 @@ module Google
1397
1634
 
1398
1635
  # rubocop:enable Metrics/AbcSize
1399
1636
  # rubocop:enable Metrics/MethodLength
1637
+ # rubocop:enable Metrics/BlockLength
1400
1638
 
1401
1639
  ##
1402
1640
  # Creates a snapshot read-only transaction for reads that execute
@@ -1508,12 +1746,13 @@ module Google
1508
1746
  # Hash values must contain the type value. If a Hash is used the
1509
1747
  # fields will be created using the same order as the Hash keys.
1510
1748
  #
1511
- # Supported type values incude:
1749
+ # Supported type values include:
1512
1750
  #
1513
1751
  # * `:BOOL`
1514
1752
  # * `:BYTES`
1515
1753
  # * `:DATE`
1516
1754
  # * `:FLOAT64`
1755
+ # * `:NUMERIC`
1517
1756
  # * `:INT64`
1518
1757
  # * `:STRING`
1519
1758
  # * `:TIMESTAMP`
@@ -1804,11 +2043,10 @@ module Google
1804
2043
  # GRPC::Aborted
1805
2044
  def delay_from_aborted err
1806
2045
  return nil if err.nil?
1807
- if err.respond_to?(:metadata) && err.metadata["retryDelay"]
1808
- # a correct metadata will look like this:
1809
- # "{\"retryDelay\":{\"seconds\":60}}"
1810
- seconds = err.metadata["retryDelay"]["seconds"].to_i
1811
- nanos = err.metadata["retryDelay"]["nanos"].to_i
2046
+ if err.respond_to?(:metadata) && err.metadata["google.rpc.retryinfo-bin"]
2047
+ retry_info = Google::Rpc::RetryInfo.decode err.metadata["google.rpc.retryinfo-bin"]
2048
+ seconds = retry_info["retry_delay"].seconds
2049
+ nanos = retry_info["retry_delay"].nanos
1812
2050
  return seconds if nanos.zero?
1813
2051
  return seconds + (nanos / 1_000_000_000.0)
1814
2052
  end