google-cloud-spanner 2.21.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/lib/google/cloud/spanner/admin/database.rb +9 -11
  4. data/lib/google/cloud/spanner/admin/instance.rb +9 -11
  5. data/lib/google/cloud/spanner/backup/job/list.rb +1 -2
  6. data/lib/google/cloud/spanner/backup/job.rb +1 -2
  7. data/lib/google/cloud/spanner/backup/list.rb +1 -3
  8. data/lib/google/cloud/spanner/backup/restore/job.rb +1 -2
  9. data/lib/google/cloud/spanner/batch_client.rb +3 -2
  10. data/lib/google/cloud/spanner/batch_snapshot.rb +14 -9
  11. data/lib/google/cloud/spanner/batch_update.rb +3 -2
  12. data/lib/google/cloud/spanner/batch_write.rb +72 -0
  13. data/lib/google/cloud/spanner/batch_write_results.rb +142 -0
  14. data/lib/google/cloud/spanner/client.rb +245 -28
  15. data/lib/google/cloud/spanner/commit.rb +4 -0
  16. data/lib/google/cloud/spanner/convert.rb +2 -2
  17. data/lib/google/cloud/spanner/database/job/list.rb +1 -2
  18. data/lib/google/cloud/spanner/database/job.rb +2 -4
  19. data/lib/google/cloud/spanner/database/list.rb +2 -3
  20. data/lib/google/cloud/spanner/fields.rb +2 -1
  21. data/lib/google/cloud/spanner/instance/config/list.rb +2 -3
  22. data/lib/google/cloud/spanner/instance/job.rb +2 -3
  23. data/lib/google/cloud/spanner/instance/list.rb +2 -3
  24. data/lib/google/cloud/spanner/lar_headers.rb +4 -0
  25. data/lib/google/cloud/spanner/mutation_group.rb +288 -0
  26. data/lib/google/cloud/spanner/project.rb +9 -27
  27. data/lib/google/cloud/spanner/results.rb +2 -2
  28. data/lib/google/cloud/spanner/service.rb +32 -6
  29. data/lib/google/cloud/spanner/session.rb +167 -17
  30. data/lib/google/cloud/spanner/snapshot.rb +5 -2
  31. data/lib/google/cloud/spanner/transaction.rb +18 -3
  32. data/lib/google/cloud/spanner/version.rb +1 -1
  33. data/lib/google-cloud-spanner.rb +6 -3
  34. metadata +26 -191
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b4512d4772029fbc6c9ea89195d788ddd6cb0ecb06568764ada121e37b0afe5
4
- data.tar.gz: acd1c491242e6c656eb8cff2ad1ec09749e4895a3badb828d58eb7db98a65760
3
+ metadata.gz: 32575eadb5e1598ba5b49fc7dc27cc70e2d6f370c52aa42cdad5e9fa3059cf41
4
+ data.tar.gz: b5bec492eed277a46d4f4031e7f9ef9ef40472df57f747a1ea88266b397fafca
5
5
  SHA512:
6
- metadata.gz: cd930852601a8ec5fb036662ad7fae03a99d5a0e9e7e566d689113d60bb62f90af4ba35da1856bdcee6a1ba147ad6f6e5a4701c37c0b59c0d371e43a25b93ec7
7
- data.tar.gz: 7cabba248fda38947ebaf27f45b6bacf25ff14e770fcfabe76d6b66dc57c6e572aa82eb8b8bb1d4ed068036805e8f5cff56b5bc8cc553bd4921f75ac1e4a8b0d
6
+ metadata.gz: c826d09f5ff0abe190d1f51a942f120ee67b032b508edba22de82b42b079e8c833ed7e044570c5f1138c0d4e85aeb9fb3d93d571ce5db8deca898f0d456cf267
7
+ data.tar.gz: e06690d05125c1af27c8fb2e5f29f0b75b1a2d9eecd31fa6865e80fc0592caba84bc2cdb864ff25bd18a8b333019fabb52f13647b42521acf0c0706049bbc0f5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Release History
2
2
 
