google-cloud-spanner 1.16.2 → 2.4.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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +66 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/lib/google-cloud-spanner.rb +11 -13
  6. data/lib/google/cloud/spanner.rb +13 -13
  7. data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
  8. data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
  9. data/lib/google/cloud/spanner/backup.rb +9 -1
  10. data/lib/google/cloud/spanner/backup/job.rb +2 -2
  11. data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
  12. data/lib/google/cloud/spanner/backup/list.rb +1 -2
  13. data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
  14. data/lib/google/cloud/spanner/batch_client.rb +2 -2
  15. data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
  16. data/lib/google/cloud/spanner/batch_update.rb +1 -1
  17. data/lib/google/cloud/spanner/client.rb +388 -47
  18. data/lib/google/cloud/spanner/commit.rb +14 -14
  19. data/lib/google/cloud/spanner/commit_response.rb +87 -0
  20. data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
  21. data/lib/google/cloud/spanner/convert.rb +16 -7
  22. data/lib/google/cloud/spanner/credentials.rb +2 -2
  23. data/lib/google/cloud/spanner/data.rb +2 -2
  24. data/lib/google/cloud/spanner/database.rb +47 -25
  25. data/lib/google/cloud/spanner/database/backup_info.rb +13 -4
  26. data/lib/google/cloud/spanner/database/job.rb +3 -3
  27. data/lib/google/cloud/spanner/database/job/list.rb +2 -2
  28. data/lib/google/cloud/spanner/database/list.rb +1 -1
  29. data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
  30. data/lib/google/cloud/spanner/fields.rb +8 -8
  31. data/lib/google/cloud/spanner/instance.rb +5 -12
  32. data/lib/google/cloud/spanner/instance/config.rb +1 -1
  33. data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
  34. data/lib/google/cloud/spanner/instance/job.rb +2 -2
  35. data/lib/google/cloud/spanner/instance/list.rb +1 -1
  36. data/lib/google/cloud/spanner/partition.rb +4 -4
  37. data/lib/google/cloud/spanner/policy.rb +2 -2
  38. data/lib/google/cloud/spanner/results.rb +103 -24
  39. data/lib/google/cloud/spanner/service.rb +369 -350
  40. data/lib/google/cloud/spanner/session.rb +370 -39
  41. data/lib/google/cloud/spanner/snapshot.rb +60 -6
  42. data/lib/google/cloud/spanner/transaction.rb +116 -10
  43. data/lib/google/cloud/spanner/version.rb +1 -1
  44. metadata +20 -107
  45. data/lib/google/cloud/spanner/admin/database.rb +0 -149
  46. data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
  47. data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
  48. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
  49. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
  50. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  51. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
  52. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
  53. data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
  54. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
  55. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
  56. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
  57. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
  58. data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
  59. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
  60. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
  61. data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
  62. data/lib/google/cloud/spanner/admin/instance.rb +0 -164
  63. data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
  64. data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
  65. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  66. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
  67. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
  68. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
  69. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
  70. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
  71. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
  72. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
  73. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
  74. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
  75. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
  76. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
  77. data/lib/google/cloud/spanner/v1.rb +0 -16
  78. data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
  79. data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
  80. data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
  81. data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
  82. data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
  83. data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
  84. data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
  85. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
  86. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
  87. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
  88. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
  89. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
  90. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
  91. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
  92. data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
  93. data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
  94. data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
  95. data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
  96. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
  97. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
  98. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
  99. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
  100. data/lib/google/spanner/v1/keys_pb.rb +0 -34
  101. data/lib/google/spanner/v1/mutation_pb.rb +0 -39
  102. data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
  103. data/lib/google/spanner/v1/result_set_pb.rb +0 -48
  104. data/lib/google/spanner/v1/spanner_pb.rb +0 -179
  105. data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
  106. data/lib/google/spanner/v1/transaction_pb.rb +0 -56
  107. data/lib/google/spanner/v1/type_pb.rb +0 -44
