google-cloud-spanner 1.16.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +1 -1
- data/CHANGELOG.md +58 -0
- data/CONTRIBUTING.md +6 -6
- data/TROUBLESHOOTING.md +0 -6
- data/lib/google-cloud-spanner.rb +11 -13
- data/lib/google/cloud/spanner.rb +13 -13
- data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
- data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
- data/lib/google/cloud/spanner/backup.rb +1 -1
- data/lib/google/cloud/spanner/backup/job.rb +2 -2
- data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
- data/lib/google/cloud/spanner/backup/list.rb +1 -2
- data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
- data/lib/google/cloud/spanner/batch_client.rb +2 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
- data/lib/google/cloud/spanner/batch_update.rb +1 -1
- data/lib/google/cloud/spanner/client.rb +388 -47
- data/lib/google/cloud/spanner/commit.rb +14 -14
- data/lib/google/cloud/spanner/commit_response.rb +87 -0
- data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
- data/lib/google/cloud/spanner/convert.rb +16 -7
- data/lib/google/cloud/spanner/credentials.rb +2 -2
- data/lib/google/cloud/spanner/data.rb +2 -2
- data/lib/google/cloud/spanner/database.rb +22 -22
- data/lib/google/cloud/spanner/database/backup_info.rb +1 -1
- data/lib/google/cloud/spanner/database/job.rb +3 -3
- data/lib/google/cloud/spanner/database/job/list.rb +2 -2
- data/lib/google/cloud/spanner/database/list.rb +1 -1
- data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
- data/lib/google/cloud/spanner/fields.rb +8 -8
- data/lib/google/cloud/spanner/instance.rb +5 -12
- data/lib/google/cloud/spanner/instance/config.rb +1 -1
- data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
- data/lib/google/cloud/spanner/instance/job.rb +2 -2
- data/lib/google/cloud/spanner/instance/list.rb +1 -1
- data/lib/google/cloud/spanner/partition.rb +4 -4
- data/lib/google/cloud/spanner/policy.rb +2 -2
- data/lib/google/cloud/spanner/results.rb +103 -24
- data/lib/google/cloud/spanner/service.rb +367 -349
- data/lib/google/cloud/spanner/session.rb +370 -39
- data/lib/google/cloud/spanner/snapshot.rb +60 -6
- data/lib/google/cloud/spanner/transaction.rb +116 -10
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +20 -107
- data/lib/google/cloud/spanner/admin/database.rb +0 -149
- data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
- data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance.rb +0 -164
- data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
- data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
- data/lib/google/cloud/spanner/v1.rb +0 -16
- data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
- data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
- data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
- data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
- data/lib/google/spanner/v1/keys_pb.rb +0 -34
- data/lib/google/spanner/v1/mutation_pb.rb +0 -39
- data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
- data/lib/google/spanner/v1/result_set_pb.rb +0 -48
- data/lib/google/spanner/v1/spanner_pb.rb +0 -179
- data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
- data/lib/google/spanner/v1/transaction_pb.rb +0 -56
- data/lib/google/spanner/v1/type_pb.rb +0 -44
@@ -155,7 +155,7 @@ module Google
|
|
155
155
|
Convert.to_input_params_and_types params, types
|
156
156
|
# param_types is a grpc map field, can't be nil
|
157
157
|
converted_types ||= {}
|
158
|
-
|
158
|
+
V1::ExecuteBatchDmlRequest::Statement.new(
|
159
159
|
sql: sql,
|
160
160
|
params: converted_params,
|
161
161
|
param_types: converted_types
|
@@ -23,6 +23,7 @@ require "google/cloud/spanner/snapshot"
|
|
23
23
|
require "google/cloud/spanner/range"
|
24
24
|
require "google/cloud/spanner/column_value"
|
25
25
|
require "google/cloud/spanner/convert"
|
26
|
+
require "google/cloud/spanner/commit_response"
|
26
27
|
|
27
28
|
module Google
|
28
29
|
module Cloud
|
@@ -222,6 +223,19 @@ module Google
|
|
222
223
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
223
224
|
# Empty to use database default. "latest" to use the latest
|
224
225
|
# available optimizer version.
|
226
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
227
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
228
|
+
# optional. The following settings can be provided:
|
229
|
+
#
|
230
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
231
|
+
# that overrides the default setting.
|
232
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
233
|
+
# setting of retry policy with the following keys:
|
234
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
235
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
236
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
237
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
238
|
+
# trigger a retry.
|
225
239
|
#
|
226
240
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
227
241
|
# execution.
|
@@ -335,8 +349,31 @@ module Google
|
|
335
349
|
# puts "User #{row[:id]} is #{row[:name]}"
|
336
350
|
# end
|
337
351
|
#
|
352
|
+
# @example Query using custom timeout and retry policy:
|
353
|
+
# require "google/cloud/spanner"
|
354
|
+
#
|
355
|
+
# spanner = Google::Cloud::Spanner.new
|
356
|
+
#
|
357
|
+
# db = spanner.client "my-instance", "my-database"
|
358
|
+
#
|
359
|
+
# timeout = 30.0
|
360
|
+
# retry_policy = {
|
361
|
+
# initial_delay: 0.25,
|
362
|
+
# max_delay: 32.0,
|
363
|
+
# multiplier: 1.3,
|
364
|
+
# retry_codes: ["UNAVAILABLE"]
|
365
|
+
# }
|
366
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
367
|
+
#
|
368
|
+
# results = db.execute_query \
|
369
|
+
# "SELECT * FROM users", call_options: call_options
|
370
|
+
#
|
371
|
+
# results.rows.each do |row|
|
372
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
373
|
+
# end
|
374
|
+
#
|
338
375
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
339
|
-
query_options: nil
|
376
|
+
query_options: nil, call_options: nil
|
340
377
|
validate_single_use_args! single_use
|
341
378
|
ensure_service!
|
342
379
|
|
@@ -347,7 +384,7 @@ module Google
|
|
347
384
|
@pool.with_session do |session|
|
348
385
|
results = session.execute_query \
|
349
386
|
sql, params: params, types: types, transaction: single_use_tx,
|
350
|
-
query_options: query_options
|
387
|
+
query_options: query_options, call_options: call_options
|
351
388
|
end
|
352
389
|
results
|
353
390
|
end
|
@@ -474,14 +511,6 @@ module Google
|
|
474
511
|
# value in `params`. In these cases, the `types` hash can be used to
|
475
512
|
# specify the exact SQL type for some or all of the SQL query
|
476
513
|
# parameters.
|
477
|
-
# @param [Hash] query_options A hash of values to specify the custom
|
478
|
-
# query options for executing SQL query. Query options are optional.
|
479
|
-
# The following settings can be provided:
|
480
|
-
#
|
481
|
-
# * `:optimizer_version` (String) The version of optimizer to use.
|
482
|
-
# Empty to use database default. "latest" to use the latest
|
483
|
-
# available optimizer version.
|
484
|
-
#
|
485
514
|
#
|
486
515
|
# The keys of the hash should be query string parameter placeholders,
|
487
516
|
# minus the "@". The values of the hash should be Cloud Spanner type
|
@@ -499,6 +528,26 @@ module Google
|
|
499
528
|
# `[:INT64]`.
|
500
529
|
# * {Fields} - Nested Structs are specified by providing a Fields
|
501
530
|
# object.
|
531
|
+
# @param [Hash] query_options A hash of values to specify the custom
|
532
|
+
# query options for executing SQL query. Query options are optional.
|
533
|
+
# The following settings can be provided:
|
534
|
+
#
|
535
|
+
# * `:optimizer_version` (String) The version of optimizer to use.
|
536
|
+
# Empty to use database default. "latest" to use the latest
|
537
|
+
# available optimizer version.
|
538
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
539
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
540
|
+
# optional. The following settings can be provided:
|
541
|
+
#
|
542
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
543
|
+
# that overrides the default setting.
|
544
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
545
|
+
# setting of retry policy with the following keys:
|
546
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
547
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
548
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
549
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
550
|
+
# trigger a retry.
|
502
551
|
# @return [Integer] The lower bound number of rows that were modified.
|
503
552
|
#
|
504
553
|
# @example
|
@@ -529,8 +578,28 @@ module Google
|
|
529
578
|
# row_count = db.execute_partition_update \
|
530
579
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
531
580
|
# query_options: { optimizer_version: "1" }
|
581
|
+
#
|
582
|
+
# @example Query using custom timeout and retry policy:
|
583
|
+
# require "google/cloud/spanner"
|
584
|
+
#
|
585
|
+
# spanner = Google::Cloud::Spanner.new
|
586
|
+
# db = spanner.client "my-instance", "my-database"
|
587
|
+
#
|
588
|
+
# timeout = 30.0
|
589
|
+
# retry_policy = {
|
590
|
+
# initial_delay: 0.25,
|
591
|
+
# max_delay: 32.0,
|
592
|
+
# multiplier: 1.3,
|
593
|
+
# retry_codes: ["UNAVAILABLE"]
|
594
|
+
# }
|
595
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
596
|
+
#
|
597
|
+
# row_count = db.execute_partition_update \
|
598
|
+
# "UPDATE users SET friends = NULL WHERE active = false",
|
599
|
+
# call_options: call_options
|
600
|
+
#
|
532
601
|
def execute_partition_update sql, params: nil, types: nil,
|
533
|
-
query_options: nil
|
602
|
+
query_options: nil, call_options: nil
|
534
603
|
ensure_service!
|
535
604
|
|
536
605
|
params, types = Convert.to_input_params_and_types params, types
|
@@ -539,7 +608,7 @@ module Google
|
|
539
608
|
results = session.execute_query \
|
540
609
|
sql, params: params, types: types,
|
541
610
|
transaction: pdml_transaction(session),
|
542
|
-
query_options: query_options
|
611
|
+
query_options: query_options, call_options: call_options
|
543
612
|
end
|
544
613
|
# Stream all PartialResultSet to get ResultSetStats
|
545
614
|
results.rows.to_a
|
@@ -620,6 +689,19 @@ module Google
|
|
620
689
|
# Useful for reading the freshest data available at a nearby
|
621
690
|
# replica, while bounding the possible staleness if the local
|
622
691
|
# replica has fallen behind.
|
692
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
693
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
694
|
+
# optional. The following settings can be provided:
|
695
|
+
#
|
696
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
697
|
+
# that overrides the default setting.
|
698
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
699
|
+
# setting of retry policy with the following keys:
|
700
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
701
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
702
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
703
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
704
|
+
# trigger a retry.
|
623
705
|
#
|
624
706
|
# @return [Google::Cloud::Spanner::Results] The results of the read.
|
625
707
|
#
|
@@ -649,8 +731,30 @@ module Google
|
|
649
731
|
# puts "User #{row[:id]} is #{row[:name]}"
|
650
732
|
# end
|
651
733
|
#
|
734
|
+
# @example Read using custom timeout and retry.
|
735
|
+
# require "google/cloud/spanner"
|
736
|
+
#
|
737
|
+
# spanner = Google::Cloud::Spanner.new
|
738
|
+
#
|
739
|
+
# db = spanner.client "my-instance", "my-database"
|
740
|
+
#
|
741
|
+
# timeout = 30.0
|
742
|
+
# retry_policy = {
|
743
|
+
# initial_delay: 0.25,
|
744
|
+
# max_delay: 32.0,
|
745
|
+
# multiplier: 1.3,
|
746
|
+
# retry_codes: ["UNAVAILABLE"]
|
747
|
+
# }
|
748
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
749
|
+
#
|
750
|
+
# results = db.read "users", [:id, :name], call_options: call_options
|
751
|
+
#
|
752
|
+
# results.rows.each do |row|
|
753
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
754
|
+
# end
|
755
|
+
#
|
652
756
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
653
|
-
single_use: nil
|
757
|
+
single_use: nil, call_options: nil
|
654
758
|
validate_single_use_args! single_use
|
655
759
|
ensure_service!
|
656
760
|
|
@@ -662,7 +766,8 @@ module Google
|
|
662
766
|
@pool.with_session do |session|
|
663
767
|
results = session.read \
|
664
768
|
table, columns, keys: keys, index: index, limit: limit,
|
665
|
-
transaction: single_use_tx
|
769
|
+
transaction: single_use_tx,
|
770
|
+
call_options: call_options
|
666
771
|
end
|
667
772
|
results
|
668
773
|
end
|
@@ -705,7 +810,16 @@ module Google
|
|
705
810
|
# See [Data
|
706
811
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
707
812
|
#
|
708
|
-
# @
|
813
|
+
# @param [Hash] commit_options A hash of commit options.
|
814
|
+
# e.g., return_commit_stats. Commit options are optional.
|
815
|
+
# The following options can be provided:
|
816
|
+
#
|
817
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
818
|
+
# then statistics related to the transaction will be included in
|
819
|
+
# {CommitResponse}. Default value is `false`
|
820
|
+
#
|
821
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
822
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
709
823
|
#
|
710
824
|
# @example
|
711
825
|
# require "google/cloud/spanner"
|
@@ -717,9 +831,24 @@ module Google
|
|
717
831
|
# db.upsert "users", [{ id: 1, name: "Charlie", active: false },
|
718
832
|
# { id: 2, name: "Harvey", active: true }]
|
719
833
|
#
|
720
|
-
|
834
|
+
# @example Get commit stats
|
835
|
+
# require "google/cloud/spanner"
|
836
|
+
#
|
837
|
+
# spanner = Google::Cloud::Spanner.new
|
838
|
+
#
|
839
|
+
# db = spanner.client "my-instance", "my-database"
|
840
|
+
#
|
841
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
842
|
+
# { id: 2, name: "Harvey", active: true }]
|
843
|
+
# commit_options = { return_commit_stats: true }
|
844
|
+
# commit_resp = db.upsert "users", records, commit_options: commit_options
|
845
|
+
#
|
846
|
+
# puts commit_resp.timestamp
|
847
|
+
# puts commit_resp.stats.mutation_count
|
848
|
+
#
|
849
|
+
def upsert table, rows, commit_options: nil
|
721
850
|
@pool.with_session do |session|
|
722
|
-
session.upsert table, rows
|
851
|
+
session.upsert table, rows, commit_options: commit_options
|
723
852
|
end
|
724
853
|
end
|
725
854
|
alias save upsert
|
@@ -761,7 +890,16 @@ module Google
|
|
761
890
|
# See [Data
|
762
891
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
763
892
|
#
|
764
|
-
# @
|
893
|
+
# @param [Hash] commit_options A hash of commit options.
|
894
|
+
# e.g., return_commit_stats. Commit options are optional.
|
895
|
+
# The following options can be provided:
|
896
|
+
#
|
897
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
898
|
+
# then statistics related to the transaction will be included in
|
899
|
+
# {CommitResponse}. Default value is `false`
|
900
|
+
#
|
901
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
902
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
765
903
|
#
|
766
904
|
# @example
|
767
905
|
# require "google/cloud/spanner"
|
@@ -773,9 +911,24 @@ module Google
|
|
773
911
|
# db.insert "users", [{ id: 1, name: "Charlie", active: false },
|
774
912
|
# { id: 2, name: "Harvey", active: true }]
|
775
913
|
#
|
776
|
-
|
914
|
+
# @example Get commit stats
|
915
|
+
# require "google/cloud/spanner"
|
916
|
+
#
|
917
|
+
# spanner = Google::Cloud::Spanner.new
|
918
|
+
#
|
919
|
+
# db = spanner.client "my-instance", "my-database"
|
920
|
+
#
|
921
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
922
|
+
# { id: 2, name: "Harvey", active: true }]
|
923
|
+
# commit_options = { return_commit_stats: true }
|
924
|
+
# commit_resp = db.insert "users", records, commit_options: commit_options
|
925
|
+
#
|
926
|
+
# puts commit_resp.timestamp
|
927
|
+
# puts commit_resp.stats.mutation_count
|
928
|
+
#
|
929
|
+
def insert table, rows, commit_options: nil
|
777
930
|
@pool.with_session do |session|
|
778
|
-
session.insert table, rows
|
931
|
+
session.insert table, rows, commit_options: commit_options
|
779
932
|
end
|
780
933
|
end
|
781
934
|
|
@@ -816,7 +969,16 @@ module Google
|
|
816
969
|
# See [Data
|
817
970
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
818
971
|
#
|
819
|
-
# @
|
972
|
+
# @param [Hash] commit_options A hash of commit options.
|
973
|
+
# e.g., return_commit_stats. Commit options are optional.
|
974
|
+
# The following options can be provided:
|
975
|
+
#
|
976
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
977
|
+
# then statistics related to the transaction will be included in
|
978
|
+
# {CommitResponse}. Default value is `false`
|
979
|
+
#
|
980
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
981
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
820
982
|
#
|
821
983
|
# @example
|
822
984
|
# require "google/cloud/spanner"
|
@@ -828,9 +990,24 @@ module Google
|
|
828
990
|
# db.update "users", [{ id: 1, name: "Charlie", active: false },
|
829
991
|
# { id: 2, name: "Harvey", active: true }]
|
830
992
|
#
|
831
|
-
|
993
|
+
# @example Get commit stats
|
994
|
+
# require "google/cloud/spanner"
|
995
|
+
#
|
996
|
+
# spanner = Google::Cloud::Spanner.new
|
997
|
+
#
|
998
|
+
# db = spanner.client "my-instance", "my-database"
|
999
|
+
#
|
1000
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
1001
|
+
# { id: 2, name: "Harvey", active: true }]
|
1002
|
+
# commit_options = { return_commit_stats: true }
|
1003
|
+
# commit_resp = db.update "users", records, commit_options: commit_options
|
1004
|
+
#
|
1005
|
+
# puts commit_resp.timestamp
|
1006
|
+
# puts commit_resp.stats.mutation_count
|
1007
|
+
#
|
1008
|
+
def update table, rows, commit_options: nil
|
832
1009
|
@pool.with_session do |session|
|
833
|
-
session.update table, rows
|
1010
|
+
session.update table, rows, commit_options: commit_options
|
834
1011
|
end
|
835
1012
|
end
|
836
1013
|
|
@@ -873,7 +1050,16 @@ module Google
|
|
873
1050
|
# See [Data
|
874
1051
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
875
1052
|
#
|
876
|
-
# @
|
1053
|
+
# @param [Hash] commit_options A hash of commit options.
|
1054
|
+
# e.g., return_commit_stats. Commit options are optional.
|
1055
|
+
# The following options can be provided:
|
1056
|
+
#
|
1057
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1058
|
+
# then statistics related to the transaction will be included in
|
1059
|
+
# {CommitResponse}. Default value is `false`
|
1060
|
+
#
|
1061
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
1062
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
877
1063
|
#
|
878
1064
|
# @example
|
879
1065
|
# require "google/cloud/spanner"
|
@@ -885,9 +1071,24 @@ module Google
|
|
885
1071
|
# db.replace "users", [{ id: 1, name: "Charlie", active: false },
|
886
1072
|
# { id: 2, name: "Harvey", active: true }]
|
887
1073
|
#
|
888
|
-
|
1074
|
+
# @example Get commit stats
|
1075
|
+
# require "google/cloud/spanner"
|
1076
|
+
#
|
1077
|
+
# spanner = Google::Cloud::Spanner.new
|
1078
|
+
#
|
1079
|
+
# db = spanner.client "my-instance", "my-database"
|
1080
|
+
#
|
1081
|
+
# records = [{ id: 1, name: "Charlie", active: false },
|
1082
|
+
# { id: 2, name: "Harvey", active: true }]
|
1083
|
+
# commit_options = { return_commit_stats: true }
|
1084
|
+
# commit_resp = db.replace "users", records, commit_options: commit_options
|
1085
|
+
#
|
1086
|
+
# puts commit_resp.timestamp
|
1087
|
+
# puts commit_resp.stats.mutation_count
|
1088
|
+
#
|
1089
|
+
def replace table, rows, commit_options: nil
|
889
1090
|
@pool.with_session do |session|
|
890
|
-
session.replace table, rows
|
1091
|
+
session.replace table, rows, commit_options: commit_options
|
891
1092
|
end
|
892
1093
|
end
|
893
1094
|
|
@@ -911,8 +1112,30 @@ module Google
|
|
911
1112
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
912
1113
|
# ranges to match returned data to. Values should have exactly as many
|
913
1114
|
# elements as there are columns in the primary key.
|
914
|
-
#
|
915
|
-
#
|
1115
|
+
# @param [Hash] commit_options A hash of commit options.
|
1116
|
+
# e.g., return_commit_stats. Commit options are optional.
|
1117
|
+
# The following options can be provided:
|
1118
|
+
#
|
1119
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1120
|
+
# then statistics related to the transaction will be included in
|
1121
|
+
# {CommitResponse}. Default value is `false`
|
1122
|
+
#
|
1123
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1124
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1125
|
+
# optional. The following settings can be provided:
|
1126
|
+
#
|
1127
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1128
|
+
# that overrides the default setting.
|
1129
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1130
|
+
# setting of retry policy with the following keys:
|
1131
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1132
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1133
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1134
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1135
|
+
# trigger a retry.
|
1136
|
+
#
|
1137
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
1138
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
916
1139
|
#
|
917
1140
|
# @example
|
918
1141
|
# require "google/cloud/spanner"
|
@@ -923,9 +1146,23 @@ module Google
|
|
923
1146
|
#
|
924
1147
|
# db.delete "users", [1, 2, 3]
|
925
1148
|
#
|
926
|
-
|
1149
|
+
# @example Get commit stats
|
1150
|
+
# require "google/cloud/spanner"
|
1151
|
+
#
|
1152
|
+
# spanner = Google::Cloud::Spanner.new
|
1153
|
+
#
|
1154
|
+
# db = spanner.client "my-instance", "my-database"
|
1155
|
+
#
|
1156
|
+
# commit_options = { return_commit_stats: true }
|
1157
|
+
# commit_resp = db.delete "users", [1, 2, 3], commit_options: commit_options
|
1158
|
+
#
|
1159
|
+
# puts commit_resp.timestamp
|
1160
|
+
# puts commit_resp.stats.mutation_count
|
1161
|
+
#
|
1162
|
+
def delete table, keys = [], commit_options: nil, call_options: nil
|
927
1163
|
@pool.with_session do |session|
|
928
|
-
session.delete table, keys
|
1164
|
+
session.delete table, keys, commit_options: commit_options,
|
1165
|
+
call_options: call_options
|
929
1166
|
end
|
930
1167
|
end
|
931
1168
|
|
@@ -944,10 +1181,33 @@ module Google
|
|
944
1181
|
# this method may be appropriate for latency sensitive and/or high
|
945
1182
|
# throughput blind changes.
|
946
1183
|
#
|
1184
|
+
# @param [Hash] commit_options A hash of commit options.
|
1185
|
+
# e.g., return_commit_stats. Commit options are optional.
|
1186
|
+
# The following options can be provided:
|
1187
|
+
#
|
1188
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1189
|
+
# then statistics related to the transaction will be included in
|
1190
|
+
# {CommitResponse}. Default value is `false`
|
1191
|
+
#
|
1192
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1193
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1194
|
+
# optional. The following settings can be provided:
|
1195
|
+
#
|
1196
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1197
|
+
# that overrides the default setting.
|
1198
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1199
|
+
# setting of retry policy with the following keys:
|
1200
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1201
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1202
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1203
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1204
|
+
# trigger a retry.
|
1205
|
+
#
|
947
1206
|
# @yield [commit] The block for mutating the data.
|
948
1207
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
949
1208
|
#
|
950
|
-
# @return [Time] The timestamp at which the operation
|
1209
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
1210
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
951
1211
|
#
|
952
1212
|
# @example
|
953
1213
|
# require "google/cloud/spanner"
|
@@ -961,15 +1221,34 @@ module Google
|
|
961
1221
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
962
1222
|
# end
|
963
1223
|
#
|
964
|
-
|
1224
|
+
# @example Get commit stats
|
1225
|
+
# require "google/cloud/spanner"
|
1226
|
+
#
|
1227
|
+
# spanner = Google::Cloud::Spanner.new
|
1228
|
+
#
|
1229
|
+
# db = spanner.client "my-instance", "my-database"
|
1230
|
+
#
|
1231
|
+
# commit_options = { return_commit_stats: true }
|
1232
|
+
# commit_resp = db.commit commit_options: commit_options do |c|
|
1233
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1234
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1235
|
+
# end
|
1236
|
+
#
|
1237
|
+
# puts commit_resp.timestamp
|
1238
|
+
# puts commit_resp.stats.mutation_count
|
1239
|
+
#
|
1240
|
+
def commit commit_options: nil, call_options: nil, &block
|
965
1241
|
raise ArgumentError, "Must provide a block" unless block_given?
|
966
1242
|
|
967
1243
|
@pool.with_session do |session|
|
968
|
-
session.commit(
|
1244
|
+
session.commit(
|
1245
|
+
commit_options: commit_options, call_options: call_options, &block
|
1246
|
+
)
|
969
1247
|
end
|
970
1248
|
end
|
971
1249
|
|
972
1250
|
# rubocop:disable Metrics/AbcSize
|
1251
|
+
# rubocop:disable Metrics/BlockLength
|
973
1252
|
# rubocop:disable Metrics/MethodLength
|
974
1253
|
|
975
1254
|
##
|
@@ -988,12 +1267,34 @@ module Google
|
|
988
1267
|
#
|
989
1268
|
# @param [Numeric] deadline The total amount of time in seconds the
|
990
1269
|
# transaction has to succeed. The default is `120`.
|
1270
|
+
# @param [Hash] commit_options A hash of commit options.
|
1271
|
+
# e.g., return_commit_stats. Commit options are optional.
|
1272
|
+
# The following options can be provided:
|
1273
|
+
#
|
1274
|
+
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1275
|
+
# then statistics related to the transaction will be included in
|
1276
|
+
# {CommitResponse}. Default value is `false`
|
1277
|
+
#
|
1278
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1279
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1280
|
+
# optional. The following settings can be provided:
|
1281
|
+
#
|
1282
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1283
|
+
# that overrides the default setting.
|
1284
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1285
|
+
# setting of retry policy with the following keys:
|
1286
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1287
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1288
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1289
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1290
|
+
# trigger a retry.
|
991
1291
|
#
|
992
1292
|
# @yield [transaction] The block for reading and writing data.
|
993
1293
|
# @yieldparam [Google::Cloud::Spanner::Transaction] transaction The
|
994
1294
|
# Transaction object.
|
995
1295
|
#
|
996
|
-
# @return [Time] The timestamp at which the
|
1296
|
+
# @return [Time, CommitResponse] The timestamp at which the operation
|
1297
|
+
# committed. If commit options are set it returns {CommitResponse}.
|
997
1298
|
#
|
998
1299
|
# @example
|
999
1300
|
# require "google/cloud/spanner"
|
@@ -1029,7 +1330,28 @@ module Google
|
|
1029
1330
|
# end
|
1030
1331
|
# end
|
1031
1332
|
#
|
1032
|
-
|
1333
|
+
# @example Get commit stats
|
1334
|
+
# require "google/cloud/spanner"
|
1335
|
+
#
|
1336
|
+
# spanner = Google::Cloud::Spanner.new
|
1337
|
+
# db = spanner.client "my-instance", "my-database"
|
1338
|
+
#
|
1339
|
+
# commit_options = { return_commit_stats: true }
|
1340
|
+
# commit_resp = db.transaction commit_options: commit_options do |tx|
|
1341
|
+
# results = tx.execute_query "SELECT * FROM users"
|
1342
|
+
#
|
1343
|
+
# results.rows.each do |row|
|
1344
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
1345
|
+
# end
|
1346
|
+
#
|
1347
|
+
# tx.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1348
|
+
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1349
|
+
# end
|
1350
|
+
#
|
1351
|
+
# puts commit_resp.timestamp
|
1352
|
+
# puts commit_resp.stats.mutation_count
|
1353
|
+
#
|
1354
|
+
def transaction deadline: 120, commit_options: nil, call_options: nil
|
1033
1355
|
ensure_service!
|
1034
1356
|
unless Thread.current[:transaction_id].nil?
|
1035
1357
|
raise "Nested transactions are not allowed"
|
@@ -1044,8 +1366,12 @@ module Google
|
|
1044
1366
|
Thread.current[:transaction_id] = tx.transaction_id
|
1045
1367
|
yield tx
|
1046
1368
|
commit_resp = @project.service.commit \
|
1047
|
-
tx.session.path, tx.mutations,
|
1048
|
-
|
1369
|
+
tx.session.path, tx.mutations,
|
1370
|
+
transaction_id: tx.transaction_id,
|
1371
|
+
commit_options: commit_options,
|
1372
|
+
call_options: call_options
|
1373
|
+
resp = CommitResponse.from_grpc commit_resp
|
1374
|
+
commit_options ? resp : resp.timestamp
|
1049
1375
|
rescue GRPC::Aborted, Google::Cloud::AbortedError => err
|
1050
1376
|
# Re-raise if deadline has passed
|
1051
1377
|
if current_time - start_time > deadline
|
@@ -1073,6 +1399,7 @@ module Google
|
|
1073
1399
|
end
|
1074
1400
|
|
1075
1401
|
# rubocop:enable Metrics/AbcSize
|
1402
|
+
# rubocop:enable Metrics/BlockLength
|
1076
1403
|
# rubocop:enable Metrics/MethodLength
|
1077
1404
|
|
1078
1405
|
##
|
@@ -1109,6 +1436,19 @@ module Google
|
|
1109
1436
|
# timestamp negotiation overhead of single-use `staleness`. (See
|
1110
1437
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
1111
1438
|
# @param [Numeric] exact_staleness Same as `staleness`.
|
1439
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1440
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1441
|
+
# optional. The following settings can be provided:
|
1442
|
+
#
|
1443
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1444
|
+
# that overrides the default setting.
|
1445
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1446
|
+
# setting of retry policy with the following keys:
|
1447
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1448
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1449
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1450
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1451
|
+
# trigger a retry.
|
1112
1452
|
#
|
1113
1453
|
# @yield [snapshot] The block for reading and writing data.
|
1114
1454
|
# @yieldparam [Google::Cloud::Spanner::Snapshot] snapshot The Snapshot
|
@@ -1129,7 +1469,7 @@ module Google
|
|
1129
1469
|
# end
|
1130
1470
|
#
|
1131
1471
|
def snapshot strong: nil, timestamp: nil, read_timestamp: nil,
|
1132
|
-
staleness: nil, exact_staleness: nil
|
1472
|
+
staleness: nil, exact_staleness: nil, call_options: nil
|
1133
1473
|
validate_snapshot_args! strong: strong, timestamp: timestamp,
|
1134
1474
|
read_timestamp: read_timestamp,
|
1135
1475
|
staleness: staleness,
|
@@ -1145,7 +1485,8 @@ module Google
|
|
1145
1485
|
snp_grpc = @project.service.create_snapshot \
|
1146
1486
|
session.path, strong: strong,
|
1147
1487
|
timestamp: (timestamp || read_timestamp),
|
1148
|
-
staleness: (staleness || exact_staleness)
|
1488
|
+
staleness: (staleness || exact_staleness),
|
1489
|
+
call_options: call_options
|
1149
1490
|
Thread.current[:transaction_id] = snp_grpc.id
|
1150
1491
|
snp = Snapshot.from_grpc snp_grpc, session
|
1151
1492
|
yield snp if block_given?
|
@@ -1336,8 +1677,8 @@ module Google
|
|
1336
1677
|
def create_new_session
|
1337
1678
|
ensure_service!
|
1338
1679
|
grpc = @project.service.create_session \
|
1339
|
-
Admin::Database::V1::
|
1340
|
-
project_id, instance_id, database_id
|
1680
|
+
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
1681
|
+
project: project_id, instance: instance_id, database: database_id
|
1341
1682
|
),
|
1342
1683
|
labels: @session_labels
|
1343
1684
|
Session.from_grpc grpc, @project.service, query_options: @query_options
|
@@ -1364,8 +1705,8 @@ module Google
|
|
1364
1705
|
def batch_create_sessions session_count
|
1365
1706
|
ensure_service!
|
1366
1707
|
resp = @project.service.batch_create_sessions \
|
1367
|
-
Admin::Database::V1::
|
1368
|
-
project_id, instance_id, database_id
|
1708
|
+
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
1709
|
+
project: project_id, instance: instance_id, database: database_id
|
1369
1710
|
),
|
1370
1711
|
session_count,
|
1371
1712
|
labels: @session_labels
|
@@ -1421,9 +1762,9 @@ module Google
|
|
1421
1762
|
bounded_staleness = Convert.number_to_duration \
|
1422
1763
|
opts[:bounded_staleness] || opts[:max_staleness]
|
1423
1764
|
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1765
|
+
V1::TransactionSelector.new(single_use:
|
1766
|
+
V1::TransactionOptions.new(read_only:
|
1767
|
+
V1::TransactionOptions::ReadOnly.new({
|
1427
1768
|
strong: opts[:strong],
|
1428
1769
|
read_timestamp: exact_timestamp,
|
1429
1770
|
exact_staleness: exact_staleness,
|
@@ -1435,7 +1776,7 @@ module Google
|
|
1435
1776
|
|
1436
1777
|
def pdml_transaction session
|
1437
1778
|
pdml_tx_grpc = @project.service.create_pdml session.path
|
1438
|
-
|
1779
|
+
V1::TransactionSelector.new id: pdml_tx_grpc.id
|
1439
1780
|
end
|
1440
1781
|
|
1441
1782
|
##
|