3
+ ### 2.23.0 (2024-06-27)
4
+
5
+ #### Features
6
+
7
+ * Support BatchWrite API ([#99](https://github.com/googleapis/ruby-spanner/issues/99))
8
+ * Support exclude_txn_from_change_streams ([#108](https://github.com/googleapis/ruby-spanner/issues/108))
9
+ #### Bug Fixes
10
+
11
+ * Resolve BigDecimal warning in Ruby 3.4 ([#103](https://github.com/googleapis/ruby-spanner/issues/103))
12
+ #### Documentation
13
+
14
+ * Update documentation regarding root partitionability ([#101](https://github.com/googleapis/ruby-spanner/issues/101))
15
+
16
+ ### 2.22.0 (2024-04-01)
17
+
18
+ #### Features
19
+
20
+ * Support FLOAT32 datatype ([#94](https://github.com/googleapis/ruby-spanner/issues/94))
21
+ * Update minimum Ruby version to 2.7 ([#89](https://github.com/googleapis/ruby-spanner/issues/89))
22
+ #### Bug Fixes
23
+
24
+ * Use https in Gemfile to avoid security vulnerability ([#95](https://github.com/googleapis/ruby-spanner/issues/95))
25
+
3
26
  ### 2.21.0 (2024-02-07)
4
27
 
5
28
  #### Features
@@ -20,6 +20,8 @@ module Google
20
20
  module Spanner
21
21
  module Admin
22
22
  module Database
23
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
24
+
23
25
  ##
24
26
  # Create a new client object for a DatabaseAdmin.
25
27
  #
@@ -81,7 +83,6 @@ module Google
81
83
  #
82
84
  # @return [Admin::Database::V1::DatabaseAdmin::Client] A client object of version V1.
83
85
  #
84
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
85
86
  def self.database_admin project_id: nil,
86
87
  credentials: nil,
87
88
  scope: nil,
@@ -135,16 +136,6 @@ module Google
135
136
  # Configure the Google Cloud Spanner Database Admin library. This configuration can be
136
137
  # applied globally to all clients.
137
138
  #
138
- # @example
139
- #
140
- # Modify the global config, setting the timeout to 10 seconds for all admin databases.
141
- #
142
- # require "google/cloud/spanner/admin/database"
143
- #
144
- # ::Google::Cloud::Spanner::Admin::Database.configure do |config|
145
- # config.timeout = 10.0
146
- # end
147
- #
148
139
  # The following configuration parameters are supported:
149
140
  #
150
141
  # * `credentials` (*type:* `String, Hash, Google::Auth::Credentials`) -
@@ -172,6 +163,13 @@ module Google
172
163
  #
173
164
  # @return [::Google::Cloud::Config] The default configuration used by this library
174
165
  #
166
+ # @example Modify the global config, setting the timeout to 10 seconds for all admin databases.
167
+ # require "google/cloud/spanner/admin/database"
168
+ #
169
+ # ::Google::Cloud::Spanner::Admin::Database.configure do |config|
170
+ # config.timeout = 10.0
171
+ # end
172
+ #
175
173
  def self.configure
176
174
  @configure ||= begin
177
175
  namespace = ["Google", "Cloud", "Spanner"]
@@ -21,6 +21,8 @@ module Google
21
21
  module Spanner
22
22
  module Admin
23
23
  module Instance
24
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
25
+
24
26
  ##
25
27
  # Create a new client object for a InstanceAdmin.
26
28
  #
@@ -81,7 +83,6 @@ module Google
81
83
  #
82
84
  # @return [Admin::Instance::V1::InstanceAdmin::Client] A client object of version V1.
83
85
  #
84
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength
85
86
  def self.instance_admin project_id: nil,
86
87
  credentials: nil,
87
88
  scope: nil,
@@ -135,16 +136,6 @@ module Google
135
136
  # Configure the Google Cloud Spanner Instance Admin library. This configuration can be
136
137
  # applied globally to all clients.
137
138
  #
138
- # @example
139
- #
140
- # Modify the global config, setting the timeout to 10 seconds for all admin instances.
141
- #
142
- # require "google/cloud/spanner/admin/instance"
143
- #
144
- # ::Google::Cloud::Spanner::Admin::Instance.configure do |config|
145
- # config.timeout = 10.0
146
- # end
147
- #
148
139
  # The following configuration parameters are supported:
149
140
  #
150
141
  # * `credentials` (*type:* `String, Hash, Google::Auth::Credentials`) -
@@ -172,6 +163,13 @@ module Google
172
163
  #
173
164
  # @return [::Google::Cloud::Config] The default configuration used by this library
174
165
  #
166
+ # @example Modify the global config, setting the timeout to 10 seconds for all admin instances.
167
+ # require "google/cloud/spanner/admin/instance"
168
+ #
169
+ # ::Google::Cloud::Spanner::Admin::Instance.configure do |config|
170
+ # config.timeout = 10.0
171
+ # end
172
+ #
175
173
  def self.configure
176
174
  @configure ||= begin
177
175
  namespace = ["Google", "Cloud", "Spanner"]
@@ -30,8 +30,7 @@ module Google
30
30
  # operations.
31
31
  #
32
32
  # @deprecated Use the result of
33
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_backup_operations}
34
- # instead.
33
+ # {Google::Cloud::Spanner::Admin::Database.database_admin}.list_backup_operations instead.
35
34
  #
36
35
  class List < DelegateClass(::Array)
37
36
  # @private
@@ -36,8 +36,7 @@ module Google
36
36
  # Long-running Operation
37
37
  #
38
38
  # @deprecated Use the long-running operation returned by
39
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#create_backup}
40
- # instead.
39
+ # {Google::Cloud::Spanner::Admin::Database.database_admin}.create_backup instead.
41
40
  #
42
41
  # @example
43
42
  # require "google/cloud/spanner"
@@ -28,9 +28,7 @@ module Google
28
28
  # Google::Cloud::Spanner::Backup::List is a special case Array with
29
29
  # additional values.
30
30
  #
31
- # @deprecated Use the result of
32
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_backups}
33
- # instead.
31
+ # @deprecated Use the result of {Google::Cloud::Spanner::Admin::Database.database_admin}.list_backups instead.
34
32
  #
35
33
  class List < DelegateClass(::Array)
36
34
  # @private
@@ -36,8 +36,7 @@ module Google
36
36
  # Long-running Operation
37
37
  #
38
38
  # @deprecated Use the long-running operation returned by
39
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#restore_database}
40
- # instead.
39
+ # {Google::Cloud::Spanner::Admin::Database.database_admin}.restore_database instead.
41
40
  #
42
41
  # @example
43
42
  # require "google/cloud/spanner"
@@ -196,8 +196,8 @@ module Google
196
196
  snp_session = session
197
197
  snp_grpc = @project.service.create_snapshot \
198
198
  snp_session.path, strong: strong,
199
- timestamp: (timestamp || read_timestamp),
200
- staleness: (staleness || exact_staleness)
199
+ timestamp: timestamp || read_timestamp,
200
+ staleness: staleness || exact_staleness
201
201
  BatchSnapshot.from_grpc snp_grpc, snp_session, directed_read_options: @directed_read_options
202
202
  end
203
203
 
@@ -306,6 +306,7 @@ module Google
306
306
  # * `:BYTES`
307
307
  # * `:DATE`
308
308
  # * `:FLOAT64`
309
+ # * `:FLOAT32`
309
310
  # * `:INT64`
310
311
  # * `:STRING`
311
312
  # * `:TIMESTAMP`
@@ -101,12 +101,13 @@ module Google
101
101
  # configured, although the values given may not necessarily be honored
102
102
  # depending on the query and options in the request.
103
103
  #
104
- # The query must have a single [distributed
104
+ # The request will fail if the query is not root partitionable. For a
105
+ # query to be root partitionable, it needs to satisfy a few conditions.
106
+ # For example, if the query execution plan contains a [distributed
105
107
  # union](https://cloud.google.com/spanner/docs/query-execution-operators#distributed_union)
106
- # operator at the root of the query plan. Such queries are
107
- # root-partitionable. If a query cannot be partitioned at the root,
108
- # Cloud Spanner cannot achieve the parallelism and in this case
109
- # partition generation will fail.
108
+ # operator, then it must be the first operator in the plan. For more
109
+ # information about other conditions, see [Read data in
110
+ # parallel](https://cloud.google.com/spanner/docs/reads#read_data_in_parallel).
110
111
  #
111
112
  # @param [String] sql The SQL query string. See [Query
112
113
  # syntax](https://cloud.google.com/spanner/docs/query-syntax).
@@ -128,6 +129,7 @@ module Google
128
129
  # | `BOOL` | `true`/`false` | |
129
130
  # | `INT64` | `Integer` | |
130
131
  # | `FLOAT64` | `Float` | |
132
+ # | `FLOAT32` | `Float` | |
131
133
  # | `STRING` | `String` | |
132
134
  # | `DATE` | `Date` | |
133
135
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -153,6 +155,7 @@ module Google
153
155
  # * `:BYTES`
154
156
  # * `:DATE`
155
157
  # * `:FLOAT64`
158
+ # * `:FLOAT32`
156
159
  # * `:INT64`
157
160
  # * `:STRING`
158
161
  # * `:TIMESTAMP`
@@ -255,7 +258,7 @@ module Google
255
258
  partition_token: grpc.partition_token,
256
259
  query_options: query_options,
257
260
  data_boost_enabled: data_boost_enabled,
258
- directed_read_options: (directed_read_options || @directed_read_options)
261
+ directed_read_options: directed_read_options || @directed_read_options
259
262
  }.compact
260
263
  )
261
264
  Partition.from_execute_sql_grpc execute_sql_grpc
@@ -365,7 +368,7 @@ module Google
365
368
  transaction: tx_selector,
366
369
  partition_token: grpc.partition_token,
367
370
  data_boost_enabled: data_boost_enabled,
368
- directed_read_options: (directed_read_options || @directed_read_options)
371
+ directed_read_options: directed_read_options || @directed_read_options
369
372
  }.compact
370
373
  )
371
374
  Partition.from_read_grpc read_grpc
@@ -477,6 +480,7 @@ module Google
477
480
  # | `BOOL` | `true`/`false` | |
478
481
  # | `INT64` | `Integer` | |
479
482
  # | `FLOAT64` | `Float` | |
483
+ # | `FLOAT32` | `Float` | |
480
484
  # | `STRING` | `String` | |
481
485
  # | `DATE` | `Date` | |
482
486
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -502,6 +506,7 @@ module Google
502
506
  # * `:BYTES`
503
507
  # * `:DATE`
504
508
  # * `:FLOAT64`
509
+ # * `:FLOAT32`
505
510
  # * `:INT64`
506
511
  # * `:STRING`
507
512
  # * `:TIMESTAMP`
@@ -704,7 +709,7 @@ module Google
704
709
  transaction: tx_selector,
705
710
  query_options: query_options,
706
711
  call_options: call_options,
707
- directed_read_options: (directed_read_options || @directed_read_options)
712
+ directed_read_options: directed_read_options || @directed_read_options
708
713
  end
709
714
  alias execute execute_query
710
715
  alias query execute_query
@@ -780,7 +785,7 @@ module Google
780
785
  session.read table, columns, keys: keys, index: index, limit: limit,
781
786
  transaction: tx_selector,
782
787
  call_options: call_options,
783
- directed_read_options: (directed_read_options || @directed_read_options)
788
+ directed_read_options: directed_read_options || @directed_read_options
784
789
  end
785
790
 
786
791
  ##
@@ -59,6 +59,7 @@ module Google
59
59
  # | `BOOL` | `true`/`false` | |
60
60
  # | `INT64` | `Integer` | |
61
61
  # | `FLOAT64` | `Float` | |
62
+ # | `FLOAT32` | `Float` | |
62
63
  # | `STRING` | `String` | |
63
64
  # | `DATE` | `Date` | |
64
65
  # | `TIMESTAMP` | `Time`, `DateTime` | |
@@ -85,6 +86,7 @@ module Google
85
86
  # * `:BYTES`
86
87
  # * `:DATE`
87
88
  # * `:FLOAT64`
89
+ # * `:FLOAT32`
88
90
  # * `:INT64`
89
91
  # * `:STRING`
90
92
  # * `:TIMESTAMP`
@@ -153,8 +155,7 @@ module Google
153
155
  end
154
156
 
155
157
  def to_grpc
156
- converted_params, converted_types = \
157
- Convert.to_input_params_and_types params, types
158
+ converted_params, converted_types = Convert.to_input_params_and_types params, types
158
159
  # param_types is a grpc map field, can't be nil
159
160
  converted_types ||= {}
160
161
  V1::ExecuteBatchDmlRequest::Statement.new(
@@ -0,0 +1,72 @@
1
+ # Copyright 2024 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
+ require "google/cloud/spanner/mutation_group"
16
+ require "google/cloud/spanner/v1"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ ##
22
+ # Part of the BatchWrite DSL.
23
+ #
24
+ # This object is passed as a parameter to the block passed to
25
+ # {Google::Cloud::Spanner::Client#batch_write}. Use this parameter to add
26
+ # mutation groups to the batch.
27
+ #
28
+ class BatchWrite
29
+ # @private
30
+ def initialize
31
+ @mutation_groups = []
32
+ end
33
+
34
+ ##
35
+ # Adds a group of mutations
36
+ #
37
+ # @example
38
+ # require "google/cloud/spanner"
39
+ #
40
+ # spanner = Google::Cloud::Spanner.new
41
+ #
42
+ # db = spanner.client "my-instance", "my-database"
43
+ #
44
+ # results = db.batch_write do |b|
45
+ # # First mutation group
46
+ # b.mutation_group do |mg|
47
+ # mg.upsert "Singers", [{ SingerId: 16, FirstName: "Charlie", LastName: "Terry" }]
48
+ # end
49
+ #
50
+ # # Second mutation group
51
+ # b.mutation_group do |mg|
52
+ # mg.upsert "Singers", [{ SingerId: 17, FirstName: "Catalina", LastName: "Smith" }]
53
+ # mg.update "Albums", [{ SingerId: 17, AlbumId: 1, AlbumTitle: "Go Go Go" }]
54
+ # end
55
+ # end
56
+ #
57
+ def mutation_group
58
+ mg = MutationGroup.new
59
+ yield mg
60
+ @mutation_groups << mg
61
+ end
62
+
63
+ # @private
64
+ def mutation_groups_grpc
65
+ @mutation_groups.map do |mg|
66
+ Google::Cloud::Spanner::V1::BatchWriteRequest::MutationGroup.new mutations: mg.mutations
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,142 @@
1
+ # Copyright 2024 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
+ require "google/cloud/errors"
16
+ require "google/cloud/spanner/convert"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ ##
22
+ # Results of a batch write.
23
+ #
24
+ # This is a stream of {BatchWriteResults::BatchResult} objects, each of
25
+ # which represents a set of mutation groups applied together.
26
+ #
27
+ # Use the Ruby Enumerable module to iterate over the results.
28
+ #
29
+ class BatchWriteResults
30
+ ##
31
+ # Result of a set of mutation groups applied together.
32
+ #
33
+ class BatchResult
34
+ # @private
35
+ def initialize grpc
36
+ @grpc = grpc
37
+ end
38
+
39
+ ##
40
+ # The indexes of the mutation groups applied together.
41
+ #
42
+ # @return [::Array<::Integer>]
43
+ #
44
+ def indexes
45
+ @grpc.indexes.to_a
46
+ end
47
+
48
+ ##
49
+ # The result of this set of mutation groups.
50
+ #
51
+ # @return [::Google::Rpc::Status]
52
+ #
53
+ def status
54
+ @grpc.status
55
+ end
56
+
57
+ ##
58
+ # Whether these mutation groups were successful.
59
+ #
60
+ # @return [::Boolean]
61
+ #
62
+ def ok?
63
+ status.code.zero?
64
+ end
65
+
66
+ ##
67
+ # Whether these mutation groups were unsuccessful.
68
+ #
69
+ # @return [::Boolean]
70
+ #
71
+ def error?
72
+ !ok?
73
+ end
74
+
75
+ ##
76
+ # The timestamp of the commit.
77
+ #
78
+ # @return [::Time]
79
+ #
80
+ def commit_timestamp
81
+ Convert.timestamp_to_time @grpc.commit_timestamp
82
+ end
83
+ end
84
+
85
+ # @private
86
+ def initialize enum
87
+ @enumerable = enum
88
+ end
89
+
90
+ ##
91
+ # Iterate over the results.
92
+ #
93
+ # @yield [::Google::Cloud::Spanner::BatchWriteResults::BatchResult]
94
+ #
95
+ def each &block
96
+ if defined? @results
97
+ @results.each(&block)
98
+ else
99
+ results = []
100
+ @enumerable.each do |grpc|
101
+ result = BatchResult.new grpc
102
+ results << result
103
+ yield result
104
+ end
105
+ @results = results
106
+ end
107
+ rescue GRPC::BadStatus => e
108
+ raise Google::Cloud::Error.from_error(e)
109
+ end
110
+
111
+ include Enumerable
112
+
113
+ ##
114
+ # Whether all mutation groups were successful.
115
+ #
116
+ # @return [::Boolean]
117
+ #
118
+ def ok?
119
+ all?(&:ok?)
120
+ end
121
+
122
+ ##
123
+ # Whether at least one mutation group encountered an error.
124
+ #
125
+ # @return [::Boolean]
126
+ #
127
+ def error?
128
+ !ok?
129
+ end
130
+
131
+ ##
132
+ # A list of the indexes of successful mutation groups.
133
+ #
134
+ # @return [::Array<::Integer>]
135
+ #
136
+ def successful_indexes
137
+ flat_map { |batch_result| batch_result.ok? ? batch_result.indexes : [] }
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end