google-cloud-spanner 2.22.0 → 2.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 513a3295d6e11b7e4550647a7aad81ac3d52d4ea3e758d79eb39c7d62a2c7202
4
- data.tar.gz: a86f44421150171474e3335af0fa82712e26387c5ecb12051ea6d3b661a2c310
3
+ metadata.gz: fe45aaee1d474b68ce2280271bd6d08756001451210dd35675405bc295c64385
4
+ data.tar.gz: 5de2b1c338ec90c0d8acc645f70a362ca7c79924bc65fd7ec575734f454a95cd
5
5
  SHA512:
6
- metadata.gz: b57e293bd3a352475fa1a57177dd54c153240850df552b230088c13fa5222916391dd17b36cb06817f214bd067b457ae0a66a638e30d7a364d1467e76cd70a1e
7
- data.tar.gz: a91b6efe6724f1f3a2e8b77fb2c85918bfe3b732bf17dc52b8728db9c10e1f18bde501dd09a08af24fd29f8297c4206cdbac3cdbb18427b21d97f2af584ecd81
6
+ metadata.gz: 2a9190ee8a2c1b19465f6fe7ab46dfcb6bb757eb5500fe933d77e9d0fd6aef5f260c5c926553c07ca8f6360d0b23dd73bd9ed1f2541ce9626c5b2fdd8ee3e1a0
7
+ data.tar.gz: e040dfdd82111133d685455b7cb2ce49bc0bb8e9a669b513cd9988e6478fd15076ebb004e651e626a5548f644f58a6c67c7a4cc529d0a58e54bb0becb71f2186
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Release History
2
2
 
3
+ ### 2.24.0 (2024-08-27)
4
+
5
+ #### Features
6
+
7
+ * Support 1.x versions of low-level spanner clients ([#113](https://github.com/googleapis/ruby-spanner/issues/113))
8
+ #### Bug Fixes
9
+
10
+ * Correct the field mask when adding labels to an instance that had none previously ([#114](https://github.com/googleapis/ruby-spanner/issues/114))
11
+
12
+ ### 2.23.0 (2024-06-27)
13
+
14
+ #### Features
15
+
16
+ * Support BatchWrite API ([#99](https://github.com/googleapis/ruby-spanner/issues/99))
17
+ * Support exclude_txn_from_change_streams ([#108](https://github.com/googleapis/ruby-spanner/issues/108))
18
+ #### Bug Fixes
19
+
20
+ * Resolve BigDecimal warning in Ruby 3.4 ([#103](https://github.com/googleapis/ruby-spanner/issues/103))
21
+ #### Documentation
22
+
23
+ * Update documentation regarding root partitionability ([#101](https://github.com/googleapis/ruby-spanner/issues/101))
24
+
3
25
  ### 2.22.0 (2024-04-01)
4
26
 
5
27
  #### 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"
@@ -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).
@@ -155,8 +155,7 @@ module Google
155
155
  end
156
156
 
157
157
  def to_grpc
158
- converted_params, converted_types = \
159
- Convert.to_input_params_and_types params, types
158
+ converted_params, converted_types = Convert.to_input_params_and_types params, types
160
159
  # param_types is a grpc map field, can't be nil
161
160
  converted_types ||= {}
162
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