google-cloud-spanner 1.16.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +1 -1
- data/CHANGELOG.md +54 -0
- data/CONTRIBUTING.md +5 -5
- data/TROUBLESHOOTING.md +0 -6
- data/lib/google-cloud-spanner.rb +11 -13
- data/lib/google/cloud/spanner.rb +6 -8
- 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 +189 -30
- data/lib/google/cloud/spanner/commit.rb +14 -14
- 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 +363 -350
- data/lib/google/cloud/spanner/session.rb +186 -31
- 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 -109
- 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
|
|
@@ -222,6 +222,19 @@ module Google
|
|
|
222
222
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
|
223
223
|
# Empty to use database default. "latest" to use the latest
|
|
224
224
|
# available optimizer version.
|
|
225
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
226
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
227
|
+
# optional. The following settings can be provided:
|
|
228
|
+
#
|
|
229
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
230
|
+
# that overrides the default setting.
|
|
231
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
232
|
+
# setting of retry policy with the following keys:
|
|
233
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
234
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
235
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
236
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
237
|
+
# trigger a retry.
|
|
225
238
|
#
|
|
226
239
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
|
227
240
|
# execution.
|
|
@@ -335,8 +348,31 @@ module Google
|
|
|
335
348
|
# puts "User #{row[:id]} is #{row[:name]}"
|
|
336
349
|
# end
|
|
337
350
|
#
|
|
351
|
+
# @example Query using custom timeout and retry policy:
|
|
352
|
+
# require "google/cloud/spanner"
|
|
353
|
+
#
|
|
354
|
+
# spanner = Google::Cloud::Spanner.new
|
|
355
|
+
#
|
|
356
|
+
# db = spanner.client "my-instance", "my-database"
|
|
357
|
+
#
|
|
358
|
+
# timeout = 30.0
|
|
359
|
+
# retry_policy = {
|
|
360
|
+
# initial_delay: 0.25,
|
|
361
|
+
# max_delay: 32.0,
|
|
362
|
+
# multiplier: 1.3,
|
|
363
|
+
# retry_codes: ["UNAVAILABLE"]
|
|
364
|
+
# }
|
|
365
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
|
366
|
+
#
|
|
367
|
+
# results = db.execute_query \
|
|
368
|
+
# "SELECT * FROM users", call_options: call_options
|
|
369
|
+
#
|
|
370
|
+
# results.rows.each do |row|
|
|
371
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
|
372
|
+
# end
|
|
373
|
+
#
|
|
338
374
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
|
339
|
-
query_options: nil
|
|
375
|
+
query_options: nil, call_options: nil
|
|
340
376
|
validate_single_use_args! single_use
|
|
341
377
|
ensure_service!
|
|
342
378
|
|
|
@@ -347,7 +383,7 @@ module Google
|
|
|
347
383
|
@pool.with_session do |session|
|
|
348
384
|
results = session.execute_query \
|
|
349
385
|
sql, params: params, types: types, transaction: single_use_tx,
|
|
350
|
-
query_options: query_options
|
|
386
|
+
query_options: query_options, call_options: call_options
|
|
351
387
|
end
|
|
352
388
|
results
|
|
353
389
|
end
|
|
@@ -474,14 +510,6 @@ module Google
|
|
|
474
510
|
# value in `params`. In these cases, the `types` hash can be used to
|
|
475
511
|
# specify the exact SQL type for some or all of the SQL query
|
|
476
512
|
# 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
513
|
#
|
|
486
514
|
# The keys of the hash should be query string parameter placeholders,
|
|
487
515
|
# minus the "@". The values of the hash should be Cloud Spanner type
|
|
@@ -499,6 +527,26 @@ module Google
|
|
|
499
527
|
# `[:INT64]`.
|
|
500
528
|
# * {Fields} - Nested Structs are specified by providing a Fields
|
|
501
529
|
# object.
|
|
530
|
+
# @param [Hash] query_options A hash of values to specify the custom
|
|
531
|
+
# query options for executing SQL query. Query options are optional.
|
|
532
|
+
# The following settings can be provided:
|
|
533
|
+
#
|
|
534
|
+
# * `:optimizer_version` (String) The version of optimizer to use.
|
|
535
|
+
# Empty to use database default. "latest" to use the latest
|
|
536
|
+
# available optimizer version.
|
|
537
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
538
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
539
|
+
# optional. The following settings can be provided:
|
|
540
|
+
#
|
|
541
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
542
|
+
# that overrides the default setting.
|
|
543
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
544
|
+
# setting of retry policy with the following keys:
|
|
545
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
546
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
547
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
548
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
549
|
+
# trigger a retry.
|
|
502
550
|
# @return [Integer] The lower bound number of rows that were modified.
|
|
503
551
|
#
|
|
504
552
|
# @example
|
|
@@ -529,8 +577,28 @@ module Google
|
|
|
529
577
|
# row_count = db.execute_partition_update \
|
|
530
578
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
|
531
579
|
# query_options: { optimizer_version: "1" }
|
|
580
|
+
#
|
|
581
|
+
# @example Query using custom timeout and retry policy:
|
|
582
|
+
# require "google/cloud/spanner"
|
|
583
|
+
#
|
|
584
|
+
# spanner = Google::Cloud::Spanner.new
|
|
585
|
+
# db = spanner.client "my-instance", "my-database"
|
|
586
|
+
#
|
|
587
|
+
# timeout = 30.0
|
|
588
|
+
# retry_policy = {
|
|
589
|
+
# initial_delay: 0.25,
|
|
590
|
+
# max_delay: 32.0,
|
|
591
|
+
# multiplier: 1.3,
|
|
592
|
+
# retry_codes: ["UNAVAILABLE"]
|
|
593
|
+
# }
|
|
594
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
|
595
|
+
#
|
|
596
|
+
# row_count = db.execute_partition_update \
|
|
597
|
+
# "UPDATE users SET friends = NULL WHERE active = false",
|
|
598
|
+
# call_options: call_options
|
|
599
|
+
#
|
|
532
600
|
def execute_partition_update sql, params: nil, types: nil,
|
|
533
|
-
query_options: nil
|
|
601
|
+
query_options: nil, call_options: nil
|
|
534
602
|
ensure_service!
|
|
535
603
|
|
|
536
604
|
params, types = Convert.to_input_params_and_types params, types
|
|
@@ -539,7 +607,7 @@ module Google
|
|
|
539
607
|
results = session.execute_query \
|
|
540
608
|
sql, params: params, types: types,
|
|
541
609
|
transaction: pdml_transaction(session),
|
|
542
|
-
query_options: query_options
|
|
610
|
+
query_options: query_options, call_options: call_options
|
|
543
611
|
end
|
|
544
612
|
# Stream all PartialResultSet to get ResultSetStats
|
|
545
613
|
results.rows.to_a
|
|
@@ -620,6 +688,19 @@ module Google
|
|
|
620
688
|
# Useful for reading the freshest data available at a nearby
|
|
621
689
|
# replica, while bounding the possible staleness if the local
|
|
622
690
|
# replica has fallen behind.
|
|
691
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
692
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
693
|
+
# optional. The following settings can be provided:
|
|
694
|
+
#
|
|
695
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
696
|
+
# that overrides the default setting.
|
|
697
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
698
|
+
# setting of retry policy with the following keys:
|
|
699
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
700
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
701
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
702
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
703
|
+
# trigger a retry.
|
|
623
704
|
#
|
|
624
705
|
# @return [Google::Cloud::Spanner::Results] The results of the read.
|
|
625
706
|
#
|
|
@@ -649,8 +730,30 @@ module Google
|
|
|
649
730
|
# puts "User #{row[:id]} is #{row[:name]}"
|
|
650
731
|
# end
|
|
651
732
|
#
|
|
733
|
+
# @example Read using custom timeout and retry.
|
|
734
|
+
# require "google/cloud/spanner"
|
|
735
|
+
#
|
|
736
|
+
# spanner = Google::Cloud::Spanner.new
|
|
737
|
+
#
|
|
738
|
+
# db = spanner.client "my-instance", "my-database"
|
|
739
|
+
#
|
|
740
|
+
# timeout = 30.0
|
|
741
|
+
# retry_policy = {
|
|
742
|
+
# initial_delay: 0.25,
|
|
743
|
+
# max_delay: 32.0,
|
|
744
|
+
# multiplier: 1.3,
|
|
745
|
+
# retry_codes: ["UNAVAILABLE"]
|
|
746
|
+
# }
|
|
747
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
|
748
|
+
#
|
|
749
|
+
# results = db.read "users", [:id, :name], call_options: call_options
|
|
750
|
+
#
|
|
751
|
+
# results.rows.each do |row|
|
|
752
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
|
753
|
+
# end
|
|
754
|
+
#
|
|
652
755
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
|
653
|
-
single_use: nil
|
|
756
|
+
single_use: nil, call_options: nil
|
|
654
757
|
validate_single_use_args! single_use
|
|
655
758
|
ensure_service!
|
|
656
759
|
|
|
@@ -662,7 +765,8 @@ module Google
|
|
|
662
765
|
@pool.with_session do |session|
|
|
663
766
|
results = session.read \
|
|
664
767
|
table, columns, keys: keys, index: index, limit: limit,
|
|
665
|
-
transaction: single_use_tx
|
|
768
|
+
transaction: single_use_tx,
|
|
769
|
+
call_options: call_options
|
|
666
770
|
end
|
|
667
771
|
results
|
|
668
772
|
end
|
|
@@ -911,6 +1015,19 @@ module Google
|
|
|
911
1015
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
|
912
1016
|
# ranges to match returned data to. Values should have exactly as many
|
|
913
1017
|
# elements as there are columns in the primary key.
|
|
1018
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
1019
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
1020
|
+
# optional. The following settings can be provided:
|
|
1021
|
+
#
|
|
1022
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
1023
|
+
# that overrides the default setting.
|
|
1024
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
1025
|
+
# setting of retry policy with the following keys:
|
|
1026
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
1027
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
1028
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
1029
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1030
|
+
# trigger a retry.
|
|
914
1031
|
#
|
|
915
1032
|
# @return [Time] The timestamp at which the operation committed.
|
|
916
1033
|
#
|
|
@@ -923,9 +1040,9 @@ module Google
|
|
|
923
1040
|
#
|
|
924
1041
|
# db.delete "users", [1, 2, 3]
|
|
925
1042
|
#
|
|
926
|
-
def delete table, keys = []
|
|
1043
|
+
def delete table, keys = [], call_options: nil
|
|
927
1044
|
@pool.with_session do |session|
|
|
928
|
-
session.delete table, keys
|
|
1045
|
+
session.delete table, keys, call_options: call_options
|
|
929
1046
|
end
|
|
930
1047
|
end
|
|
931
1048
|
|
|
@@ -944,6 +1061,20 @@ module Google
|
|
|
944
1061
|
# this method may be appropriate for latency sensitive and/or high
|
|
945
1062
|
# throughput blind changes.
|
|
946
1063
|
#
|
|
1064
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
1065
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
1066
|
+
# optional. The following settings can be provided:
|
|
1067
|
+
#
|
|
1068
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
1069
|
+
# that overrides the default setting.
|
|
1070
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
1071
|
+
# setting of retry policy with the following keys:
|
|
1072
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
1073
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
1074
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
1075
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1076
|
+
# trigger a retry.
|
|
1077
|
+
#
|
|
947
1078
|
# @yield [commit] The block for mutating the data.
|
|
948
1079
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
|
949
1080
|
#
|
|
@@ -961,11 +1092,11 @@ module Google
|
|
|
961
1092
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
|
962
1093
|
# end
|
|
963
1094
|
#
|
|
964
|
-
def commit &block
|
|
1095
|
+
def commit call_options: nil, &block
|
|
965
1096
|
raise ArgumentError, "Must provide a block" unless block_given?
|
|
966
1097
|
|
|
967
1098
|
@pool.with_session do |session|
|
|
968
|
-
session.commit(&block)
|
|
1099
|
+
session.commit(call_options: call_options, &block)
|
|
969
1100
|
end
|
|
970
1101
|
end
|
|
971
1102
|
|
|
@@ -988,6 +1119,19 @@ module Google
|
|
|
988
1119
|
#
|
|
989
1120
|
# @param [Numeric] deadline The total amount of time in seconds the
|
|
990
1121
|
# transaction has to succeed. The default is `120`.
|
|
1122
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
1123
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
1124
|
+
# optional. The following settings can be provided:
|
|
1125
|
+
#
|
|
1126
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
1127
|
+
# that overrides the default setting.
|
|
1128
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
1129
|
+
# setting of retry policy with the following keys:
|
|
1130
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
1131
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
1132
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
1133
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1134
|
+
# trigger a retry.
|
|
991
1135
|
#
|
|
992
1136
|
# @yield [transaction] The block for reading and writing data.
|
|
993
1137
|
# @yieldparam [Google::Cloud::Spanner::Transaction] transaction The
|
|
@@ -1029,7 +1173,7 @@ module Google
|
|
|
1029
1173
|
# end
|
|
1030
1174
|
# end
|
|
1031
1175
|
#
|
|
1032
|
-
def transaction deadline: 120
|
|
1176
|
+
def transaction deadline: 120, call_options: nil
|
|
1033
1177
|
ensure_service!
|
|
1034
1178
|
unless Thread.current[:transaction_id].nil?
|
|
1035
1179
|
raise "Nested transactions are not allowed"
|
|
@@ -1044,7 +1188,8 @@ module Google
|
|
|
1044
1188
|
Thread.current[:transaction_id] = tx.transaction_id
|
|
1045
1189
|
yield tx
|
|
1046
1190
|
commit_resp = @project.service.commit \
|
|
1047
|
-
tx.session.path, tx.mutations,
|
|
1191
|
+
tx.session.path, tx.mutations,
|
|
1192
|
+
transaction_id: tx.transaction_id, call_options: call_options
|
|
1048
1193
|
return Convert.timestamp_to_time commit_resp.commit_timestamp
|
|
1049
1194
|
rescue GRPC::Aborted, Google::Cloud::AbortedError => err
|
|
1050
1195
|
# Re-raise if deadline has passed
|
|
@@ -1109,6 +1254,19 @@ module Google
|
|
|
1109
1254
|
# timestamp negotiation overhead of single-use `staleness`. (See
|
|
1110
1255
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
|
1111
1256
|
# @param [Numeric] exact_staleness Same as `staleness`.
|
|
1257
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
|
1258
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
|
1259
|
+
# optional. The following settings can be provided:
|
|
1260
|
+
#
|
|
1261
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
|
1262
|
+
# that overrides the default setting.
|
|
1263
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
|
1264
|
+
# setting of retry policy with the following keys:
|
|
1265
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
|
1266
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
|
1267
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
1268
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
1269
|
+
# trigger a retry.
|
|
1112
1270
|
#
|
|
1113
1271
|
# @yield [snapshot] The block for reading and writing data.
|
|
1114
1272
|
# @yieldparam [Google::Cloud::Spanner::Snapshot] snapshot The Snapshot
|
|
@@ -1129,7 +1287,7 @@ module Google
|
|
|
1129
1287
|
# end
|
|
1130
1288
|
#
|
|
1131
1289
|
def snapshot strong: nil, timestamp: nil, read_timestamp: nil,
|
|
1132
|
-
staleness: nil, exact_staleness: nil
|
|
1290
|
+
staleness: nil, exact_staleness: nil, call_options: nil
|
|
1133
1291
|
validate_snapshot_args! strong: strong, timestamp: timestamp,
|
|
1134
1292
|
read_timestamp: read_timestamp,
|
|
1135
1293
|
staleness: staleness,
|
|
@@ -1145,7 +1303,8 @@ module Google
|
|
|
1145
1303
|
snp_grpc = @project.service.create_snapshot \
|
|
1146
1304
|
session.path, strong: strong,
|
|
1147
1305
|
timestamp: (timestamp || read_timestamp),
|
|
1148
|
-
staleness: (staleness || exact_staleness)
|
|
1306
|
+
staleness: (staleness || exact_staleness),
|
|
1307
|
+
call_options: call_options
|
|
1149
1308
|
Thread.current[:transaction_id] = snp_grpc.id
|
|
1150
1309
|
snp = Snapshot.from_grpc snp_grpc, session
|
|
1151
1310
|
yield snp if block_given?
|
|
@@ -1336,8 +1495,8 @@ module Google
|
|
|
1336
1495
|
def create_new_session
|
|
1337
1496
|
ensure_service!
|
|
1338
1497
|
grpc = @project.service.create_session \
|
|
1339
|
-
Admin::Database::V1::
|
|
1340
|
-
project_id, instance_id, database_id
|
|
1498
|
+
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
1499
|
+
project: project_id, instance: instance_id, database: database_id
|
|
1341
1500
|
),
|
|
1342
1501
|
labels: @session_labels
|
|
1343
1502
|
Session.from_grpc grpc, @project.service, query_options: @query_options
|
|
@@ -1364,8 +1523,8 @@ module Google
|
|
|
1364
1523
|
def batch_create_sessions session_count
|
|
1365
1524
|
ensure_service!
|
|
1366
1525
|
resp = @project.service.batch_create_sessions \
|
|
1367
|
-
Admin::Database::V1::
|
|
1368
|
-
project_id, instance_id, database_id
|
|
1526
|
+
Admin::Database::V1::DatabaseAdmin::Paths.database_path(
|
|
1527
|
+
project: project_id, instance: instance_id, database: database_id
|
|
1369
1528
|
),
|
|
1370
1529
|
session_count,
|
|
1371
1530
|
labels: @session_labels
|
|
@@ -1421,9 +1580,9 @@ module Google
|
|
|
1421
1580
|
bounded_staleness = Convert.number_to_duration \
|
|
1422
1581
|
opts[:bounded_staleness] || opts[:max_staleness]
|
|
1423
1582
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1583
|
+
V1::TransactionSelector.new(single_use:
|
|
1584
|
+
V1::TransactionOptions.new(read_only:
|
|
1585
|
+
V1::TransactionOptions::ReadOnly.new({
|
|
1427
1586
|
strong: opts[:strong],
|
|
1428
1587
|
read_timestamp: exact_timestamp,
|
|
1429
1588
|
exact_staleness: exact_staleness,
|
|
@@ -1435,7 +1594,7 @@ module Google
|
|
|
1435
1594
|
|
|
1436
1595
|
def pdml_transaction session
|
|
1437
1596
|
pdml_tx_grpc = @project.service.create_pdml session.path
|
|
1438
|
-
|
|
1597
|
+
V1::TransactionSelector.new id: pdml_tx_grpc.id
|
|
1439
1598
|
end
|
|
1440
1599
|
|
|
1441
1600
|
##
|
|
@@ -96,8 +96,8 @@ module Google
|
|
|
96
96
|
rows.delete_if(&:nil?)
|
|
97
97
|
rows.delete_if(&:empty?)
|
|
98
98
|
@mutations += rows.map do |row|
|
|
99
|
-
|
|
100
|
-
insert_or_update:
|
|
99
|
+
V1::Mutation.new(
|
|
100
|
+
insert_or_update: V1::Mutation::Write.new(
|
|
101
101
|
table: table, columns: row.keys.map(&:to_s),
|
|
102
102
|
values: [Convert.object_to_grpc_value(row.values).list_value]
|
|
103
103
|
)
|
|
@@ -154,8 +154,8 @@ module Google
|
|
|
154
154
|
rows.delete_if(&:nil?)
|
|
155
155
|
rows.delete_if(&:empty?)
|
|
156
156
|
@mutations += rows.map do |row|
|
|
157
|
-
|
|
158
|
-
insert:
|
|
157
|
+
V1::Mutation.new(
|
|
158
|
+
insert: V1::Mutation::Write.new(
|
|
159
159
|
table: table, columns: row.keys.map(&:to_s),
|
|
160
160
|
values: [Convert.object_to_grpc_value(row.values).list_value]
|
|
161
161
|
)
|
|
@@ -211,8 +211,8 @@ module Google
|
|
|
211
211
|
rows.delete_if(&:nil?)
|
|
212
212
|
rows.delete_if(&:empty?)
|
|
213
213
|
@mutations += rows.map do |row|
|
|
214
|
-
|
|
215
|
-
update:
|
|
214
|
+
V1::Mutation.new(
|
|
215
|
+
update: V1::Mutation::Write.new(
|
|
216
216
|
table: table, columns: row.keys.map(&:to_s),
|
|
217
217
|
values: [Convert.object_to_grpc_value(row.values).list_value]
|
|
218
218
|
)
|
|
@@ -270,8 +270,8 @@ module Google
|
|
|
270
270
|
rows.delete_if(&:nil?)
|
|
271
271
|
rows.delete_if(&:empty?)
|
|
272
272
|
@mutations += rows.map do |row|
|
|
273
|
-
|
|
274
|
-
replace:
|
|
273
|
+
V1::Mutation.new(
|
|
274
|
+
replace: V1::Mutation::Write.new(
|
|
275
275
|
table: table, columns: row.keys.map(&:to_s),
|
|
276
276
|
values: [Convert.object_to_grpc_value(row.values).list_value]
|
|
277
277
|
)
|
|
@@ -306,8 +306,8 @@ module Google
|
|
|
306
306
|
#
|
|
307
307
|
def delete table, keys = []
|
|
308
308
|
@mutations += [
|
|
309
|
-
|
|
310
|
-
delete:
|
|
309
|
+
V1::Mutation.new(
|
|
310
|
+
delete: V1::Mutation::Delete.new(
|
|
311
311
|
table: table, key_set: key_set(keys)
|
|
312
312
|
)
|
|
313
313
|
)
|
|
@@ -323,20 +323,20 @@ module Google
|
|
|
323
323
|
protected
|
|
324
324
|
|
|
325
325
|
def key_set keys
|
|
326
|
-
return
|
|
326
|
+
return V1::KeySet.new all: true if keys.nil?
|
|
327
327
|
keys = [keys] unless keys.is_a? Array
|
|
328
|
-
return
|
|
328
|
+
return V1::KeySet.new all: true if keys.empty?
|
|
329
329
|
if keys_are_ranges? keys
|
|
330
330
|
key_ranges = keys.map do |r|
|
|
331
331
|
Convert.to_key_range r
|
|
332
332
|
end
|
|
333
|
-
return
|
|
333
|
+
return V1::KeySet.new ranges: key_ranges
|
|
334
334
|
end
|
|
335
335
|
key_list = keys.map do |key|
|
|
336
336
|
key = [key] unless key.is_a? Array
|
|
337
337
|
Convert.object_to_grpc_value(key).list_value
|
|
338
338
|
end
|
|
339
|
-
|
|
339
|
+
V1::KeySet.new keys: key_list
|
|
340
340
|
end
|
|
341
341
|
|
|
342
342
|
def keys_are_ranges? keys
|