google-cloud-spanner 2.27.0 → 2.29.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2950745d1ef3cf6be982e2bc64a29ce467e8a15710293265181d41dd138a80ad
4
- data.tar.gz: 6e96c531e76300e6d77d5d261ec0d09da96157f82aa3f4c32c502b52ce6b6f74
3
+ metadata.gz: c47f3cfa10a6d612de5578cd6602dece290f316246a809a265b504fc74737307
4
+ data.tar.gz: fe95585faa6210cb5110dbc54e3bb95e0a9126577c1893854880ebd8232946a1
5
5
  SHA512:
6
- metadata.gz: 55291fac48fb628c64d4df17266cf1a07babbd918b8411e7116e8ba23b0430c20dbf0f210098f27052bbcd9d97c9e3ed0ec2937a4c342cb5994946df2dcf2ac6
7
- data.tar.gz: b2e91d7c79a316a69b3657eace1232936a13013236117170b974a9487e0d9fdd5c9de34bba851ffbe310a26c6864954fd94de68df91fdb1a9d64bd06773d5aff
6
+ metadata.gz: fa836a8f8a9e7da61b9ca53e655a8ab0870dcc50435756af6d2637931b9f16c1f12853a4eab16038176ca4b85395f6d83d7cbccec9a8c37ad5c562f9ee83ad2e
7
+ data.tar.gz: 873894c371f0f7e9679a4df3f4b8fdc28e0047f135584b11616bc25f53982ef42b378cd323c3216d2283f6517071d218dc8a1c7a60fb1b842bac9422fa0b3bda
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Release History
2
2
 
