google-cloud-datastore 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b372b670c25604994c20b79779906b9a7c00b21bdf3ada9a23eb2cbb5968d053
4
- data.tar.gz: 2cb8cac3d2de7b1b631d1c9ee7332b7391a73a720968bf09dc0608430de2a472
3
+ metadata.gz: 6c062edd7866b2d8f56365618cdbfca915d1df66440e9bdfca54d4e85bbc0133
4
+ data.tar.gz: c4085c6ba18cd98c6ec7f38b6487dfbab56dd00030eb3dcad70afa184772056e
5
5
  SHA512:
6
- metadata.gz: dba07c333a2230e08f4c315dce2b8e28c748a082561c0692d9e419ba47565496b4b47463912e6cebea34ca3c33732df257ec6b4bcd9419b664cc16a4338b9b76
7
- data.tar.gz: e817d031036cefd768ccf202a291435c6a710f69292ea61f2349bd5456732b3e0253ce94c75006abbcbc231c6c6e664bd4340dd2836f20978542dc2bb30b3b45
6
+ metadata.gz: 9621f21518ea67ebedcd0230f16b240976152d99133b2e0e4ecb7a770e92079e47a44868925cb7ac4aaeef8030a6138ef2842836749b4274c9a5ada151eeae28
7
+ data.tar.gz: 0dbf0d457be8a4b94e6be54a7eaae13ea31113d818025ed59905fc3c7bbd64c3c10bff2fbb36519f3a94cd17f0b901bfb9029d837e5a4c36f73282ef39012997
data/AUTHENTICATION.md CHANGED
@@ -125,15 +125,6 @@ To configure your system for this, simply:
125
125
  **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
126
126
  *should* only be used during development.
127
127
 
