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