@@ -1,1485 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/spanner.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/spanner/v1/spanner_pb"
29
- require "google/cloud/spanner/v1/credentials"
30
- require "google/cloud/spanner/version"
31
-
32
- module Google
33
- module Cloud
34
- module Spanner
35
- module V1
36
- # Cloud Spanner API
37
- #
38
- # The Cloud Spanner API can be used to manage sessions and execute
39
- # transactions on data stored in Cloud Spanner databases.
40
- #
41
- # @!attribute [r] spanner_stub
42
- # @return [Google::Spanner::V1::Spanner::Stub]
43
- class SpannerClient
44
- # @private
45
- attr_reader :spanner_stub
46
-
47
- # The default address of the service.
48
- SERVICE_ADDRESS = "spanner.googleapis.com".freeze
49
-
50
- # The default port of the service.
51
- DEFAULT_SERVICE_PORT = 443
52
-
53
- # The default set of gRPC interceptors.
54
- GRPC_INTERCEPTORS = []
55
-
56
- DEFAULT_TIMEOUT = 30
57
-
58
- PAGE_DESCRIPTORS = {
59
- "list_sessions" => Google::Gax::PageDescriptor.new(
60
- "page_token",
61
- "next_page_token",
62
- "sessions")
63
- }.freeze
64
-
65
- private_constant :PAGE_DESCRIPTORS
66
-
67
- # The scopes needed to make gRPC calls to all of the methods defined in
68
- # this service.
69
- ALL_SCOPES = [
70
- "https://www.googleapis.com/auth/cloud-platform",
71
- "https://www.googleapis.com/auth/spanner.data"
72
- ].freeze
73
-
74
-
75
- DATABASE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
76
- "projects/{project}/instances/{instance}/databases/{database}"
77
- )
78
-
79
- private_constant :DATABASE_PATH_TEMPLATE
80
-
81
- SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
82
- "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
83
- )
84
-
85
- private_constant :SESSION_PATH_TEMPLATE
86
-
87
- # Returns a fully-qualified database resource name string.
88
- # @param project [String]
89
- # @param instance [String]
90
- # @param database [String]
91
- # @return [String]
92
- def self.database_path project, instance, database
93
- DATABASE_PATH_TEMPLATE.render(
94
- :"project" => project,
95
- :"instance" => instance,
96
- :"database" => database
97
- )
98
- end
99
-
100
- # Returns a fully-qualified session resource name string.
101
- # @param project [String]
102
- # @param instance [String]
103
- # @param database [String]
104
- # @param session [String]
105
- # @return [String]
106
- def self.session_path project, instance, database, session
107
- SESSION_PATH_TEMPLATE.render(
108
- :"project" => project,
109
- :"instance" => instance,
110
- :"database" => database,
111
- :"session" => session
112
- )
113
- end
114
-
115
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
116
- # Provides the means for authenticating requests made by the client. This parameter can
117
- # be many types.
118
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
119
- # authenticating requests made by this client.
120
- # A `String` will be treated as the path to the keyfile to be used for the construction of
121
- # credentials for this client.
122
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
123
- # credentials for this client.
124
- # A `GRPC::Core::Channel` will be used to make calls through.
125
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
126
- # should already be composed with a `GRPC::Core::CallCredentials` object.
127
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
128
- # metadata for requests, generally, to give OAuth credentials.
129
- # @param scopes [Array<String>]
130
- # The OAuth scopes for this service. This parameter is ignored if
131
- # an updater_proc is supplied.
132
- # @param client_config [Hash]
133
- # A Hash for call options for each method. See
134
- # Google::Gax#construct_settings for the structure of
135
- # this data. Falls back to the default config if not specified
136
- # or the specified config is missing data points.
137
- # @param timeout [Numeric]
138
- # The default timeout, in seconds, for calls made through this client.
139
- # @param metadata [Hash]
140
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
141
- # @param service_address [String]
142
- # Override for the service hostname, or `nil` to leave as the default.
143
- # @param service_port [Integer]
144
- # Override for the service port, or `nil` to leave as the default.
145
- # @param exception_transformer [Proc]
146
- # An optional proc that intercepts any exceptions raised during an API call to inject
147
- # custom error handling.
148
- def initialize \
149
- credentials: nil,
150
- scopes: ALL_SCOPES,
151
- client_config: {},
152
- timeout: DEFAULT_TIMEOUT,
153
- metadata: nil,
154
- service_address: nil,
155
- service_port: nil,
156
- exception_transformer: nil,
157
- lib_name: nil,
158
- lib_version: ""
159
- # These require statements are intentionally placed here to initialize
160
- # the gRPC module only when it's required.
161
- # See https://github.com/googleapis/toolkit/issues/446
162
- require "google/gax/grpc"
163
- require "google/spanner/v1/spanner_services_pb"
164
-
165
- credentials ||= Google::Cloud::Spanner::V1::Credentials.default
166
-
167
- if credentials.is_a?(String) || credentials.is_a?(Hash)
168
- updater_proc = Google::Cloud::Spanner::V1::Credentials.new(credentials).updater_proc
169
- end
170
- if credentials.is_a?(GRPC::Core::Channel)
171
- channel = credentials
172
- end
173
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
174
- chan_creds = credentials
175
- end
176
- if credentials.is_a?(Proc)
177
- updater_proc = credentials
178
- end
179
- if credentials.is_a?(Google::Auth::Credentials)
180
- updater_proc = credentials.updater_proc
181
- end
182
-
183
- package_version = Google::Cloud::Spanner::VERSION
184
-
185
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
186
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
187
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
188
- google_api_client << " grpc/#{GRPC::VERSION}"
189
- google_api_client.freeze
190
-
191
- headers = { :"x-goog-api-client" => google_api_client }
192
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
193
- headers[:"x-goog-user-project"] = credentials.quota_project_id
194
- end
195
- headers.merge!(metadata) unless metadata.nil?
196
- client_config_file = Pathname.new(__dir__).join(
197
- "spanner_client_config.json"
198
- )
199
- defaults = client_config_file.open do |f|
200
- Google::Gax.construct_settings(
201
- "google.spanner.v1.Spanner",
202
- JSON.parse(f.read),
203
- client_config,
204
- Google::Gax::Grpc::STATUS_CODE_NAMES,
205
- timeout,
206
- page_descriptors: PAGE_DESCRIPTORS,
207
- errors: Google::Gax::Grpc::API_ERRORS,
208
- metadata: headers
209
- )
210
- end
211
-
212
- # Allow overriding the service path/port in subclasses.
213
- service_path = service_address || self.class::SERVICE_ADDRESS
214
- port = service_port || self.class::DEFAULT_SERVICE_PORT
215
- interceptors = self.class::GRPC_INTERCEPTORS
216
- @spanner_stub = Google::Gax::Grpc.create_stub(
217
- service_path,
218
- port,
219
- chan_creds: chan_creds,
220
- channel: channel,
221
- updater_proc: updater_proc,
222
- scopes: scopes,
223
- interceptors: interceptors,
224
- &Google::Spanner::V1::Spanner::Stub.method(:new)
225
- )
226
-
227
- @create_session = Google::Gax.create_api_call(
228
- @spanner_stub.method(:create_session),
229
- defaults["create_session"],
230
- exception_transformer: exception_transformer,
231
- params_extractor: proc do |request|
232
- {'database' => request.database}
233
- end
234
- )
235
- @batch_create_sessions = Google::Gax.create_api_call(
236
- @spanner_stub.method(:batch_create_sessions),
237
- defaults["batch_create_sessions"],
238
- exception_transformer: exception_transformer,
239
- params_extractor: proc do |request|
240
- {'database' => request.database}
241
- end
242
- )
243
- @get_session = Google::Gax.create_api_call(
244
- @spanner_stub.method(:get_session),
245
- defaults["get_session"],
246
- exception_transformer: exception_transformer,
247
- params_extractor: proc do |request|
248
- {'name' => request.name}
249
- end
250
- )
251
- @list_sessions = Google::Gax.create_api_call(
252
- @spanner_stub.method(:list_sessions),
253
- defaults["list_sessions"],
254
- exception_transformer: exception_transformer,
255
- params_extractor: proc do |request|
256
- {'database' => request.database}
257
- end
258
- )
259
- @delete_session = Google::Gax.create_api_call(
260
- @spanner_stub.method(:delete_session),
261
- defaults["delete_session"],
262
- exception_transformer: exception_transformer,
263
- params_extractor: proc do |request|
264
- {'name' => request.name}
265
- end
266
- )
267
- @execute_sql = Google::Gax.create_api_call(
268
- @spanner_stub.method(:execute_sql),
269
- defaults["execute_sql"],
270
- exception_transformer: exception_transformer,
271
- params_extractor: proc do |request|
272
- {'session' => request.session}
273
- end
274
- )
275
- @execute_streaming_sql = Google::Gax.create_api_call(
276
- @spanner_stub.method(:execute_streaming_sql),
277
- defaults["execute_streaming_sql"],
278
- exception_transformer: exception_transformer,
279
- params_extractor: proc do |request|
280
- {'session' => request.session}
281
- end
282
- )
283
- @execute_batch_dml = Google::Gax.create_api_call(
284
- @spanner_stub.method(:execute_batch_dml),
285
- defaults["execute_batch_dml"],
286
- exception_transformer: exception_transformer,
287
- params_extractor: proc do |request|
288
- {'session' => request.session}
289
- end
290
- )
291
- @read = Google::Gax.create_api_call(
292
- @spanner_stub.method(:read),
293
- defaults["read"],
294
- exception_transformer: exception_transformer,
295
- params_extractor: proc do |request|
296
- {'session' => request.session}
297
- end
298
- )
299
- @streaming_read = Google::Gax.create_api_call(
300
- @spanner_stub.method(:streaming_read),
301
- defaults["streaming_read"],
302
- exception_transformer: exception_transformer,
303
- params_extractor: proc do |request|
304
- {'session' => request.session}
305
- end
306
- )
307
- @begin_transaction = Google::Gax.create_api_call(
308
- @spanner_stub.method(:begin_transaction),
309
- defaults["begin_transaction"],
310
- exception_transformer: exception_transformer,
311
- params_extractor: proc do |request|
312
- {'session' => request.session}
313
- end
314
- )
315
- @commit = Google::Gax.create_api_call(
316
- @spanner_stub.method(:commit),
317
- defaults["commit"],
318
- exception_transformer: exception_transformer,
319
- params_extractor: proc do |request|
320
- {'session' => request.session}
321
- end
322
- )
323
- @rollback = Google::Gax.create_api_call(
324
- @spanner_stub.method(:rollback),
325
- defaults["rollback"],
326
- exception_transformer: exception_transformer,
327
- params_extractor: proc do |request|
328
- {'session' => request.session}
329
- end
330
- )
331
- @partition_query = Google::Gax.create_api_call(
332
- @spanner_stub.method(:partition_query),
333
- defaults["partition_query"],
334
- exception_transformer: exception_transformer,
335
- params_extractor: proc do |request|
336
- {'session' => request.session}
337
- end
338
- )
339
- @partition_read = Google::Gax.create_api_call(
340
- @spanner_stub.method(:partition_read),
341
- defaults["partition_read"],
342
- exception_transformer: exception_transformer,
343
- params_extractor: proc do |request|
344
- {'session' => request.session}
345
- end
346
- )
347
- end
348
-
349
- # Service calls
350
-
351
- # Creates a new session. A session can be used to perform
352
- # transactions that read and/or modify data in a Cloud Spanner database.
353
- # Sessions are meant to be reused for many consecutive
354
- # transactions.
355
- #
356
- # Sessions can only execute one transaction at a time. To execute
357
- # multiple concurrent read-write/write-only transactions, create
358
- # multiple sessions. Note that standalone reads and queries use a
359
- # transaction internally, and count toward the one transaction
360
- # limit.
361
- #
362
- # Active sessions use additional server resources, so it is a good idea to
363
- # delete idle and unneeded sessions.
364
- # Aside from explicit deletes, Cloud Spanner may delete sessions for which no
365
- # operations are sent for more than an hour. If a session is deleted,
366
- # requests to it return `NOT_FOUND`.
367
- #
368
- # Idle sessions can be kept alive by sending a trivial SQL query
369
- # periodically, e.g., `"SELECT 1"`.
370
- #
371
- # @param database [String]
372
- # Required. The database in which the new session is created.
373
- # @param session [Google::Spanner::V1::Session | Hash]
374
- # The session to create.
375
- # A hash of the same form as `Google::Spanner::V1::Session`
376
- # can also be provided.
377
- # @param options [Google::Gax::CallOptions]
378
- # Overrides the default settings for this call, e.g, timeout,
379
- # retries, etc.
380
- # @yield [result, operation] Access the result along with the RPC operation
381
- # @yieldparam result [Google::Spanner::V1::Session]
382
- # @yieldparam operation [GRPC::ActiveCall::Operation]
383
- # @return [Google::Spanner::V1::Session]
384
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
385
- # @example
386
- # require "google/cloud/spanner/v1"
387
- #
388
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
389
- # formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
390
- # response = spanner_client.create_session(formatted_database)
391
-
392
- def create_session \
393
- database,
394
- session: nil,
395
- options: nil,
396
- &block
397
- req = {
398
- database: database,
399
- session: session
400
- }.delete_if { |_, v| v.nil? }
401
- req = Google::Gax::to_proto(req, Google::Spanner::V1::CreateSessionRequest)
402
- @create_session.call(req, options, &block)
403
- end
404
-
405
- # Creates multiple new sessions.
406
- #
407
- # This API can be used to initialize a session cache on the clients.
408
- # See https://goo.gl/TgSFN2 for best practices on session cache management.
409
- #
410
- # @param database [String]
411
- # Required. The database in which the new sessions are created.
412
- # @param session_count [Integer]
413
- # Required. The number of sessions to be created in this batch call.
414
- # The API may return fewer than the requested number of sessions. If a
415
- # specific number of sessions are desired, the client can make additional
416
- # calls to BatchCreateSessions (adjusting
417
- # {Google::Spanner::V1::BatchCreateSessionsRequest#session_count session_count} as necessary).
418
- # @param session_template [Google::Spanner::V1::Session | Hash]
419
- # Parameters to be applied to each created session.
420
- # A hash of the same form as `Google::Spanner::V1::Session`
421
- # can also be provided.
422
- # @param options [Google::Gax::CallOptions]
423
- # Overrides the default settings for this call, e.g, timeout,
424
- # retries, etc.
425
- # @yield [result, operation] Access the result along with the RPC operation
426
- # @yieldparam result [Google::Spanner::V1::BatchCreateSessionsResponse]
427
- # @yieldparam operation [GRPC::ActiveCall::Operation]
428
- # @return [Google::Spanner::V1::BatchCreateSessionsResponse]
429
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
430
- # @example
431
- # require "google/cloud/spanner/v1"
432
- #
433
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
434
- # formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
435
- #
436
- # # TODO: Initialize `session_count`:
437
- # session_count = 0
438
- # response = spanner_client.batch_create_sessions(formatted_database, session_count)
439
-
440
- def batch_create_sessions \
441
- database,
442
- session_count,
443
- session_template: nil,
444
- options: nil,
445
- &block
446
- req = {
447
- database: database,
448
- session_count: session_count,
449
- session_template: session_template
450
- }.delete_if { |_, v| v.nil? }
451
- req = Google::Gax::to_proto(req, Google::Spanner::V1::BatchCreateSessionsRequest)
452
- @batch_create_sessions.call(req, options, &block)
453
- end
454
-
455
- # Gets a session. Returns `NOT_FOUND` if the session does not exist.
456
- # This is mainly useful for determining whether a session is still
457
- # alive.
458
- #
459
- # @param name [String]
460
- # Required. The name of the session to retrieve.
461
- # @param options [Google::Gax::CallOptions]
462
- # Overrides the default settings for this call, e.g, timeout,
463
- # retries, etc.
464
- # @yield [result, operation] Access the result along with the RPC operation
465
- # @yieldparam result [Google::Spanner::V1::Session]
466
- # @yieldparam operation [GRPC::ActiveCall::Operation]
467
- # @return [Google::Spanner::V1::Session]
468
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
469
- # @example
470
- # require "google/cloud/spanner/v1"
471
- #
472
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
473
- # formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
474
- # response = spanner_client.get_session(formatted_name)
475
-
476
- def get_session \
477
- name,
478
- options: nil,
479
- &block
480
- req = {
481
- name: name
482
- }.delete_if { |_, v| v.nil? }
483
- req = Google::Gax::to_proto(req, Google::Spanner::V1::GetSessionRequest)
484
- @get_session.call(req, options, &block)
485
- end
486
-
487
- # Lists all sessions in a given database.
488
- #
489
- # @param database [String]
490
- # Required. The database in which to list sessions.
491
- # @param page_size [Integer]
492
- # The maximum number of resources contained in the underlying API
493
- # response. If page streaming is performed per-resource, this
494
- # parameter does not affect the return value. If page streaming is
495
- # performed per-page, this determines the maximum number of
496
- # resources in a page.
497
- # @param filter [String]
498
- # An expression for filtering the results of the request. Filter rules are
499
- # case insensitive. The fields eligible for filtering are:
500
- #
501
- # * `labels.key` where key is the name of a label
502
- #
503
- # Some examples of using filters are:
504
- #
505
- # * `labels.env:*` --> The session has the label "env".
506
- # * `labels.env:dev` --> The session has the label "env" and the value of
507
- # the label contains the string "dev".
508
- # @param options [Google::Gax::CallOptions]
509
- # Overrides the default settings for this call, e.g, timeout,
510
- # retries, etc.
511
- # @yield [result, operation] Access the result along with the RPC operation
512
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>]
513
- # @yieldparam operation [GRPC::ActiveCall::Operation]
514
- # @return [Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>]
515
- # An enumerable of Google::Spanner::V1::Session instances.
516
- # See Google::Gax::PagedEnumerable documentation for other
517
- # operations such as per-page iteration or access to the response
518
- # object.
519
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
520
- # @example
521
- # require "google/cloud/spanner/v1"
522
- #
523
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
524
- # formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
525
- #
526
- # # Iterate over all results.
527
- # spanner_client.list_sessions(formatted_database).each do |element|
528
- # # Process element.
529
- # end
530
- #
531
- # # Or iterate over results one page at a time.
532
- # spanner_client.list_sessions(formatted_database).each_page do |page|
533
- # # Process each page at a time.
534
- # page.each do |element|
535
- # # Process element.
536
- # end
537
- # end
538
-
539
- def list_sessions \
540
- database,
541
- page_size: nil,
542
- filter: nil,
543
- options: nil,
544
- &block
545
- req = {
546
- database: database,
547
- page_size: page_size,
548
- filter: filter
549
- }.delete_if { |_, v| v.nil? }
550
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ListSessionsRequest)
551
- @list_sessions.call(req, options, &block)
552
- end
553
-
554
- # Ends a session, releasing server resources associated with it. This will
555
- # asynchronously trigger cancellation of any operations that are running with
556
- # this session.
557
- #
558
- # @param name [String]
559
- # Required. The name of the session to delete.
560
- # @param options [Google::Gax::CallOptions]
561
- # Overrides the default settings for this call, e.g, timeout,
562
- # retries, etc.
563
- # @yield [result, operation] Access the result along with the RPC operation
564
- # @yieldparam result []
565
- # @yieldparam operation [GRPC::ActiveCall::Operation]
566
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
567
- # @example
568
- # require "google/cloud/spanner/v1"
569
- #
570
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
571
- # formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
572
- # spanner_client.delete_session(formatted_name)
573
-
574
- def delete_session \
575
- name,
576
- options: nil,
577
- &block
578
- req = {
579
- name: name
580
- }.delete_if { |_, v| v.nil? }
581
- req = Google::Gax::to_proto(req, Google::Spanner::V1::DeleteSessionRequest)
582
- @delete_session.call(req, options, &block)
583
- nil
584
- end
585
-
586
- # Executes an SQL statement, returning all results in a single reply. This
587
- # method cannot be used to return a result set larger than 10 MiB;
588
- # if the query yields more data than that, the query fails with
589
- # a `FAILED_PRECONDITION` error.
590
- #
591
- # Operations inside read-write transactions might return `ABORTED`. If
592
- # this occurs, the application should restart the transaction from
593
- # the beginning. See {Google::Spanner::V1::Transaction Transaction} for more details.
594
- #
595
- # Larger result sets can be fetched in streaming fashion by calling
596
- # {Google::Spanner::V1::Spanner::ExecuteStreamingSql ExecuteStreamingSql} instead.
597
- #
598
- # @param session [String]
599
- # Required. The session in which the SQL query should be performed.
600
- # @param sql [String]
601
- # Required. The SQL string.
602
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
603
- # The transaction to use.
604
- #
605
- # For queries, if none is provided, the default is a temporary read-only
606
- # transaction with strong concurrency.
607
- #
608
- # Standard DML statements require a read-write transaction. To protect
609
- # against replays, single-use transactions are not supported. The caller
610
- # must either supply an existing transaction ID or begin a new transaction.
611
- #
612
- # Partitioned DML requires an existing Partitioned DML transaction ID.
613
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
614
- # can also be provided.
615
- # @param params [Google::Protobuf::Struct | Hash]
616
- # Parameter names and values that bind to placeholders in the SQL string.
617
- #
618
- # A parameter placeholder consists of the `@` character followed by the
619
- # parameter name (for example, `@firstName`). Parameter names can contain
620
- # letters, numbers, and underscores.
621
- #
622
- # Parameters can appear anywhere that a literal value is expected. The same
623
- # parameter name can be used more than once, for example:
624
- #
625
- # `"WHERE id > @msg_id AND id < @msg_id + 100"`
626
- #
627
- # It is an error to execute a SQL statement with unbound parameters.
628
- # A hash of the same form as `Google::Protobuf::Struct`
629
- # can also be provided.
630
- # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
631
- # It is not always possible for Cloud Spanner to infer the right SQL type
632
- # from a JSON value. For example, values of type `BYTES` and values
633
- # of type `STRING` both appear in {Google::Spanner::V1::ExecuteSqlRequest#params params} as JSON strings.
634
- #
635
- # In these cases, `param_types` can be used to specify the exact
636
- # SQL type for some or all of the SQL statement parameters. See the
637
- # definition of {Google::Spanner::V1::Type Type} for more information
638
- # about SQL types.
639
- # A hash of the same form as `Google::Spanner::V1::Type`
640
- # can also be provided.
641
- # @param resume_token [String]
642
- # If this request is resuming a previously interrupted SQL statement
643
- # execution, `resume_token` should be copied from the last
644
- # {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
645
- # enables the new SQL statement execution to resume where the last one left
646
- # off. The rest of the request parameters must exactly match the
647
- # request that yielded this token.
648
- # @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
649
- # Used to control the amount of debugging information returned in
650
- # {Google::Spanner::V1::ResultSetStats ResultSetStats}. If {Google::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {Google::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only
651
- # be set to {Google::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode::NORMAL}.
652
- # @param partition_token [String]
653
- # If present, results will be restricted to the specified partition
654
- # previously created using PartitionQuery(). There must be an exact
655
- # match for the values of fields common to this message and the
656
- # PartitionQueryRequest message used to create this partition_token.
657
- # @param seqno [Integer]
658
- # A per-transaction sequence number used to identify this request. This field
659
- # makes each request idempotent such that if the request is received multiple
660
- # times, at most one will succeed.
661
- #
662
- # The sequence number must be monotonically increasing within the
663
- # transaction. If a request arrives for the first time with an out-of-order
664
- # sequence number, the transaction may be aborted. Replays of previously
665
- # handled requests will yield the same response as the first execution.
666
- #
667
- # Required for DML statements. Ignored for queries.
668
- # @param query_options [Google::Spanner::V1::ExecuteSqlRequest::QueryOptions | Hash]
669
- # Query optimizer configuration to use for the given query.
670
- # A hash of the same form as `Google::Spanner::V1::ExecuteSqlRequest::QueryOptions`
671
- # can also be provided.
672
- # @param options [Google::Gax::CallOptions]
673
- # Overrides the default settings for this call, e.g, timeout,
674
- # retries, etc.
675
- # @yield [result, operation] Access the result along with the RPC operation
676
- # @yieldparam result [Google::Spanner::V1::ResultSet]
677
- # @yieldparam operation [GRPC::ActiveCall::Operation]
678
- # @return [Google::Spanner::V1::ResultSet]
679
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
680
- # @example
681
- # require "google/cloud/spanner/v1"
682
- #
683
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
684
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
685
- #
686
- # # TODO: Initialize `sql`:
687
- # sql = ''
688
- # response = spanner_client.execute_sql(formatted_session, sql)
689
-
690
- def execute_sql \
691
- session,
692
- sql,
693
- transaction: nil,
694
- params: nil,
695
- param_types: nil,
696
- resume_token: nil,
697
- query_mode: nil,
698
- partition_token: nil,
699
- seqno: nil,
700
- query_options: nil,
701
- options: nil,
702
- &block
703
- req = {
704
- session: session,
705
- sql: sql,
706
- transaction: transaction,
707
- params: params,
708
- param_types: param_types,
709
- resume_token: resume_token,
710
- query_mode: query_mode,
711
- partition_token: partition_token,
712
- seqno: seqno,
713
- query_options: query_options
714
- }.delete_if { |_, v| v.nil? }
715
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
716
- @execute_sql.call(req, options, &block)
717
- end
718
-
719
- # Like {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}, except returns the result
720
- # set as a stream. Unlike {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}, there
721
- # is no limit on the size of the returned result set. However, no
722
- # individual row in the result set can exceed 100 MiB, and no
723
- # column value can exceed 10 MiB.
724
- #
725
- # @param session [String]
726
- # Required. The session in which the SQL query should be performed.
727
- # @param sql [String]
728
- # Required. The SQL string.
729
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
730
- # The transaction to use.
731
- #
732
- # For queries, if none is provided, the default is a temporary read-only
733
- # transaction with strong concurrency.
734
- #
735
- # Standard DML statements require a read-write transaction. To protect
736
- # against replays, single-use transactions are not supported. The caller
737
- # must either supply an existing transaction ID or begin a new transaction.
738
- #
739
- # Partitioned DML requires an existing Partitioned DML transaction ID.
740
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
741
- # can also be provided.
742
- # @param params [Google::Protobuf::Struct | Hash]
743
- # Parameter names and values that bind to placeholders in the SQL string.
744
- #
745
- # A parameter placeholder consists of the `@` character followed by the
746
- # parameter name (for example, `@firstName`). Parameter names can contain
747
- # letters, numbers, and underscores.
748
- #
749
- # Parameters can appear anywhere that a literal value is expected. The same
750
- # parameter name can be used more than once, for example:
751
- #
752
- # `"WHERE id > @msg_id AND id < @msg_id + 100"`
753
- #
754
- # It is an error to execute a SQL statement with unbound parameters.
755
- # A hash of the same form as `Google::Protobuf::Struct`
756
- # can also be provided.
757
- # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
758
- # It is not always possible for Cloud Spanner to infer the right SQL type
759
- # from a JSON value. For example, values of type `BYTES` and values
760
- # of type `STRING` both appear in {Google::Spanner::V1::ExecuteSqlRequest#params params} as JSON strings.
761
- #
762
- # In these cases, `param_types` can be used to specify the exact
763
- # SQL type for some or all of the SQL statement parameters. See the
764
- # definition of {Google::Spanner::V1::Type Type} for more information
765
- # about SQL types.
766
- # A hash of the same form as `Google::Spanner::V1::Type`
767
- # can also be provided.
768
- # @param resume_token [String]
769
- # If this request is resuming a previously interrupted SQL statement
770
- # execution, `resume_token` should be copied from the last
771
- # {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
772
- # enables the new SQL statement execution to resume where the last one left
773
- # off. The rest of the request parameters must exactly match the
774
- # request that yielded this token.
775
- # @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
776
- # Used to control the amount of debugging information returned in
777
- # {Google::Spanner::V1::ResultSetStats ResultSetStats}. If {Google::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {Google::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only
778
- # be set to {Google::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode::NORMAL}.
779
- # @param partition_token [String]
780
- # If present, results will be restricted to the specified partition
781
- # previously created using PartitionQuery(). There must be an exact
782
- # match for the values of fields common to this message and the
783
- # PartitionQueryRequest message used to create this partition_token.
784
- # @param seqno [Integer]
785
- # A per-transaction sequence number used to identify this request. This field
786
- # makes each request idempotent such that if the request is received multiple
787
- # times, at most one will succeed.
788
- #
789
- # The sequence number must be monotonically increasing within the
790
- # transaction. If a request arrives for the first time with an out-of-order
791
- # sequence number, the transaction may be aborted. Replays of previously
792
- # handled requests will yield the same response as the first execution.
793
- #
794
- # Required for DML statements. Ignored for queries.
795
- # @param query_options [Google::Spanner::V1::ExecuteSqlRequest::QueryOptions | Hash]
796
- # Query optimizer configuration to use for the given query.
797
- # A hash of the same form as `Google::Spanner::V1::ExecuteSqlRequest::QueryOptions`
798
- # can also be provided.
799
- # @param options [Google::Gax::CallOptions]
800
- # Overrides the default settings for this call, e.g, timeout,
801
- # retries, etc.
802
- # @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
803
- # An enumerable of Google::Spanner::V1::PartialResultSet instances.
804
- #
805
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
806
- # @example
807
- # require "google/cloud/spanner/v1"
808
- #
809
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
810
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
811
- #
812
- # # TODO: Initialize `sql`:
813
- # sql = ''
814
- # spanner_client.execute_streaming_sql(formatted_session, sql).each do |element|
815
- # # Process element.
816
- # end
817
-
818
- def execute_streaming_sql \
819
- session,
820
- sql,
821
- transaction: nil,
822
- params: nil,
823
- param_types: nil,
824
- resume_token: nil,
825
- query_mode: nil,
826
- partition_token: nil,
827
- seqno: nil,
828
- query_options: nil,
829
- options: nil
830
- req = {
831
- session: session,
832
- sql: sql,
833
- transaction: transaction,
834
- params: params,
835
- param_types: param_types,
836
- resume_token: resume_token,
837
- query_mode: query_mode,
838
- partition_token: partition_token,
839
- seqno: seqno,
840
- query_options: query_options
841
- }.delete_if { |_, v| v.nil? }
842
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
843
- @execute_streaming_sql.call(req, options)
844
- end
845
-
846
- # Executes a batch of SQL DML statements. This method allows many statements
847
- # to be run with lower latency than submitting them sequentially with
848
- # {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}.
849
- #
850
- # Statements are executed in sequential order. A request can succeed even if
851
- # a statement fails. The {Google::Spanner::V1::ExecuteBatchDmlResponse#status ExecuteBatchDmlResponse#status} field in the
852
- # response provides information about the statement that failed. Clients must
853
- # inspect this field to determine whether an error occurred.
854
- #
855
- # Execution stops after the first failed statement; the remaining statements
856
- # are not executed.
857
- #
858
- # @param session [String]
859
- # Required. The session in which the DML statements should be performed.
860
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
861
- # Required. The transaction to use. Must be a read-write transaction.
862
- #
863
- # To protect against replays, single-use transactions are not supported. The
864
- # caller must either supply an existing transaction ID or begin a new
865
- # transaction.
866
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
867
- # can also be provided.
868
- # @param statements [Array<Google::Spanner::V1::ExecuteBatchDmlRequest::Statement | Hash>]
869
- # Required. The list of statements to execute in this batch. Statements are executed
870
- # serially, such that the effects of statement `i` are visible to statement
871
- # `i+1`. Each statement must be a DML statement. Execution stops at the
872
- # first failed statement; the remaining statements are not executed.
873
- #
874
- # Callers must provide at least one statement.
875
- # A hash of the same form as `Google::Spanner::V1::ExecuteBatchDmlRequest::Statement`
876
- # can also be provided.
877
- # @param seqno [Integer]
878
- # Required. A per-transaction sequence number used to identify this request. This field
879
- # makes each request idempotent such that if the request is received multiple
880
- # times, at most one will succeed.
881
- #
882
- # The sequence number must be monotonically increasing within the
883
- # transaction. If a request arrives for the first time with an out-of-order
884
- # sequence number, the transaction may be aborted. Replays of previously
885
- # handled requests will yield the same response as the first execution.
886
- # @param options [Google::Gax::CallOptions]
887
- # Overrides the default settings for this call, e.g, timeout,
888
- # retries, etc.
889
- # @yield [result, operation] Access the result along with the RPC operation
890
- # @yieldparam result [Google::Spanner::V1::ExecuteBatchDmlResponse]
891
- # @yieldparam operation [GRPC::ActiveCall::Operation]
892
- # @return [Google::Spanner::V1::ExecuteBatchDmlResponse]
893
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
894
- # @example
895
- # require "google/cloud/spanner/v1"
896
- #
897
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
898
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
899
- #
900
- # # TODO: Initialize `transaction`:
901
- # transaction = {}
902
- #
903
- # # TODO: Initialize `statements`:
904
- # statements = []
905
- #
906
- # # TODO: Initialize `seqno`:
907
- # seqno = 0
908
- # response = spanner_client.execute_batch_dml(formatted_session, transaction, statements, seqno)
909
-
910
- def execute_batch_dml \
911
- session,
912
- transaction,
913
- statements,
914
- seqno,
915
- options: nil,
916
- &block
917
- req = {
918
- session: session,
919
- transaction: transaction,
920
- statements: statements,
921
- seqno: seqno
922
- }.delete_if { |_, v| v.nil? }
923
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteBatchDmlRequest)
924
- @execute_batch_dml.call(req, options, &block)
925
- end
926
-
927
- # Reads rows from the database using key lookups and scans, as a
928
- # simple key/value style alternative to
929
- # {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}. This method cannot be used to
930
- # return a result set larger than 10 MiB; if the read matches more
931
- # data than that, the read fails with a `FAILED_PRECONDITION`
932
- # error.
933
- #
934
- # Reads inside read-write transactions might return `ABORTED`. If
935
- # this occurs, the application should restart the transaction from
936
- # the beginning. See {Google::Spanner::V1::Transaction Transaction} for more details.
937
- #
938
- # Larger result sets can be yielded in streaming fashion by calling
939
- # {Google::Spanner::V1::Spanner::StreamingRead StreamingRead} instead.
940
- #
941
- # @param session [String]
942
- # Required. The session in which the read should be performed.
943
- # @param table [String]
944
- # Required. The name of the table in the database to be read.
945
- # @param columns [Array<String>]
946
- # Required. The columns of {Google::Spanner::V1::ReadRequest#table table} to be returned for each row matching
947
- # this request.
948
- # @param key_set [Google::Spanner::V1::KeySet | Hash]
949
- # Required. `key_set` identifies the rows to be yielded. `key_set` names the
950
- # primary keys of the rows in {Google::Spanner::V1::ReadRequest#table table} to be yielded, unless {Google::Spanner::V1::ReadRequest#index index}
951
- # is present. If {Google::Spanner::V1::ReadRequest#index index} is present, then {Google::Spanner::V1::ReadRequest#key_set key_set} instead names
952
- # index keys in {Google::Spanner::V1::ReadRequest#index index}.
953
- #
954
- # If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded
955
- # in table primary key order (if {Google::Spanner::V1::ReadRequest#index index} is empty) or index key order
956
- # (if {Google::Spanner::V1::ReadRequest#index index} is non-empty). If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is not
957
- # empty, rows will be yielded in an unspecified order.
958
- #
959
- # It is not an error for the `key_set` to name rows that do not
960
- # exist in the database. Read yields nothing for nonexistent rows.
961
- # A hash of the same form as `Google::Spanner::V1::KeySet`
962
- # can also be provided.
963
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
964
- # The transaction to use. If none is provided, the default is a
965
- # temporary read-only transaction with strong concurrency.
966
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
967
- # can also be provided.
968
- # @param index [String]
969
- # If non-empty, the name of an index on {Google::Spanner::V1::ReadRequest#table table}. This index is
970
- # used instead of the table primary key when interpreting {Google::Spanner::V1::ReadRequest#key_set key_set}
971
- # and sorting result rows. See {Google::Spanner::V1::ReadRequest#key_set key_set} for further information.
972
- # @param limit [Integer]
973
- # If greater than zero, only the first `limit` rows are yielded. If `limit`
974
- # is zero, the default is no limit. A limit cannot be specified if
975
- # `partition_token` is set.
976
- # @param resume_token [String]
977
- # If this request is resuming a previously interrupted read,
978
- # `resume_token` should be copied from the last
979
- # {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
980
- # enables the new read to resume where the last read left off. The
981
- # rest of the request parameters must exactly match the request
982
- # that yielded this token.
983
- # @param partition_token [String]
984
- # If present, results will be restricted to the specified partition
985
- # previously created using PartitionRead(). There must be an exact
986
- # match for the values of fields common to this message and the
987
- # PartitionReadRequest message used to create this partition_token.
988
- # @param options [Google::Gax::CallOptions]
989
- # Overrides the default settings for this call, e.g, timeout,
990
- # retries, etc.
991
- # @yield [result, operation] Access the result along with the RPC operation
992
- # @yieldparam result [Google::Spanner::V1::ResultSet]
993
- # @yieldparam operation [GRPC::ActiveCall::Operation]
994
- # @return [Google::Spanner::V1::ResultSet]
995
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
996
- # @example
997
- # require "google/cloud/spanner/v1"
998
- #
999
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1000
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1001
- #
1002
- # # TODO: Initialize `table`:
1003
- # table = ''
1004
- #
1005
- # # TODO: Initialize `columns`:
1006
- # columns = []
1007
- #
1008
- # # TODO: Initialize `key_set`:
1009
- # key_set = {}
1010
- # response = spanner_client.read(formatted_session, table, columns, key_set)
1011
-
1012
- def read \
1013
- session,
1014
- table,
1015
- columns,
1016
- key_set,
1017
- transaction: nil,
1018
- index: nil,
1019
- limit: nil,
1020
- resume_token: nil,
1021
- partition_token: nil,
1022
- options: nil,
1023
- &block
1024
- req = {
1025
- session: session,
1026
- table: table,
1027
- columns: columns,
1028
- key_set: key_set,
1029
- transaction: transaction,
1030
- index: index,
1031
- limit: limit,
1032
- resume_token: resume_token,
1033
- partition_token: partition_token
1034
- }.delete_if { |_, v| v.nil? }
1035
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
1036
- @read.call(req, options, &block)
1037
- end
1038
-
1039
- # Like {Google::Spanner::V1::Spanner::Read Read}, except returns the result set as a
1040
- # stream. Unlike {Google::Spanner::V1::Spanner::Read Read}, there is no limit on the
1041
- # size of the returned result set. However, no individual row in
1042
- # the result set can exceed 100 MiB, and no column value can exceed
1043
- # 10 MiB.
1044
- #
1045
- # @param session [String]
1046
- # Required. The session in which the read should be performed.
1047
- # @param table [String]
1048
- # Required. The name of the table in the database to be read.
1049
- # @param columns [Array<String>]
1050
- # Required. The columns of {Google::Spanner::V1::ReadRequest#table table} to be returned for each row matching
1051
- # this request.
1052
- # @param key_set [Google::Spanner::V1::KeySet | Hash]
1053
- # Required. `key_set` identifies the rows to be yielded. `key_set` names the
1054
- # primary keys of the rows in {Google::Spanner::V1::ReadRequest#table table} to be yielded, unless {Google::Spanner::V1::ReadRequest#index index}
1055
- # is present. If {Google::Spanner::V1::ReadRequest#index index} is present, then {Google::Spanner::V1::ReadRequest#key_set key_set} instead names
1056
- # index keys in {Google::Spanner::V1::ReadRequest#index index}.
1057
- #
1058
- # If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded
1059
- # in table primary key order (if {Google::Spanner::V1::ReadRequest#index index} is empty) or index key order
1060
- # (if {Google::Spanner::V1::ReadRequest#index index} is non-empty). If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is not
1061
- # empty, rows will be yielded in an unspecified order.
1062
- #
1063
- # It is not an error for the `key_set` to name rows that do not
1064
- # exist in the database. Read yields nothing for nonexistent rows.
1065
- # A hash of the same form as `Google::Spanner::V1::KeySet`
1066
- # can also be provided.
1067
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
1068
- # The transaction to use. If none is provided, the default is a
1069
- # temporary read-only transaction with strong concurrency.
1070
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
1071
- # can also be provided.
1072
- # @param index [String]
1073
- # If non-empty, the name of an index on {Google::Spanner::V1::ReadRequest#table table}. This index is
1074
- # used instead of the table primary key when interpreting {Google::Spanner::V1::ReadRequest#key_set key_set}
1075
- # and sorting result rows. See {Google::Spanner::V1::ReadRequest#key_set key_set} for further information.
1076
- # @param limit [Integer]
1077
- # If greater than zero, only the first `limit` rows are yielded. If `limit`
1078
- # is zero, the default is no limit. A limit cannot be specified if
1079
- # `partition_token` is set.
1080
- # @param resume_token [String]
1081
- # If this request is resuming a previously interrupted read,
1082
- # `resume_token` should be copied from the last
1083
- # {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
1084
- # enables the new read to resume where the last read left off. The
1085
- # rest of the request parameters must exactly match the request
1086
- # that yielded this token.
1087
- # @param partition_token [String]
1088
- # If present, results will be restricted to the specified partition
1089
- # previously created using PartitionRead(). There must be an exact
1090
- # match for the values of fields common to this message and the
1091
- # PartitionReadRequest message used to create this partition_token.
1092
- # @param options [Google::Gax::CallOptions]
1093
- # Overrides the default settings for this call, e.g, timeout,
1094
- # retries, etc.
1095
- # @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
1096
- # An enumerable of Google::Spanner::V1::PartialResultSet instances.
1097
- #
1098
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1099
- # @example
1100
- # require "google/cloud/spanner/v1"
1101
- #
1102
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1103
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1104
- #
1105
- # # TODO: Initialize `table`:
1106
- # table = ''
1107
- #
1108
- # # TODO: Initialize `columns`:
1109
- # columns = []
1110
- #
1111
- # # TODO: Initialize `key_set`:
1112
- # key_set = {}
1113
- # spanner_client.streaming_read(formatted_session, table, columns, key_set).each do |element|
1114
- # # Process element.
1115
- # end
1116
-
1117
- def streaming_read \
1118
- session,
1119
- table,
1120
- columns,
1121
- key_set,
1122
- transaction: nil,
1123
- index: nil,
1124
- limit: nil,
1125
- resume_token: nil,
1126
- partition_token: nil,
1127
- options: nil
1128
- req = {
1129
- session: session,
1130
- table: table,
1131
- columns: columns,
1132
- key_set: key_set,
1133
- transaction: transaction,
1134
- index: index,
1135
- limit: limit,
1136
- resume_token: resume_token,
1137
- partition_token: partition_token
1138
- }.delete_if { |_, v| v.nil? }
1139
- req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
1140
- @streaming_read.call(req, options)
1141
- end
1142
-
1143
- # Begins a new transaction. This step can often be skipped:
1144
- # {Google::Spanner::V1::Spanner::Read Read}, {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql} and
1145
- # {Google::Spanner::V1::Spanner::Commit Commit} can begin a new transaction as a
1146
- # side-effect.
1147
- #
1148
- # @param session [String]
1149
- # Required. The session in which the transaction runs.
1150
- # @param options_ [Google::Spanner::V1::TransactionOptions | Hash]
1151
- # Required. Options for the new transaction.
1152
- # A hash of the same form as `Google::Spanner::V1::TransactionOptions`
1153
- # can also be provided.
1154
- # @param options [Google::Gax::CallOptions]
1155
- # Overrides the default settings for this call, e.g, timeout,
1156
- # retries, etc.
1157
- # @yield [result, operation] Access the result along with the RPC operation
1158
- # @yieldparam result [Google::Spanner::V1::Transaction]
1159
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1160
- # @return [Google::Spanner::V1::Transaction]
1161
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1162
- # @example
1163
- # require "google/cloud/spanner/v1"
1164
- #
1165
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1166
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1167
- #
1168
- # # TODO: Initialize `options_`:
1169
- # options_ = {}
1170
- # response = spanner_client.begin_transaction(formatted_session, options_)
1171
-
1172
- def begin_transaction \
1173
- session,
1174
- options_,
1175
- options: nil,
1176
- &block
1177
- req = {
1178
- session: session,
1179
- options: options_
1180
- }.delete_if { |_, v| v.nil? }
1181
- req = Google::Gax::to_proto(req, Google::Spanner::V1::BeginTransactionRequest)
1182
- @begin_transaction.call(req, options, &block)
1183
- end
1184
-
1185
- # Commits a transaction. The request includes the mutations to be
1186
- # applied to rows in the database.
1187
- #
1188
- # `Commit` might return an `ABORTED` error. This can occur at any time;
1189
- # commonly, the cause is conflicts with concurrent
1190
- # transactions. However, it can also happen for a variety of other
1191
- # reasons. If `Commit` returns `ABORTED`, the caller should re-attempt
1192
- # the transaction from the beginning, re-using the same session.
1193
- #
1194
- # @param session [String]
1195
- # Required. The session in which the transaction to be committed is running.
1196
- # @param mutations [Array<Google::Spanner::V1::Mutation | Hash>]
1197
- # The mutations to be executed when this transaction commits. All
1198
- # mutations are applied atomically, in the order they appear in
1199
- # this list.
1200
- # A hash of the same form as `Google::Spanner::V1::Mutation`
1201
- # can also be provided.
1202
- # @param transaction_id [String]
1203
- # Commit a previously-started transaction.
1204
- # @param single_use_transaction [Google::Spanner::V1::TransactionOptions | Hash]
1205
- # Execute mutations in a temporary transaction. Note that unlike
1206
- # commit of a previously-started transaction, commit with a
1207
- # temporary transaction is non-idempotent. That is, if the
1208
- # `CommitRequest` is sent to Cloud Spanner more than once (for
1209
- # instance, due to retries in the application, or in the
1210
- # transport library), it is possible that the mutations are
1211
- # executed more than once. If this is undesirable, use
1212
- # {Google::Spanner::V1::Spanner::BeginTransaction BeginTransaction} and
1213
- # {Google::Spanner::V1::Spanner::Commit Commit} instead.
1214
- # A hash of the same form as `Google::Spanner::V1::TransactionOptions`
1215
- # can also be provided.
1216
- # @param options [Google::Gax::CallOptions]
1217
- # Overrides the default settings for this call, e.g, timeout,
1218
- # retries, etc.
1219
- # @yield [result, operation] Access the result along with the RPC operation
1220
- # @yieldparam result [Google::Spanner::V1::CommitResponse]
1221
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1222
- # @return [Google::Spanner::V1::CommitResponse]
1223
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1224
- # @example
1225
- # require "google/cloud/spanner/v1"
1226
- #
1227
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1228
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1229
- #
1230
- # # TODO: Initialize `mutations`:
1231
- # mutations = []
1232
- # response = spanner_client.commit(formatted_session, mutations)
1233
-
1234
- def commit \
1235
- session,
1236
- mutations,
1237
- transaction_id: nil,
1238
- single_use_transaction: nil,
1239
- options: nil,
1240
- &block
1241
- req = {
1242
- session: session,
1243
- mutations: mutations,
1244
- transaction_id: transaction_id,
1245
- single_use_transaction: single_use_transaction
1246
- }.delete_if { |_, v| v.nil? }
1247
- req = Google::Gax::to_proto(req, Google::Spanner::V1::CommitRequest)
1248
- @commit.call(req, options, &block)
1249
- end
1250
-
1251
- # Rolls back a transaction, releasing any locks it holds. It is a good
1252
- # idea to call this for any transaction that includes one or more
1253
- # {Google::Spanner::V1::Spanner::Read Read} or {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql} requests and
1254
- # ultimately decides not to commit.
1255
- #
1256
- # `Rollback` returns `OK` if it successfully aborts the transaction, the
1257
- # transaction was already aborted, or the transaction is not
1258
- # found. `Rollback` never returns `ABORTED`.
1259
- #
1260
- # @param session [String]
1261
- # Required. The session in which the transaction to roll back is running.
1262
- # @param transaction_id [String]
1263
- # Required. The transaction to roll back.
1264
- # @param options [Google::Gax::CallOptions]
1265
- # Overrides the default settings for this call, e.g, timeout,
1266
- # retries, etc.
1267
- # @yield [result, operation] Access the result along with the RPC operation
1268
- # @yieldparam result []
1269
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1270
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1271
- # @example
1272
- # require "google/cloud/spanner/v1"
1273
- #
1274
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1275
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1276
- #
1277
- # # TODO: Initialize `transaction_id`:
1278
- # transaction_id = ''
1279
- # spanner_client.rollback(formatted_session, transaction_id)
1280
-
1281
- def rollback \
1282
- session,
1283
- transaction_id,
1284
- options: nil,
1285
- &block
1286
- req = {
1287
- session: session,
1288
- transaction_id: transaction_id
1289
- }.delete_if { |_, v| v.nil? }
1290
- req = Google::Gax::to_proto(req, Google::Spanner::V1::RollbackRequest)
1291
- @rollback.call(req, options, &block)
1292
- nil
1293
- end
1294
-
1295
- # Creates a set of partition tokens that can be used to execute a query
1296
- # operation in parallel. Each of the returned partition tokens can be used
1297
- # by {Google::Spanner::V1::Spanner::ExecuteStreamingSql ExecuteStreamingSql} to specify a subset
1298
- # of the query result to read. The same session and read-only transaction
1299
- # must be used by the PartitionQueryRequest used to create the
1300
- # partition tokens and the ExecuteSqlRequests that use the partition tokens.
1301
- #
1302
- # Partition tokens become invalid when the session used to create them
1303
- # is deleted, is idle for too long, begins a new transaction, or becomes too
1304
- # old. When any of these happen, it is not possible to resume the query, and
1305
- # the whole operation must be restarted from the beginning.
1306
- #
1307
- # @param session [String]
1308
- # Required. The session used to create the partitions.
1309
- # @param sql [String]
1310
- # Required. The query request to generate partitions for. The request will fail if
1311
- # the query is not root partitionable. The query plan of a root
1312
- # partitionable query has a single distributed union operator. A distributed
1313
- # union operator conceptually divides one or more tables into multiple
1314
- # splits, remotely evaluates a subquery independently on each split, and
1315
- # then unions all results.
1316
- #
1317
- # This must not contain DML commands, such as INSERT, UPDATE, or
1318
- # DELETE. Use {Google::Spanner::V1::Spanner::ExecuteStreamingSql ExecuteStreamingSql} with a
1319
- # PartitionedDml transaction for large, partition-friendly DML operations.
1320
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
1321
- # Read only snapshot transactions are supported, read/write and single use
1322
- # transactions are not.
1323
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
1324
- # can also be provided.
1325
- # @param params [Google::Protobuf::Struct | Hash]
1326
- # Parameter names and values that bind to placeholders in the SQL string.
1327
- #
1328
- # A parameter placeholder consists of the `@` character followed by the
1329
- # parameter name (for example, `@firstName`). Parameter names can contain
1330
- # letters, numbers, and underscores.
1331
- #
1332
- # Parameters can appear anywhere that a literal value is expected. The same
1333
- # parameter name can be used more than once, for example:
1334
- #
1335
- # `"WHERE id > @msg_id AND id < @msg_id + 100"`
1336
- #
1337
- # It is an error to execute a SQL statement with unbound parameters.
1338
- # A hash of the same form as `Google::Protobuf::Struct`
1339
- # can also be provided.
1340
- # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
1341
- # It is not always possible for Cloud Spanner to infer the right SQL type
1342
- # from a JSON value. For example, values of type `BYTES` and values
1343
- # of type `STRING` both appear in {Google::Spanner::V1::PartitionQueryRequest#params params} as JSON strings.
1344
- #
1345
- # In these cases, `param_types` can be used to specify the exact
1346
- # SQL type for some or all of the SQL query parameters. See the
1347
- # definition of {Google::Spanner::V1::Type Type} for more information
1348
- # about SQL types.
1349
- # A hash of the same form as `Google::Spanner::V1::Type`
1350
- # can also be provided.
1351
- # @param partition_options [Google::Spanner::V1::PartitionOptions | Hash]
1352
- # Additional options that affect how many partitions are created.
1353
- # A hash of the same form as `Google::Spanner::V1::PartitionOptions`
1354
- # can also be provided.
1355
- # @param options [Google::Gax::CallOptions]
1356
- # Overrides the default settings for this call, e.g, timeout,
1357
- # retries, etc.
1358
- # @yield [result, operation] Access the result along with the RPC operation
1359
- # @yieldparam result [Google::Spanner::V1::PartitionResponse]
1360
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1361
- # @return [Google::Spanner::V1::PartitionResponse]
1362
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1363
- # @example
1364
- # require "google/cloud/spanner/v1"
1365
- #
1366
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1367
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1368
- #
1369
- # # TODO: Initialize `sql`:
1370
- # sql = ''
1371
- # response = spanner_client.partition_query(formatted_session, sql)
1372
-
1373
- def partition_query \
1374
- session,
1375
- sql,
1376
- transaction: nil,
1377
- params: nil,
1378
- param_types: nil,
1379
- partition_options: nil,
1380
- options: nil,
1381
- &block
1382
- req = {
1383
- session: session,
1384
- sql: sql,
1385
- transaction: transaction,
1386
- params: params,
1387
- param_types: param_types,
1388
- partition_options: partition_options
1389
- }.delete_if { |_, v| v.nil? }
1390
- req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionQueryRequest)
1391
- @partition_query.call(req, options, &block)
1392
- end
1393
-
1394
- # Creates a set of partition tokens that can be used to execute a read
1395
- # operation in parallel. Each of the returned partition tokens can be used
1396
- # by {Google::Spanner::V1::Spanner::StreamingRead StreamingRead} to specify a subset of the read
1397
- # result to read. The same session and read-only transaction must be used by
1398
- # the PartitionReadRequest used to create the partition tokens and the
1399
- # ReadRequests that use the partition tokens. There are no ordering
1400
- # guarantees on rows returned among the returned partition tokens, or even
1401
- # within each individual StreamingRead call issued with a partition_token.
1402
- #
1403
- # Partition tokens become invalid when the session used to create them
1404
- # is deleted, is idle for too long, begins a new transaction, or becomes too
1405
- # old. When any of these happen, it is not possible to resume the read, and
1406
- # the whole operation must be restarted from the beginning.
1407
- #
1408
- # @param session [String]
1409
- # Required. The session used to create the partitions.
1410
- # @param table [String]
1411
- # Required. The name of the table in the database to be read.
1412
- # @param key_set [Google::Spanner::V1::KeySet | Hash]
1413
- # Required. `key_set` identifies the rows to be yielded. `key_set` names the
1414
- # primary keys of the rows in {Google::Spanner::V1::PartitionReadRequest#table table} to be yielded, unless {Google::Spanner::V1::PartitionReadRequest#index index}
1415
- # is present. If {Google::Spanner::V1::PartitionReadRequest#index index} is present, then {Google::Spanner::V1::PartitionReadRequest#key_set key_set} instead names
1416
- # index keys in {Google::Spanner::V1::PartitionReadRequest#index index}.
1417
- #
1418
- # It is not an error for the `key_set` to name rows that do not
1419
- # exist in the database. Read yields nothing for nonexistent rows.
1420
- # A hash of the same form as `Google::Spanner::V1::KeySet`
1421
- # can also be provided.
1422
- # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
1423
- # Read only snapshot transactions are supported, read/write and single use
1424
- # transactions are not.
1425
- # A hash of the same form as `Google::Spanner::V1::TransactionSelector`
1426
- # can also be provided.
1427
- # @param index [String]
1428
- # If non-empty, the name of an index on {Google::Spanner::V1::PartitionReadRequest#table table}. This index is
1429
- # used instead of the table primary key when interpreting {Google::Spanner::V1::PartitionReadRequest#key_set key_set}
1430
- # and sorting result rows. See {Google::Spanner::V1::PartitionReadRequest#key_set key_set} for further information.
1431
- # @param columns [Array<String>]
1432
- # The columns of {Google::Spanner::V1::PartitionReadRequest#table table} to be returned for each row matching
1433
- # this request.
1434
- # @param partition_options [Google::Spanner::V1::PartitionOptions | Hash]
1435
- # Additional options that affect how many partitions are created.
1436
- # A hash of the same form as `Google::Spanner::V1::PartitionOptions`
1437
- # can also be provided.
1438
- # @param options [Google::Gax::CallOptions]
1439
- # Overrides the default settings for this call, e.g, timeout,
1440
- # retries, etc.
1441
- # @yield [result, operation] Access the result along with the RPC operation
1442
- # @yieldparam result [Google::Spanner::V1::PartitionResponse]
1443
- # @yieldparam operation [GRPC::ActiveCall::Operation]
1444
- # @return [Google::Spanner::V1::PartitionResponse]
1445
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
1446
- # @example
1447
- # require "google/cloud/spanner/v1"
1448
- #
1449
- # spanner_client = Google::Cloud::Spanner::V1::SpannerClient.new
1450
- # formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
1451
- #
1452
- # # TODO: Initialize `table`:
1453
- # table = ''
1454
- #
1455
- # # TODO: Initialize `key_set`:
1456
- # key_set = {}
1457
- # response = spanner_client.partition_read(formatted_session, table, key_set)
1458
-
1459
- def partition_read \
1460
- session,
1461
- table,
1462
- key_set,
1463
- transaction: nil,
1464
- index: nil,
1465
- columns: nil,
1466
- partition_options: nil,
1467
- options: nil,
1468
- &block
1469
- req = {
1470
- session: session,
1471
- table: table,
1472
- key_set: key_set,
1473
- transaction: transaction,
1474
- index: index,
1475
- columns: columns,
1476
- partition_options: partition_options
1477
- }.delete_if { |_, v| v.nil? }
1478
- req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionReadRequest)
1479
- @partition_read.call(req, options, &block)
1480
- end
1481
- end
1482
- end
1483
- end
1484
- end
1485
- end