128
- [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
129
- [dev-console]: https://console.cloud.google.com/project
130
-
131
- [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
132
-
133
- [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
134
- [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
135
- [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
136
-
137
128
  ## Creating a Service Account
138
129
 
139
130
  Google Cloud requires a **Project ID** and **Service Account Credentials** to
@@ -144,31 +135,22 @@ If you are not running this client within [Google Cloud Platform
144
135
  environments](#google-cloud-platform-environments), you need a Google
145
136
  Developers service account.
146
137
 
147
- 1. Visit the [Google Developers Console][dev-console].
138
+ 1. Visit the [Google Cloud Console](https://console.cloud.google.com/project).
148
139
  1. Create a new project or click on an existing project.
149
- 1. Activate the slide-out navigation tray and select **API Manager**. From
140
+ 1. Activate the menu in the upper left and select **APIs & Services**. From
150
141
  here, you will enable the APIs that your application requires.
151
142
 
152
- ![Enable the APIs that your application requires][enable-apis]
153
-
154
143
  *Note: You may need to enable billing in order to use these services.*
155
144
 
156
145
  1. Select **Credentials** from the side navigation.
157
146
 
158
- You should see a screen like one of the following.
159
-
160
- ![Create a new service account][create-new-service-account]
161
-
162
- ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
163
-
164
- Find the "Add credentials" drop down and select "Service account" to be
165
- guided through downloading a new JSON key file.
166
-
167
- If you want to re-use an existing service account, you can easily generate a
168
- new key file. Just select the account you wish to re-use, and click "Generate
169
- new JSON key":
147
+ Find the "Create credentials" drop down near the top of the page, and select
148
+ "Service account" to be guided through downloading a new JSON key file.
170
149
 
171
- ![Re-use an existing service account][reuse-service-account]
150
+ If you want to re-use an existing service account, you can easily generate
151
+ a new key file. Just select the account you wish to re-use click the pencil
152
+ tool on the right side to edit the service account, select the **Keys** tab,
153
+ and then select **Add Key**.
172
154
 
173
155
  The key file you download will be used by this library to authenticate API
174
156
  requests and should be stored in a secure location.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 2.8.0 (2023-09-12)
4
+
5
+ #### Features
6
+
7
+ * Support sum & avg aggregate functions ([#22884](https://github.com/googleapis/google-cloud-ruby/issues/22884))
8
+
9
+ ### 2.7.1 (2023-05-18)
10
+
11
+ #### Documentation
12
+
13
+ * Fixed broken links in authentication documentation ([#21619](https://github.com/googleapis/google-cloud-ruby/issues/21619))
14
+
3
15
  ### 2.7.0 (2023-04-12)
4
16
 
5
17
  #### Features
@@ -56,19 +56,30 @@ module Google
56
56
  # puts aggregate_query_results.get('total')
57
57
  #
58
58
  class AggregateQuery
59
- ##
60
- # @private The Google::Cloud::Datastore::V1::Query object.
61
- attr_reader :query
59
+ # @private
60
+ DEFAULT_COUNT_AGGREGATE_ALIAS = "count".freeze
61
+
62
+ # @private
63
+ DEFAULT_SUM_AGGREGATE_ALIAS = "sum".freeze
64
+
65
+ # @private
66
+ DEFAULT_AVG_AGGREGATE_ALIAS = "avg".freeze
62
67
 
63
68
  ##
64
- # @private Array of Google::Cloud::Datastore::V1::AggregationQuery::Aggregation objects
65
- attr_reader :aggregates
69
+ # @private The Google::Cloud::Datastore::V1::AggregationQuery object.
70
+ attr_reader :grpc
66
71
 
67
72
  ##
68
- # @private Creates a new AggregateQuery
73
+ # @private
74
+ #
75
+ # Returns a new AggregateQuery object
76
+ #
77
+ # @param query [Google::Cloud::Datastore::V1::Query]
69
78
  def initialize query
70
- @query = query
71
- @aggregates = []
79
+ @grpc = Google::Cloud::Datastore::V1::AggregationQuery.new(
80
+ nested_query: query,
81
+ aggregations: []
82
+ )
72
83
  end
73
84
 
74
85
  ##
@@ -111,8 +122,8 @@ module Google
111
122
  # puts aggregate_query_results.get('total')
112
123
  #
113
124
  def add_count aggregate_alias: nil
114
- aggregate_alias ||= ALIASES[:count]
115
- aggregates << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
125
+ aggregate_alias ||= DEFAULT_COUNT_AGGREGATE_ALIAS
126
+ @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
116
127
  count: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Count.new,
117
128
  alias: aggregate_alias
118
129
  )
@@ -120,19 +131,118 @@ module Google
120
131
  self
121
132
  end
122
133
 
123
- # @private
124
- def to_grpc
125
- Google::Cloud::Datastore::V1::AggregationQuery.new(
126
- nested_query: query,
127
- aggregations: aggregates
134
+ ##
135
+ # Adds a sum aggregate.
136
+ #
137
+ # @param name [String] The property to sum by.
138
+ # @param aggregate_alias [String] Alias to refer to the aggregate. Optional
139
+ #
140
+ # @return [AggregateQuery] The modified aggregate query object with the added SUM aggregate.
141
+ #
142
+ # @example
143
+ # require "google/cloud/datastore"
144
+ #
145
+ # datastore = Google::Cloud::Datastore.new
146
+ #
147
+ # query = Google::Cloud::Datastore::Query.new
148
+ # query.kind("Task")
149
+ # .where("done", "=", false)
150
+ #
151
+ # Create an aggregate query
152
+ # aggregate_query = query.aggregate_query
153
+ # .add_sum("score")
154
+ #
155
+ # aggregate_query_results = dataset.run_aggregation aggregate_query
156
+ # puts aggregate_query_results.get
157
+ #
158
+ # @example Alias an aggregate SUM query
159
+ # require "google/cloud/datastore"
160
+ #
161
+ # datastore = Google::Cloud::Datastore.new
162
+ #
163
+ # query = Google::Cloud::Datastore::Query.new
164
+ # query.kind("Task")
165
+ # .where("done", "=", false)
166
+ #
167
+ # # Create an aggregate query
168
+ # aggregate_query = query.aggregate_query
169
+ # .add_sum("score", aggregate_alias: 'total_score')
170
+ #
171
+ # aggregate_query_results = dataset.run_aggregation aggregate_query
172
+ # puts aggregate_query_results.get('total_score')
173
+ #
174
+ def add_sum name, aggregate_alias: nil
175
+ aggregate_alias ||= DEFAULT_SUM_AGGREGATE_ALIAS
176
+ @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
177
+ sum: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Sum.new(
178
+ property: Google::Cloud::Datastore::V1::PropertyReference.new(
179
+ name: name
180
+ )
181
+ ),
182
+ alias: aggregate_alias
128
183
  )
184
+
185
+ self
129
186
  end
130
187
 
131
188
  ##
189
+ # Adds an average aggregate.
190
+ #
191
+ # @param name [String] The property to apply average on.
192
+ # @param aggregate_alias [String] Alias to refer to the aggregate. Optional
193
+ #
194
+ # @return [AggregateQuery] The modified aggregate query object with the added AVG aggregate.
195
+ #
196
+ # @example
197
+ # require "google/cloud/datastore"
198
+ #
199
+ # datastore = Google::Cloud::Datastore.new
200
+ #
201
+ # query = Google::Cloud::Datastore::Query.new
202
+ # query.kind("Task")
203
+ # .where("done", "=", false)
204
+ #
205
+ # Create an aggregate query
206
+ # aggregate_query = query.aggregate_query
207
+ # .add_avg("score")
208
+ #
209
+ # aggregate_query_results = dataset.run_aggregation aggregate_query
210
+ # puts aggregate_query_results.get
211
+ #
212
+ # @example Alias an aggregate AVG query
213
+ # require "google/cloud/datastore"
214
+ #
215
+ # datastore = Google::Cloud::Datastore.new
216
+ #
217
+ # query = Google::Cloud::Datastore::Query.new
218
+ # query.kind("Task")
219
+ # .where("done", "=", false)
220
+ #
221
+ # # Create an aggregate query
222
+ # aggregate_query = query.aggregate_query
223
+ # .add_avg("score", aggregate_alias: 'avg_score')
224
+ #
225
+ # aggregate_query_results = dataset.run_aggregation aggregate_query
226
+ # puts aggregate_query_results.get('avg_score')
227
+ #
228
+ def add_avg name, aggregate_alias: nil
229
+ aggregate_alias ||= DEFAULT_AVG_AGGREGATE_ALIAS
230
+ @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
231
+ avg: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Avg.new(
232
+ property: Google::Cloud::Datastore::V1::PropertyReference.new(
233
+ name: name
234
+ )
235
+ ),
236
+ alias: aggregate_alias
237
+ )
238
+
239
+ self
240
+ end
241
+
132
242
  # @private
133
- ALIASES = {
134
- count: "count"
135
- }.freeze
243
+ def to_grpc
244
+ @grpc
245
+ end
136
246
  end
137
247
  end
138
248
  end
@@ -39,6 +39,17 @@ module Google
39
39
  # puts aggregate_query_results.get
40
40
  #
41
41
  class AggregateQueryResults
42
+ ##
43
+ # @private Object of type [Hash{String => Object}].
44
+ #
45
+ # String can have the following values:
46
+ # - an aggregate literal "sum", "avg", or "count"
47
+ # - a custom aggregate alias
48
+ # Object can have the following types:
49
+ # - Integer
50
+ # - Float
51
+ attr_reader :aggregate_fields
52
+
42
53
  ##
43
54
  # Read timestamp the query was done on the database at.
44
55
  #
@@ -52,7 +63,8 @@ module Google
52
63
  # the aggregate value. For an AggregateQuery with a
53
64
  # single aggregate field, this parameter can be omitted.
54
65
  #
55
- # @return [Integer] The aggregate value.
66
+ # @return [Integer, Float, nil] The aggregate value. Returns `nil`
67
+ # if the aggregate_alias does not exist.
56
68
  #
57
69
  # @example
58
70
  # require "google/cloud/datastore"
@@ -101,8 +113,15 @@ module Google
101
113
  .batch
102
114
  .aggregation_results[0]
103
115
  .aggregate_properties
116
+ .map do |aggregate_alias, value|
117
+ if value.has_integer_value?
118
+ [aggregate_alias, value.integer_value]
119
+ else
120
+ [aggregate_alias, value.double_value]
121
+ end
122
+ end
104
123
  .to_h
105
- .transform_values { |v| v[:integer_value] }
124
+
106
125
  new.tap do |s|
107
126
  s.instance_variable_set :@aggregate_fields, aggregate_fields
108
127
  s.instance_variable_set :@read_time, aggregate_query_response.batch.read_time
@@ -987,8 +987,8 @@ module Google
987
987
  #
988
988
  # @param name [String] The property to filter by.
989
989
  # @param operator [String] The operator to filter by. Defaults to nil.
990
- # @param value The value to compare the property to. Defaults to nil.
991
- # Possible values are:
990
+ # @param value [Object] The value to compare the property to. Defaults
991
+ # to nil. Possible values are:
992
992
  # - Integer
993
993
  # - Float/BigDecimal
994
994
  # - String
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Datastore
19
- VERSION = "2.7.0".freeze
19
+ VERSION = "2.8.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-12 00:00:00.000000000 Z
12
+ date: 2023-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  - !ruby/object:Gem::Version
239
239
  version: '0'
240
240
  requirements: []
241
- rubygems_version: 3.4.2
241
+ rubygems_version: 3.4.19
242
242
  signing_key:
243
243
  specification_version: 4
244
244
  summary: API Client library for Google Cloud Datastore