google-cloud-datastore 2.12.0 → 2.13.1
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 +4 -4
- data/AUTHENTICATION.md +12 -1
- data/CHANGELOG.md +12 -0
- data/OVERVIEW.md +6 -1
- data/lib/google/cloud/datastore/dataset/aggregate_query_results.rb +40 -14
- data/lib/google/cloud/datastore/dataset.rb +24 -3
- data/lib/google/cloud/datastore/read_only_transaction.rb +23 -3
- data/lib/google/cloud/datastore/service.rb +11 -2
- data/lib/google/cloud/datastore/transaction.rb +53 -0
- data/lib/google/cloud/datastore/version.rb +1 -1
- data/lib/google/cloud/datastore.rb +21 -3
- data/lib/google-cloud-datastore.rb +19 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96ae4fca8972cf097e7b6b10d73e709ecef3d409fc68c96cae5ebcb7058c2d1b
|
|
4
|
+
data.tar.gz: 43c974a4d78a4533403e854d4e6ead63b19307c390e1cd1ed87194562ddde1f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed233508a15ee0c5adeed09f82435be5c9517a045e3b48fe46bfc2503bac49f82863b085ea630a20419232ba852b785377572fbc61dc1ba6048c4bf54415347a
|
|
7
|
+
data.tar.gz: c79f29a8601d877a7f32860b173350977eb8c94a50a4cd2c2b3a1ae3145e90762b525a2603f949c98f6cc6cc96d54b1d4ac049e6f20a3538c64ae4f11bb1e32c
|
data/AUTHENTICATION.md
CHANGED
|
@@ -46,6 +46,12 @@ code.
|
|
|
46
46
|
|
|
47
47
|
**Credentials** are discovered in the following order:
|
|
48
48
|
|
|
49
|
+
> [!WARNING]
|
|
50
|
+
> If you accept a credential configuration (JSON file or Hash) from an
|
|
51
|
+
> external source for authentication to Google Cloud, you must validate it before
|
|
52
|
+
> providing it to a Google API client library. Providing an unvalidated credential
|
|
53
|
+
> configuration to Google APIs can compromise the security of your systems and data.
|
|
54
|
+
|
|
49
55
|
1. Specify credentials in method arguments
|
|
50
56
|
2. Specify credentials in configuration
|
|
51
57
|
3. Discover credentials path in environment variables
|
|
@@ -100,11 +106,16 @@ The **Project ID** and the path to the **Credentials JSON** file can be configur
|
|
|
100
106
|
instead of placing them in environment variables or providing them as arguments.
|
|
101
107
|
|
|
102
108
|
```ruby
|
|
109
|
+
require "googleauth"
|
|
103
110
|
require "google/cloud/datastore"
|
|
104
111
|
|
|
112
|
+
credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
113
|
+
json_key_io: ::File.open("/path/to/keyfile.json")
|
|
114
|
+
)
|
|
115
|
+
|
|
105
116
|
Google::Cloud::Datastore.configure do |config|
|
|
106
117
|
config.project_id = "my-project-id"
|
|
107
|
-
config.credentials =
|
|
118
|
+
config.credentials = credentials
|
|
108
119
|
end
|
|
109
120
|
|
|
110
121
|
client = Google::Cloud::Datastore.new
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 2.13.1 (2025-11-04)
|
|
4
|
+
|
|
5
|
+
#### Documentation
|
|
6
|
+
|
|
7
|
+
* add warning about loading unvalidated credentials ([#32121](https://github.com/googleapis/google-cloud-ruby/issues/32121))
|
|
8
|
+
|
|
9
|
+
### 2.13.0 (2025-07-24)
|
|
10
|
+
|
|
11
|
+
#### Features
|
|
12
|
+
|
|
13
|
+
* add explain query features to aggregate query in Cloud Datastore ([#30704](https://github.com/googleapis/google-cloud-ruby/issues/30704))
|
|
14
|
+
|
|
3
15
|
### 2.12.0 (2025-07-15)
|
|
4
16
|
|
|
5
17
|
#### Features
|
data/OVERVIEW.md
CHANGED
|
@@ -14,11 +14,16 @@ your code or via environment variables. Read more about the options for
|
|
|
14
14
|
connecting in the {file:AUTHENTICATION.md Authentication Guide}.
|
|
15
15
|
|
|
16
16
|
```ruby
|
|
17
|
+
require "googleauth"
|
|
17
18
|
require "google/cloud/datastore"
|
|
18
19
|
|
|
20
|
+
credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
21
|
+
json_key_io: ::File.open("/path/to/keyfile.json")
|
|
22
|
+
)
|
|
23
|
+
|
|
19
24
|
datastore = Google::Cloud::Datastore.new(
|
|
20
25
|
project_id: "my-todo-project",
|
|
21
|
-
credentials:
|
|
26
|
+
credentials: credentials
|
|
22
27
|
)
|
|
23
28
|
|
|
24
29
|
task = datastore.find "Task", "sampleTask"
|
|
@@ -57,9 +57,24 @@ module Google
|
|
|
57
57
|
# @return [Google::Protobuf::Timestamp]
|
|
58
58
|
attr_reader :read_time
|
|
59
59
|
|
|
60
|
+
# Query explain metrics. This is only present when the `explain_options`
|
|
61
|
+
# are provided to {Google::Cloud::Datastore::Dataset#run_aggregation}.
|
|
62
|
+
# It is sent only once with the response.
|
|
63
|
+
#
|
|
64
|
+
# @return [Google::Cloud::Datastore::V1::ExplainMetrics, nil]
|
|
65
|
+
attr_reader :explain_metrics
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
# The options for query explanation.
|
|
69
|
+
#
|
|
70
|
+
# This is a copy of the input parameter supplied to the {Dataset#run_aggregation} function.
|
|
71
|
+
#
|
|
72
|
+
# @return [Google::Cloud::Datastore::V1::ExplainOptions, nil]
|
|
73
|
+
attr_reader :explain_options
|
|
74
|
+
|
|
60
75
|
##
|
|
61
76
|
# @private
|
|
62
|
-
attr_writer :aggregate_fields, :read_time
|
|
77
|
+
attr_writer :aggregate_fields, :read_time, :explain_metrics, :explain_options
|
|
63
78
|
|
|
64
79
|
##
|
|
65
80
|
# Retrieves the aggregate data.
|
|
@@ -113,22 +128,33 @@ module Google
|
|
|
113
128
|
##
|
|
114
129
|
# @private New AggregateQueryResults from a
|
|
115
130
|
# Google::Cloud::Datastore::V1::RunAggregationQueryResponse object.
|
|
116
|
-
def self.from_grpc aggregate_query_response
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
def self.from_grpc aggregate_query_response, explain_options
|
|
132
|
+
# If the aggregate query is run with explain_options and analyze = false,
|
|
133
|
+
# the RunAggregationQueryResponse will not have batch results
|
|
134
|
+
# only explain metrics.
|
|
135
|
+
aggregate_fields = {}
|
|
136
|
+
read_time = nil
|
|
137
|
+
|
|
138
|
+
if aggregate_query_response.batch
|
|
139
|
+
aggregate_fields = aggregate_query_response
|
|
140
|
+
.batch
|
|
141
|
+
.aggregation_results[0]
|
|
142
|
+
.aggregate_properties
|
|
143
|
+
.map do |aggregate_alias, value|
|
|
144
|
+
if value.has_integer_value?
|
|
145
|
+
[aggregate_alias, value.integer_value]
|
|
146
|
+
else
|
|
147
|
+
[aggregate_alias, value.double_value]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
read_time = aggregate_query_response.batch.read_time
|
|
151
|
+
end
|
|
128
152
|
|
|
129
153
|
new.tap do |aq_result|
|
|
154
|
+
aq_result.explain_options = explain_options
|
|
155
|
+
aq_result.explain_metrics = aggregate_query_response.explain_metrics
|
|
130
156
|
aq_result.aggregate_fields = aggregate_fields.to_h
|
|
131
|
-
aq_result.read_time =
|
|
157
|
+
aq_result.read_time = read_time
|
|
132
158
|
end
|
|
133
159
|
end
|
|
134
160
|
end
|
|
@@ -549,6 +549,10 @@ module Google
|
|
|
549
549
|
# [Eventual Consistency in Google Cloud
|
|
550
550
|
# Datastore](https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/#h.tf76fya5nqk8)
|
|
551
551
|
# for more information.
|
|
552
|
+
# @param [Hash, Google::Cloud::Datastore::V1::ExplainOptions] explain_options The options for query explanation.
|
|
553
|
+
# Provide this argument to enable explain metrics. If this argument is left unset,
|
|
554
|
+
# the results will not include explain metrics.
|
|
555
|
+
# See {Google::Cloud::Datastore::V1::ExplainOptions} for details. Optional.
|
|
552
556
|
#
|
|
553
557
|
# @return [Google::Cloud::Datastore::Dataset::AggregateQueryResults]
|
|
554
558
|
#
|
|
@@ -607,15 +611,32 @@ module Google
|
|
|
607
611
|
# done: false
|
|
608
612
|
# res = datastore.run_aggregation gql_query, namespace: "example-ns"
|
|
609
613
|
#
|
|
610
|
-
|
|
614
|
+
# @example Run the aggregate query with explain options to get query plan and execution statistics.
|
|
615
|
+
# require "google/cloud/datastore"
|
|
616
|
+
#
|
|
617
|
+
# datastore = Google::Cloud::Datastore.new
|
|
618
|
+
#
|
|
619
|
+
# query = datastore.query("Task")
|
|
620
|
+
# aggregate_query = query.aggregate_query.add_count aggregate_alias: "total"
|
|
621
|
+
# results = datastore.run_aggregation aggregate_query, explain_options: { analyze: true }
|
|
622
|
+
#
|
|
623
|
+
# if results.explain_metrics
|
|
624
|
+
# stats = results.explain_metrics.execution_stats
|
|
625
|
+
# puts "Read operations: #{stats.read_operations}"
|
|
626
|
+
# end
|
|
627
|
+
#
|
|
628
|
+
def run_aggregation aggregate_query, namespace: nil, consistency: nil, read_time: nil, explain_options: nil
|
|
611
629
|
ensure_service!
|
|
612
630
|
unless aggregate_query.is_a?(AggregateQuery) || aggregate_query.is_a?(GqlQuery)
|
|
613
631
|
raise ArgumentError, "Cannot run a #{aggregate_query.class} object."
|
|
614
632
|
end
|
|
615
633
|
check_consistency! consistency
|
|
616
634
|
aggregate_query_res = service.run_aggregation_query aggregate_query.to_grpc, namespace,
|
|
617
|
-
consistency: consistency,
|
|
618
|
-
|
|
635
|
+
consistency: consistency,
|
|
636
|
+
read_time: read_time,
|
|
637
|
+
explain_options: explain_options
|
|
638
|
+
|
|
639
|
+
AggregateQueryResults.from_grpc aggregate_query_res, explain_options
|
|
619
640
|
end
|
|
620
641
|
|
|
621
642
|
##
|
|
@@ -236,14 +236,34 @@ module Google
|
|
|
236
236
|
# .add_count
|
|
237
237
|
# res = tx.run_aggregation aggregate_query
|
|
238
238
|
# end
|
|
239
|
+
# @example Run the aggregate query with explain options:
|
|
240
|
+
# require "google/cloud/datastore"
|
|
241
|
+
#
|
|
242
|
+
# datastore = Google::Cloud::Datastore.new
|
|
243
|
+
#
|
|
244
|
+
# datastore.read_only_transaction do |tx|
|
|
245
|
+
# query = tx.query("Task")
|
|
246
|
+
# aggregate_query = query.aggregate_query.add_count aggregate_alias: "total"
|
|
247
|
+
# results = tx.run_aggregation aggregate_query, explain_options: { analyze: true }
|
|
248
|
+
#
|
|
249
|
+
# if results.explain_metrics
|
|
250
|
+
# stats = results.explain_metrics.execution_stats
|
|
251
|
+
# puts "Read operations: #{stats.read_operations}"
|
|
252
|
+
# end
|
|
253
|
+
# end
|
|
239
254
|
#
|
|
240
|
-
def run_aggregation aggregate_query, namespace: nil
|
|
255
|
+
def run_aggregation aggregate_query, namespace: nil, explain_options: nil
|
|
241
256
|
ensure_service!
|
|
242
257
|
unless aggregate_query.is_a?(AggregateQuery) || aggregate_query.is_a?(GqlQuery)
|
|
243
258
|
raise ArgumentError, "Cannot run a #{aggregate_query.class} object."
|
|
244
259
|
end
|
|
245
|
-
|
|
246
|
-
|
|
260
|
+
|
|
261
|
+
aggregate_query_results = service.run_aggregation_query aggregate_query.to_grpc,
|
|
262
|
+
namespace,
|
|
263
|
+
transaction: @id,
|
|
264
|
+
explain_options: explain_options
|
|
265
|
+
|
|
266
|
+
Dataset::AggregateQueryResults.from_grpc aggregate_query_results, explain_options
|
|
247
267
|
end
|
|
248
268
|
|
|
249
269
|
##
|
|
@@ -98,7 +98,15 @@ module Google
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
## Query for aggregates
|
|
101
|
-
def run_aggregation_query query, namespace = nil, consistency: nil, transaction: nil, read_time: nil
|
|
101
|
+
def run_aggregation_query query, namespace = nil, consistency: nil, transaction: nil, read_time: nil,
|
|
102
|
+
explain_options: nil
|
|
103
|
+
if explain_options
|
|
104
|
+
explain_options = ::Gapic::Protobuf.coerce(
|
|
105
|
+
explain_options,
|
|
106
|
+
to: ::Google::Cloud::Datastore::V1::ExplainOptions
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
102
110
|
gql_query = nil
|
|
103
111
|
if query.is_a? Google::Cloud::Datastore::V1::GqlQuery
|
|
104
112
|
gql_query = query
|
|
@@ -115,7 +123,8 @@ module Google
|
|
|
115
123
|
partition_id: partition_id,
|
|
116
124
|
read_options: read_options,
|
|
117
125
|
aggregation_query: query,
|
|
118
|
-
gql_query: gql_query
|
|
126
|
+
gql_query: gql_query,
|
|
127
|
+
explain_options: explain_options
|
|
119
128
|
end
|
|
120
129
|
|
|
121
130
|
##
|
|
@@ -310,6 +310,59 @@ module Google
|
|
|
310
310
|
end
|
|
311
311
|
alias run_query run
|
|
312
312
|
|
|
313
|
+
##
|
|
314
|
+
# Retrieve aggregate query results specified by an AggregateQuery. The query is run within the
|
|
315
|
+
# transaction.
|
|
316
|
+
#
|
|
317
|
+
# @param [AggregateQuery, GqlQuery] aggregate_query The Query object
|
|
318
|
+
# with the search criteria.
|
|
319
|
+
# @param [String] namespace The namespace the query is to run within.
|
|
320
|
+
# @param [Hash, Google::Cloud::Datastore::V1::ExplainOptions] explain_options
|
|
321
|
+
# The options for query explanation. See {Google::Cloud::Datastore::V1::ExplainOptions}
|
|
322
|
+
# for details. Optional.
|
|
323
|
+
#
|
|
324
|
+
# @return [Google::Cloud::Datastore::Dataset::AggregateQueryResults]
|
|
325
|
+
#
|
|
326
|
+
# @example
|
|
327
|
+
# require "google/cloud/datastore"
|
|
328
|
+
#
|
|
329
|
+
# datastore = Google::Cloud::Datastore.new
|
|
330
|
+
#
|
|
331
|
+
# datastore.transaction do |tx|
|
|
332
|
+
# query = tx.query("Task")
|
|
333
|
+
# .where("done", "=", false)
|
|
334
|
+
# aggregate_query = query.aggregate_query
|
|
335
|
+
# .add_count
|
|
336
|
+
# res = tx.run_aggregation aggregate_query
|
|
337
|
+
# end
|
|
338
|
+
#
|
|
339
|
+
# @example Run the aggregate query with explain options:
|
|
340
|
+
# require "google/cloud/datastore"
|
|
341
|
+
#
|
|
342
|
+
# datastore = Google::Cloud::Datastore.new
|
|
343
|
+
#
|
|
344
|
+
# datastore.transaction do |tx|
|
|
345
|
+
# query = tx.query("Task")
|
|
346
|
+
# aggregate_query = query.aggregate_query.add_count aggregate_alias: "total"
|
|
347
|
+
# results = tx.run_aggregation aggregate_query, explain_options: { analyze: true }
|
|
348
|
+
#
|
|
349
|
+
# if results.explain_metrics
|
|
350
|
+
# stats = results.explain_metrics.execution_stats
|
|
351
|
+
# puts "Read operations: #{stats.read_operations}"
|
|
352
|
+
# end
|
|
353
|
+
# end
|
|
354
|
+
#
|
|
355
|
+
def run_aggregation aggregate_query, namespace: nil, explain_options: nil
|
|
356
|
+
ensure_service!
|
|
357
|
+
unless aggregate_query.is_a?(AggregateQuery) || aggregate_query.is_a?(GqlQuery)
|
|
358
|
+
raise ArgumentError, "Cannot run a #{aggregate_query.class} object."
|
|
359
|
+
end
|
|
360
|
+
aggregate_query_results = service.run_aggregation_query aggregate_query.to_grpc, namespace,
|
|
361
|
+
transaction: @id,
|
|
362
|
+
explain_options: explain_options
|
|
363
|
+
Dataset::AggregateQueryResults.from_grpc aggregate_query_results, explain_options
|
|
364
|
+
end
|
|
365
|
+
|
|
313
366
|
##
|
|
314
367
|
# Begins a transaction.
|
|
315
368
|
# This method is run when a new Transaction is created.
|
|
@@ -58,9 +58,27 @@ module Google
|
|
|
58
58
|
#
|
|
59
59
|
# @param [String] project_id Identifier for a Datastore project. If not
|
|
60
60
|
# present, the default project for the credentials is used.
|
|
61
|
-
# @param [
|
|
62
|
-
#
|
|
63
|
-
#
|
|
61
|
+
# @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
|
|
62
|
+
# object. (See {Datastore::Credentials})
|
|
63
|
+
# @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
|
|
64
|
+
# is deprecated. Providing an unvalidated credential configuration to
|
|
65
|
+
# Google APIs can compromise the security of your systems and data.
|
|
66
|
+
#
|
|
67
|
+
# @example
|
|
68
|
+
#
|
|
69
|
+
# # The recommended way to provide credentials is to use the `make_creds` method
|
|
70
|
+
# # on the appropriate credentials class for your environment.
|
|
71
|
+
#
|
|
72
|
+
# require "googleauth"
|
|
73
|
+
#
|
|
74
|
+
# credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
75
|
+
# json_key_io: ::File.open("/path/to/keyfile.json")
|
|
76
|
+
# )
|
|
77
|
+
#
|
|
78
|
+
# datastore = Google::Cloud::Datastore.new(
|
|
79
|
+
# project_id: "my-project-id",
|
|
80
|
+
# credentials: credentials
|
|
81
|
+
# )
|
|
64
82
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
|
65
83
|
# the set of resources and operations that the connection can access.
|
|
66
84
|
# See [Using OAuth 2.0 to Access Google
|
|
@@ -84,9 +84,25 @@ module Google
|
|
|
84
84
|
#
|
|
85
85
|
# @param [String] project_id Identifier for a Datastore project. If not
|
|
86
86
|
# present, the default project for the credentials is used.
|
|
87
|
-
# @param [
|
|
88
|
-
#
|
|
89
|
-
#
|
|
87
|
+
# @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
|
|
88
|
+
# object. (See {Datastore::Credentials})
|
|
89
|
+
# @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
|
|
90
|
+
# is deprecated. Providing an unvalidated credential configuration to
|
|
91
|
+
# Google APIs can compromise the security of your systems and data.
|
|
92
|
+
#
|
|
93
|
+
# @example
|
|
94
|
+
#
|
|
95
|
+
# # The recommended way to provide credentials is to use the `make_creds` method
|
|
96
|
+
# # on the appropriate credentials class for your environment.
|
|
97
|
+
#
|
|
98
|
+
# credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
|
|
99
|
+
# json_key_io: ::File.open("/path/to/keyfile.json")
|
|
100
|
+
# )
|
|
101
|
+
#
|
|
102
|
+
# datastore = Google::Cloud::Datastore.new(
|
|
103
|
+
# project_id: "my-project-id",
|
|
104
|
+
# credentials: credentials
|
|
105
|
+
# )
|
|
90
106
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
|
91
107
|
# set of resources and operations that the connection can access. See
|
|
92
108
|
# [Using OAuth 2.0 to Access Google
|