google-cloud-datastore 2.7.1 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c062edd7866b2d8f56365618cdbfca915d1df66440e9bdfca54d4e85bbc0133
|
4
|
+
data.tar.gz: c4085c6ba18cd98c6ec7f38b6487dfbab56dd00030eb3dcad70afa184772056e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9621f21518ea67ebedcd0230f16b240976152d99133b2e0e4ecb7a770e92079e47a44868925cb7ac4aaeef8030a6138ef2842836749b4274c9a5ada151eeae28
|
7
|
+
data.tar.gz: 0dbf0d457be8a4b94e6be54a7eaae13ea31113d818025ed59905fc3c7bbd64c3c10bff2fbb36519f3a94cd17f0b901bfb9029d837e5a4c36f73282ef39012997
|
data/CHANGELOG.md
CHANGED
@@ -56,6 +56,15 @@ module Google
|
|
56
56
|
# puts aggregate_query_results.get('total')
|
57
57
|
#
|
58
58
|
class AggregateQuery
|
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
|
67
|
+
|
59
68
|
##
|
60
69
|
# @private The Google::Cloud::Datastore::V1::AggregationQuery object.
|
61
70
|
attr_reader :grpc
|
@@ -113,7 +122,7 @@ module Google
|
|
113
122
|
# puts aggregate_query_results.get('total')
|
114
123
|
#
|
115
124
|
def add_count aggregate_alias: nil
|
116
|
-
aggregate_alias ||=
|
125
|
+
aggregate_alias ||= DEFAULT_COUNT_AGGREGATE_ALIAS
|
117
126
|
@grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new(
|
118
127
|
count: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Count.new,
|
119
128
|
alias: aggregate_alias
|
@@ -122,16 +131,118 @@ module Google
|
|
122
131
|
self
|
123
132
|
end
|
124
133
|
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
183
|
+
)
|
184
|
+
|
185
|
+
self
|
128
186
|
end
|
129
187
|
|
130
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
|
+
|
131
242
|
# @private
|
132
|
-
|
133
|
-
|
134
|
-
|
243
|
+
def to_grpc
|
244
|
+
@grpc
|
245
|
+
end
|
135
246
|
end
|
136
247
|
end
|
137
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
|
-
|
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
|
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.
|
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-
|
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.
|
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
|