3
+ ### 2.29.0 (2025-11-06)
4
+
5
+ #### Features
6
+
7
+ * allow sending request tags for snapshot queries ([#200](https://github.com/googleapis/ruby-spanner/issues/200))
8
+ #### Bug Fixes
9
+
10
+ * Don't route to leader for single-use transactions in Client#execute_query ([#201](https://github.com/googleapis/ruby-spanner/issues/201))
11
+
12
+ ### 2.28.0 (2025-10-22)
13
+
14
+ #### Features
15
+
16
+ * Add support for order_by and lock_hint options ([#182](https://github.com/googleapis/ruby-spanner/issues/182))
17
+
18
+ #### Bug Fixes
19
+
20
+ * use create Transaction when retrying when enumerating rows in `Spanner::Results` ([#191](https://github.com/googleapis/ruby-spanner/issues/191))
21
+ * run explicit BeginTransaction in Client#transaction for mutation-only payloads ([#191](https://github.com/googleapis/ruby-spanner/issues/191))
22
+ * Transaction#initialize is no longer incorrectly marked as public in documentation ([#191](https://github.com/googleapis/ruby-spanner/issues/191))
23
+ * several field accessors in Partition are no longer incorrectly marked as public in documentation ([#191](https://github.com/googleapis/ruby-spanner/issues/191))
24
+ * session keepalive uses Process.clock_gettime instead of Time.now ([#185](https://github.com/googleapis/ruby-spanner/pull/185))
25
+
3
26
  ### 2.27.0 (2025-05-28)
4
27
 
5
28
  #### Features
@@ -33,8 +33,9 @@ module Google
33
33
  # {Google::Cloud::Spanner::Admin::Database.database_admin}.list_backup_operations instead.
34
34
  #
35
35
  class List < DelegateClass(::Array)
36
+ # The `Spanner::Service` reference.
36
37
  # @private
37
- # The gRPC Service object.
38
+ # @return [::Google::Cloud::Spanner::Service]
38
39
  attr_accessor :service
39
40
 
40
41
  # @private
@@ -148,13 +149,14 @@ module Google
148
149
  end
149
150
  end
150
151
 
151
- ##
152
- # @private
153
- #
154
- # New Backup::Job::List from a
152
+ # Creates a new `Spanner::Backup::Job::List` of `Gapic::Operation` operations from a
155
153
  # `Gapic::PagedEnumerable<Google::Longrunning::Operation>`
156
154
  # object. Operation object is a backup operation.
157
- #
155
+ # @param grpc [::Gapic::PagedEnumerable<::Google::Longrunning::Operation>]
156
+ # Wrapped `Gapic::PagedEnumberable` reference.
157
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
158
+ # @private
159
+ # @return [::Google::Cloud::Spanner::Backup::Job::List]
158
160
  def self.from_grpc grpc, service
159
161
  operations_client =
160
162
  service.databases.instance_variable_get "@operations_client"
@@ -58,12 +58,14 @@ module Google
58
58
  # end
59
59
  #
60
60
  class Job
61
- ##
62
- # @private The `Gapic::Operation` gRPC object.
61
+ # The wrapped `Gapic::Operation` object.
62
+ # @private
63
+ # @return [::Gapic::Operation]
63
64
  attr_accessor :grpc
64
65
 
65
- ##
66
- # @private The gRPC Service object.
66
+ # The `Spanner::Service` reference.
67
+ # @private
68
+ # @return [::Google::Cloud::Spanner::Service]
67
69
  attr_accessor :service
68
70
 
69
71
  ##
@@ -265,8 +267,11 @@ module Google
265
267
  Convert.timestamp_to_time @grpc.metadata.cancel_time
266
268
  end
267
269
 
268
- ##
269
- # @private New Backup::Job from a `Gapic::Operation` object.
270
+ # Create a new Backup::Job from a `Gapic::Operation` object.
271
+ # @param grpc [::Gapic::Operation`] The wrapped `Gapic::Operation` object.
272
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
273
+ # @private
274
+ # @return [::Google::Cloud::Spanner::Backup::Job]
270
275
  def self.from_grpc grpc, service
271
276
  new.tap do |job|
272
277
  job.instance_variable_set :@grpc, grpc
@@ -63,8 +63,18 @@ module Google
63
63
  # new_partition
64
64
  #
65
65
  class BatchClient
66
- ##
67
- # @private Creates a new Spanner BatchClient instance.
66
+ # Creates a new Spanner BatchClient instance.
67
+ # @param project [::Google::Cloud::Spanner::Project] A `Spanner::Project` ref.
68
+ # @param instance_id [::String] Instance id, e.g. `"my-instance"`.
69
+ # @param database_id [::String] Database id, e.g. `"my-database"`.
70
+ # @param session_labels [::Hash, nil] Optional. The labels to be applied to all sessions
71
+ # created by the client. Example: `"team" => "billing-service"`.
72
+ # @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
73
+ # query options for executing SQL query. Example parameter `:optimizer_version`.
74
+ # @param directed_read_options [::Hash, nil] Optional. Client options used to set
75
+ # the `directed_read_options` for all ReadRequests and ExecuteSqlRequests.
76
+ # Converts to `V1::DirectedReadOptions`. Example option: `:exclude_replicas`.
77
+ # @private
68
78
  def initialize project, instance_id, database_id, session_labels: nil,
69
79
  query_options: nil, directed_read_options: nil
70
80
  @project = project
@@ -404,15 +414,18 @@ module Google
404
414
 
405
415
  protected
406
416
 
407
- ##
408
- # @private Raise an error unless an active connection to the service is
417
+ # Raise an error unless an active connection to the service is
409
418
  # available.
419
+ # @private
420
+ # @raise [StandardError]
421
+ # @return [nil]
410
422
  def ensure_service!
411
423
  raise "Must have active connection to service" unless @project.service
412
424
  end
413
425
 
414
- ##
415
426
  # New session for each use.
427
+ # @private
428
+ # @return [::Google::Cloud::Spanner::Session]
416
429
  def session
417
430
  ensure_service!
418
431
  grpc = @project.service.create_session \
@@ -51,12 +51,26 @@ module Google
51
51
  # end
52
52
  #
53
53
  class Client
54
- ##
54
+ # A semi-arbitrary constant for thread-wide global parameter name
55
55
  # @private
56
56
  IS_TRANSACTION_RUNNING_KEY = "ruby_spanner_is_transaction_running".freeze
57
57
 
58
- ##
59
- # @private Creates a new Spanner Client instance.
58
+ # Creates a new Spanner Client instance.
59
+ # @param project [::Google::Cloud::Spanner::Project] A `Spanner::Project` ref.
60
+ # @param instance_id [::String] Instance id, e.g. `"my-instance"`.
61
+ # @param database_id [::String] Database id, e.g. `"my-database"`.
62
+ # @param session_labels [::Hash, nil] Optional. The labels to be applied to all sessions
63
+ # created by the client. Example: `"team" => "billing-service"`.
64
+ # @param pool_opts [::Hash] Optional. `Spanner::Pool` creation options.
65
+ # Example parameter: `:keepalive`.
66
+ # @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
67
+ # query options for executing SQL query. Example parameter `:optimizer_version`.
68
+ # @param database_role [::String, nil] Optional. The Spanner session creator role.
69
+ # Example: `analyst`
70
+ # @param directed_read_options [::Hash, nil] Optional. Client options used to set
71
+ # the `directed_read_options` for all ReadRequests and ExecuteSqlRequests.
72
+ # Converts to `V1::DirectedReadOptions`. Example option: `:exclude_replicas`.
73
+ # @private
60
74
  def initialize project, instance_id, database_id, session_labels: nil,
61
75
  pool_opts: {}, query_options: nil, database_role: nil,
62
76
  directed_read_options: nil
@@ -89,7 +103,7 @@ module Google
89
103
  end
90
104
 
91
105
  # The Spanner project connected to.
92
- # @return [Project]
106
+ # @return [::Google::Cloud::Spanner::Project]
93
107
  def project
94
108
  @project
95
109
  end
@@ -470,7 +484,7 @@ module Google
470
484
  request_options = Convert.to_request_options request_options,
471
485
  tag_type: :request_tag
472
486
  single_use_tx = single_use_transaction single_use
473
- route_to_leader = LARHeaders.execute_query true
487
+ route_to_leader = LARHeaders.execute_query false
474
488
  results = nil
475
489
  @pool.with_session do |session|
476
490
  results = session.execute_query \
@@ -878,6 +892,14 @@ module Google
878
892
  # and all replicas are exhausted without finding a healthy replica,
879
893
  # Spanner will wait for a replica in the list to become available,
880
894
  # requests may fail due to DEADLINE_EXCEEDED errors.
895
+ # @param [::Google::Cloud::Spanner::V1::ReadRequest::OrderBy] order_by An option to control the order in which
896
+ # rows are returned from a read.
897
+ # To see the available options refer to
898
+ # [Google::Cloud::Spanner::V1::ReadRequest::OrderBy](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-OrderBy)
899
+ # @param [::Google::Cloud::Spanner::V1::ReadRequest::LockHint] lock_hint A lock hint mechanism for reads done
900
+ # within a transaction.
901
+ # To see the available options refer to
902
+ # [Google::Cloud::Spanner::V1::ReadRequest::LockHint](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-LockHint)
881
903
  #
882
904
  # @return [Google::Cloud::Spanner::Results] The results of the read.
883
905
  #
@@ -962,7 +984,7 @@ module Google
962
984
  #
963
985
  def read table, columns, keys: nil, index: nil, limit: nil,
964
986
  single_use: nil, request_options: nil, call_options: nil,
965
- directed_read_options: nil
987
+ directed_read_options: nil, order_by: nil, lock_hint: nil
966
988
  validate_single_use_args! single_use
967
989
  ensure_service!
968
990
 
@@ -981,7 +1003,9 @@ module Google
981
1003
  request_options: request_options,
982
1004
  call_options: call_options,
983
1005
  directed_read_options: directed_read_options || @directed_read_options,
984
- route_to_leader: route_to_leader
1006
+ route_to_leader: route_to_leader,
1007
+ order_by: order_by,
1008
+ lock_hint: lock_hint
985
1009
  end
986
1010
  results
987
1011
  end
@@ -2102,15 +2126,28 @@ module Google
2102
2126
  begin
2103
2127
  Thread.current[IS_TRANSACTION_RUNNING_KEY] = true
2104
2128
  yield tx
2105
- transaction_id = nil
2106
- transaction_id = tx.transaction_id if tx.existing_transaction?
2107
- commit_resp = @project.service.commit \
2108
- tx.session.path, tx.mutations,
2129
+
2130
+ unless tx.existing_transaction?
2131
+ # This can happen if the yielded `tx` object was only used to add mutations.
2132
+ # Then it never called any RPCs and didn't create a server-side Transaction object.
2133
+ # In which case we should make an explicit BeginTransaction call here.
2134
+ tx.safe_begin_transaction!(
2135
+ exclude_from_change_streams: exclude_txn_from_change_streams,
2136
+ request_options: request_options,
2137
+ call_options: call_options
2138
+ )
2139
+ end
2140
+
2141
+ transaction_id = tx.transaction_id
2142
+ commit_resp = @project.service.commit(
2143
+ tx.session.path,
2144
+ tx.mutations,
2109
2145
  transaction_id: transaction_id,
2110
2146
  exclude_txn_from_change_streams: exclude_txn_from_change_streams,
2111
2147
  commit_options: commit_options,
2112
2148
  request_options: request_options,
2113
2149
  call_options: call_options
2150
+ )
2114
2151
  resp = CommitResponse.from_grpc commit_resp
2115
2152
  commit_options ? resp : resp.timestamp
2116
2153
  rescue GRPC::Aborted,
@@ -2409,17 +2446,21 @@ module Google
2409
2446
  @pool.reset
2410
2447
  end
2411
2448
 
2412
- ##
2449
+ # Creates a new Session objece.
2450
+ # @param multiplexed [::Boolean] Optional. Default to `false`.
2451
+ # If `true`, specifies a multiplexed session.
2413
2452
  # @private
2414
- # Creates a new session object every time.
2415
- def create_new_session
2453
+ # @return [::Google::Cloud::Spanner::Session]
2454
+ def create_new_session multiplexed: false
2416
2455
  ensure_service!
2417
2456
  grpc = @project.service.create_session \
2418
2457
  Admin::Database::V1::DatabaseAdmin::Paths.database_path(
2419
2458
  project: project_id, instance: instance_id, database: database_id
2420
2459
  ),
2421
2460
  labels: @session_labels,
2422
- database_role: @database_role
2461
+ database_role: @database_role,
2462
+ multiplexed: multiplexed
2463
+
2423
2464
  Session.from_grpc grpc, @project.service, query_options: @query_options
2424
2465
  end
2425
2466
 
@@ -74,11 +74,16 @@ module Google
74
74
  # end
75
75
  #
76
76
  class Instance
77
- ##
78
- # @private The gRPC Service object.
77
+ # The `Spanner::Service` reference.
78
+ # @private
79
+ # @return [::Google::Cloud::Spanner::Service]
79
80
  attr_accessor :service
80
81
 
81
- # @private Creates a new Instance instance.
82
+ # Creates a new `Spanner::Instance` instance.
83
+ # @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
84
+ # The protobuf `V1::Instance` underlying object.
85
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
86
+ # @private
82
87
  def initialize grpc, service
83
88
  @grpc = grpc
84
89
  @service = service
@@ -957,9 +962,13 @@ module Google
957
962
  grpc.permissions
958
963
  end
959
964
 
960
- ##
961
- # @private Creates a new Instance instance from a
965
+ # Creates a new Instance instance from a
962
966
  # `Google::Cloud::Spanner::Admin::Instance::V1::Instance`.
967
+ # @param grpc [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
968
+ # The protobuf `V1::Instance` underlying object.
969
+ # @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` reference.
970
+ # @private
971
+ # @return [::Google::Cloud::Spanner::Instance]
963
972
  def self.from_grpc grpc, service
964
973
  new grpc, service
965
974
  end
@@ -75,7 +75,7 @@ module Google
75
75
  (?:T(?!$)
76
76
  (?:(?<hours>-?\d+)H)?
77
77
  (?:(?<minutes>-?\d+)M)?
78
- (?:(?<seconds>-?(?!S)\d*(?:[\.,]\d{1,9})?)S)?)?
78
+ (?:(?<seconds>-?(?!S)\d*(?:[.,]\d{1,9})?)S)?)?
79
79
  $
80
80
  /x
81
81
  interval_months = 0
@@ -44,8 +44,14 @@ module Google
44
44
  # results = batch_snapshot.execute_partition partition
45
45
  #
46
46
  class Partition
47
- # @ private
47
+ # A `V1::ExecuteSqlRequest` that is related to this partition.
48
+ # @private
49
+ # @return [::Google::Cloud::Spanner::V1::ExecuteSqlRequest]
48
50
  attr_reader :execute
51
+
52
+ # A `V1::ReadRequest` that is related to this partition.
53
+ # @private
54
+ # @return [::Google::Cloud::Spanner::V1::ReadRequest]
49
55
  attr_reader :read
50
56
 
51
57
  ##
@@ -36,6 +36,16 @@ module Google
36
36
  # and `Session` objects as values.
37
37
  attr_accessor :sessions_in_use
38
38
 
39
+ # Creates a new Session pool that manages non-multiplexed sessions.
40
+ # @param client [::Google::Cloud::Spanner::Client] A `Spanner::Client` reference
41
+ # @param min [::Integer] Min number of sessions to keep
42
+ # @param max [::Integer] Max number of sessions to keep
43
+ # @param keepalive [::Numeric] How long after their last usage the sessions can be reclaimed
44
+ # @param fail [::Boolean] If `true` the pool will raise `SessionLimitError` if number of new sessions
45
+ # needed is more that can be created due to the `max` parameter. If `false` it will wait instead.
46
+ # @param threads [::Integer, nil] Number of threads in the thread pool that is used for keepalive and
47
+ # release session actions. If `nil` the Pool will choose a reasonable default.
48
+ # @private
39
49
  def initialize client, min: 10, max: 100, keepalive: 1800,
40
50
  fail: true, threads: nil
41
51
  @client = client
@@ -52,6 +62,11 @@ module Google
52
62
  init
53
63
  end
54
64
 
65
+ # Provides a session for running an operation
66
+ # @yield session Session a client can use to run an operation
67
+ # @yieldparam [::Google::Cloud::Spanner::Session] `Spanner::Session` to run an operation
68
+ # @private
69
+ # @return [nil]
55
70
  def with_session
56
71
  session = checkout_session
57
72
  begin
@@ -66,12 +66,22 @@ module Google
66
66
  # end
67
67
  #
68
68
  class Project
69
- ##
70
- # @private The Service object.
71
- attr_accessor :service, :query_options
69
+ # The `Spanner::Service` reference.
70
+ # @private
71
+ # @return [::Google::Cloud::Spanner::Service]
72
+ attr_accessor :service
72
73
 
73
- ##
74
- # @private Creates a new Spanner Project instance.
74
+ # A hash of values to specify the custom query options for executing SQL query.
75
+ # Example option: `:optimizer_version`.
76
+ # @private
77
+ # @return [::Hash, nil]
78
+ attr_accessor :query_options
79
+
80
+ # Creates a new Spanner Project instance.
81
+ # @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` ref.
82
+ # @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
83
+ # query options for executing SQL query. Example option: `:optimizer_version`.
84
+ # @private
75
85
  def initialize service, query_options: nil
76
86
  @service = service
77
87
  @query_options = query_options
@@ -80,6 +90,8 @@ module Google
80
90
  ##
81
91
  # The identifier for the Cloud Spanner project.
82
92
  #
93
+ # @return [::String]
94
+ #
83
95
  # @example
84
96
  # require "google/cloud"
85
97
  #
@@ -40,19 +40,44 @@ module Google
40
40
  # puts "Column #{name} is type #{type}"
41
41
  # end
42
42
  #
43
+ # results.rows.each do |row|
44
+ # puts "User #{row[:id]} is #{row[:name]}"
45
+ # end
46
+ #
43
47
  class Results
44
- ##
45
- # @private Object of type
46
- # Google::Cloud::Spanner::V1::ResultSetMetadata
48
+ # The `V1::ResultSetMetadata` protobuf object from the first
49
+ # PartialResultSet.
50
+ # @private
51
+ # @return [::Google::Cloud::Spanner::V1::ResultSetMetadata]
47
52
  attr_reader :metadata
48
53
 
54
+ # Creates a new Results instance.
55
+ # @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
56
+ # @param partial_result_sets [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
57
+ # Raw enumerable from grpc `StreamingRead` call.
58
+ # @param session_name [::String] Required.
59
+ # The session in which the transaction to be committed is running.
60
+ # Values are of the form:
61
+ # `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
62
+ # @param metadata [::Google::Cloud::Spanner::V1::ResultSetMetadata] ParialResultSet metadata object
63
+ # @param stats [::Google::Cloud::Spanner::V1::ResultSetStats] Query plan and execution statistics
64
+ # for the statement that produced this streaming result set.
65
+ # @private
66
+ def initialize service, partial_result_sets, session_name, metadata, stats
67
+ @service = service
68
+ @partial_result_sets = partial_result_sets
69
+ @session_name = session_name
70
+ @metadata = metadata
71
+ @stats = stats
72
+ end
73
+
49
74
  ##
50
75
  # The read timestamp chosen for single-use snapshots (read-only
51
76
  # transactions).
52
77
  # @return [Time] The chosen timestamp.
53
78
  def timestamp
54
- return nil if @metadata.nil? || @metadata.transaction.nil?
55
- Convert.timestamp_to_time @metadata.transaction.read_timestamp
79
+ return nil if transaction.nil?
80
+ Convert.timestamp_to_time transaction.read_timestamp
56
81
  end
57
82
 
58
83
  ##
@@ -78,9 +103,9 @@ module Google
78
103
  @fields ||= Fields.from_grpc @metadata.row_type.fields
79
104
  end
80
105
 
81
- ##
106
+ # Returns a transaction from the first ResultSet's metadata if available
82
107
  # @private
83
- # Returns a transaction if available
108
+ # @return [::Google::Cloud::Spanner::V1::Transaction, nil]
84
109
  def transaction
85
110
  @metadata&.transaction
86
111
  end
@@ -128,16 +153,18 @@ module Google
128
153
  loop do
129
154
  begin
130
155
  if should_resume_request
131
- @enum = resume_request(resume_token)
156
+ @partial_result_sets = resume_request(resume_token)
132
157
  buffered_responses = []
133
158
  should_resume_request = false
134
159
  elsif should_retry_request
135
- @enum = retry_request()
160
+ @partial_result_sets = retry_request()
136
161
  buffered_responses = []
137
162
  should_retry_request = false
138
163
  end
139
164
 
140
- grpc = @enum.next
165
+ # @type [::Google::Cloud::Spanner::V1::PartialResultsSet]
166
+ grpc = @partial_result_sets.next
167
+
141
168
  # metadata should be set before the first iteration...
142
169
  @metadata ||= grpc.metadata
143
170
  @stats ||= grpc.stats
@@ -243,13 +270,13 @@ module Google
243
270
  def resume_request resume_token
244
271
  if @execute_query_options
245
272
  @service.execute_streaming_sql(
246
- @session_path,
273
+ @session_name,
247
274
  @sql,
248
275
  **@execute_query_options.merge(resume_token: resume_token)
249
276
  )
250
277
  else
251
278
  @service.streaming_read_table(
252
- @session_path,
279
+ @session_name,
253
280
  @table,
254
281
  @columns,
255
282
  **@read_options.merge(resume_token: resume_token)
@@ -262,9 +289,9 @@ module Google
262
289
  # Retries a request, by re-executing it from scratch.
263
290
  def retry_request
264
291
  if @execute_query_options
265
- @service.execute_streaming_sql @session_path, @sql, **@execute_query_options
292
+ @service.execute_streaming_sql @session_name, @sql, **@execute_query_options
266
293
  else
267
- @service.streaming_read_table @session_path, @table, @columns, **@read_options
294
+ @service.streaming_read_table @session_name, @table, @columns, **@read_options
268
295
  end
269
296
  end
270
297
 
@@ -295,35 +322,80 @@ module Google
295
322
  @stats.row_count == :row_count_exact
296
323
  end
297
324
 
325
+ # Creates a `Spanner::Results` for a given `PartialResultSet` grpc stream.
326
+ # @param partial_result_sets [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
327
+ # Raw enumerable from underlying grpc call.
328
+ # @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
329
+ # @param session_name [::String] Required.
330
+ # The session in which the transaction to be committed is running.
331
+ # Values are of the form:
332
+ # `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
298
333
  # @private
299
- def self.from_enum enum, service
300
- grpc = enum.peek
301
- new.tap do |results|
302
- results.instance_variable_set :@metadata, grpc.metadata
303
- results.instance_variable_set :@stats, grpc.stats
304
- results.instance_variable_set :@enum, enum
305
- results.instance_variable_set :@service, service
306
- end
334
+ # @return [::Google::Cloud::Spanner::Results]
335
+ def self.from_partial_result_sets partial_result_sets, service, session_name
336
+ # @type [::Google::Cloud::Spanner::V1::PartialResultSet]
337
+ partial_result_set = partial_result_sets.peek
338
+ metadata = partial_result_set.metadata
339
+ stats = partial_result_set.stats
340
+ new service, partial_result_sets, session_name, metadata, stats
307
341
  rescue GRPC::BadStatus => e
308
342
  raise Google::Cloud::Error.from_error(e)
309
343
  end
310
344
 
345
+ # Creates a `Spanner::Results` wrapper from ExecuteStreamingSql call results and params.
346
+ # @param response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
347
+ # Raw enumerable from grpc `ExecuteStreamingSql` call.
348
+ # @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
349
+ # @param session_name [::String] Required.
350
+ # The session in which the transaction to be committed is running.
351
+ # Values are of the form:
352
+ # `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
353
+ # @param sql [::String] The SQL query string that was executed.
354
+ # @param execute_query_options [::Hash] Full request options
355
+ # that were sent to the `service.execute_streaming_sql`. This hash joins params needed to
356
+ # construct `::Gapic::CallOptions`, e.g. `call_options` and header-related `route_to_leader`
357
+ # with params specific to `execute_streaming_sql`, such as `seqno`.
311
358
  # @private
312
- def self.from_execute_query_response response, service, session_path, sql, execute_query_options
313
- from_enum(response, service).tap do |results|
314
- results.instance_variable_set :@session_path, session_path
359
+ # @return [::Google::Cloud::Spanner::Results]
360
+ def self.from_execute_query_response response, service, session_name, sql, execute_query_options
361
+ from_partial_result_sets(response, service, session_name).tap do |results|
362
+ execute_query_options_copy = execute_query_options.dup
363
+ unless results.metadata.transaction.nil?
364
+ execute_query_options_copy[:transaction] = V1::TransactionSelector.new id: results.metadata.transaction.id
365
+ end
366
+
315
367
  results.instance_variable_set :@sql, sql
316
- results.instance_variable_set :@execute_query_options, execute_query_options
368
+ results.instance_variable_set :@execute_query_options, execute_query_options_copy
317
369
  end
318
370
  end
319
371
 
372
+ # Creates a `Spanner::Results` wrapper from StreamingRead call results and params.
373
+ # @param response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
374
+ # Raw enumerable from grpc `StreamingRead` call.
375
+ # @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
376
+ # @param session_name [::String] Required.
377
+ # The session in which the transaction to be committed is running.
378
+ # Values are of the form:
379
+ # `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
380
+ # @param table [::String] The name of the table in the database that was read by `StreamingRead` request.
381
+ # @param columns [::Array<String, Symbol>] The columns of table that were returned
382
+ # by the `StreamingRead` request.
383
+ # @param read_options [::Hash] Full request options
384
+ # that were sent to the `service.streaming_read_table`. This hash joins params needed to
385
+ # construct `::Gapic::CallOptions`, e.g. `call_options` and header-related `route_to_leader`
386
+ # with params specific to `streaming_read_table`, such as `keys`.
320
387
  # @private
321
- def self.from_read_response response, service, session_path, table, columns, read_options
322
- from_enum(response, service).tap do |results|
323
- results.instance_variable_set :@session_path, session_path
388
+ # @return [::Google::Cloud::Spanner::Results]
389
+ def self.from_read_response response, service, session_name, table, columns, read_options
390
+ from_partial_result_sets(response, service, session_name).tap do |results|
391
+ read_options_copy = read_options.dup
392
+ unless results.metadata.transaction.nil?
393
+ read_options_copy[:transaction] = V1::TransactionSelector.new id: results.metadata.transaction.id
394
+ end
395
+
324
396
  results.instance_variable_set :@table, table
325
397
  results.instance_variable_set :@columns, columns
326
- results.instance_variable_set :@read_options, read_options
398
+ results.instance_variable_set :@read_options, read_options_copy
327
399
  end
328
400
  end
329
401