google-cloud-bigquery 1.12.0 → 1.16.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 +4 -4
- data/CHANGELOG.md +54 -1
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +1 -1
- data/lib/google-cloud-bigquery.rb +1 -0
- data/lib/google/cloud/bigquery.rb +19 -7
- data/lib/google/cloud/bigquery/dataset.rb +81 -1
- data/lib/google/cloud/bigquery/external.rb +46 -0
- data/lib/google/cloud/bigquery/extract_job.rb +46 -7
- data/lib/google/cloud/bigquery/job/list.rb +8 -11
- data/lib/google/cloud/bigquery/model.rb +76 -0
- data/lib/google/cloud/bigquery/project.rb +31 -7
- data/lib/google/cloud/bigquery/service.rb +14 -7
- data/lib/google/cloud/bigquery/table.rb +59 -5
- data/lib/google/cloud/bigquery/table/async_inserter.rb +15 -1
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95ecbf392c1c918219849034d540067effe661d635f7d435c1f73c0bbdcbefb3
|
4
|
+
data.tar.gz: 6452936f3e68a2fb9249fbdd23e54374ce67a86945b936adc6d06571b0266d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c28948fc38d7fccd1b3775f209926eacbe671ddd36432660f336457d0630d8ce921b1600170cb7d56b093c2f805dd39d84230ddc04668f9e3a3d1238d0038dc
|
7
|
+
data.tar.gz: 7adba9ab644ef05f683a5a1b5f647e9106b77d997796c0d867d569caeac10d778d2948823f383f3eb7cfe1b5946b5c22a46d1403352f8358c7df1500ffdf291c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,58 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.16.0 / 2019-10-03
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Add Dataset default_encryption
|
8
|
+
* Add Dataset#default_encryption
|
9
|
+
* Add Dataset#default_encryption=
|
10
|
+
|
11
|
+
### 1.15.0 / 2019-09-30
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* Add Model encryption
|
16
|
+
* Add Model#encryption
|
17
|
+
* Add Model#encryption=
|
18
|
+
* Add range support for Google Sheets
|
19
|
+
* Add External::SheetsSource#range
|
20
|
+
* Add External::SheetsSource#range=
|
21
|
+
* Support use_avro_logical_types on extract jobs
|
22
|
+
* Add ExtractJob#use_avro_logical_types?
|
23
|
+
* Add ExtractJob::Updater#use_avro_logical_types=
|
24
|
+
|
25
|
+
### 1.14.1 / 2019-09-04
|
26
|
+
|
27
|
+
#### Documentation
|
28
|
+
|
29
|
+
* Add note about streaming insert issues
|
30
|
+
* Acknowledge tradeoffs when inserting rows soon after
|
31
|
+
table metadata has been changed.
|
32
|
+
* Add link to BigQuery Troubleshooting guide.
|
33
|
+
|
34
|
+
### 1.14.0 / 2019-08-23
|
35
|
+
|
36
|
+
#### Features
|
37
|
+
|
38
|
+
* Support overriding of service endpoint
|
39
|
+
|
40
|
+
#### Performance Improvements
|
41
|
+
|
42
|
+
* Use MiniMime to detect content types
|
43
|
+
|
44
|
+
#### Documentation
|
45
|
+
|
46
|
+
* Update documentation
|
47
|
+
|
48
|
+
### 1.13.0 / 2019-07-31
|
49
|
+
|
50
|
+
* Add Table#require_partition_filter
|
51
|
+
* List jobs using min and max created_at
|
52
|
+
* Reduce thread usage at startup
|
53
|
+
* Allocate threads in pool as needed, not all up front
|
54
|
+
* Update documentation links
|
55
|
+
|
3
56
|
### 1.12.0 / 2019-07-10
|
4
57
|
|
5
58
|
* Add BigQuery Model API
|
@@ -34,7 +87,7 @@
|
|
34
87
|
* Add copy and extract methods to Project
|
35
88
|
* Add Project#extract and Project#extract_job
|
36
89
|
* Add Project#copy and Project#copy_job
|
37
|
-
* Deprecate dryrun param in Table#copy_job, Table#extract_job and
|
90
|
+
* Deprecate dryrun param in Table#copy_job, Table#extract_job and
|
38
91
|
Table#load_job
|
39
92
|
* Fix memoization in Dataset#exists? and Table#exists?
|
40
93
|
* Add force param to Dataset#exists? and Table#exists?
|
data/LOGGING.md
CHANGED
@@ -6,7 +6,7 @@ Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#l
|
|
6
6
|
library. The logger that you set may be a Ruby stdlib
|
7
7
|
[`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as
|
8
8
|
shown below, or a
|
9
|
-
[`Google::Cloud::Logging::Logger`](https://googleapis.
|
9
|
+
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
10
10
|
that will write logs to [Stackdriver
|
11
11
|
Logging](https://cloud.google.com/logging/).
|
12
12
|
|
data/OVERVIEW.md
CHANGED
@@ -87,7 +87,7 @@ advantages over legacy SQL, including:
|
|
87
87
|
* Complex `JOIN` predicates, including arbitrary expressions
|
88
88
|
|
89
89
|
For examples that demonstrate some of these features, see [Standard SQL
|
90
|
-
ghlights](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-
|
90
|
+
ghlights](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#standard_sql_highlights).
|
91
91
|
|
92
92
|
As shown in this example, standard SQL is the library default:
|
93
93
|
|
@@ -135,4 +135,5 @@ Google::Cloud.configure.add_config! :bigquery do |config|
|
|
135
135
|
config.add_field! :scope, nil, match: [String, Array]
|
136
136
|
config.add_field! :retries, nil, match: Integer
|
137
137
|
config.add_field! :timeout, nil, match: Integer
|
138
|
+
config.add_field! :endpoint, nil, match: String
|
138
139
|
end
|
@@ -51,6 +51,8 @@ module Google
|
|
51
51
|
# @param [Integer] retries Number of times to retry requests on server
|
52
52
|
# error. The default value is `5`. Optional.
|
53
53
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
54
|
+
# @param [String] endpoint Override of the endpoint host name. Optional.
|
55
|
+
# If the param is nil, uses the default endpoint.
|
54
56
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
55
57
|
# @param [String] keyfile Alias for the `credentials` argument.
|
56
58
|
# Deprecated.
|
@@ -65,26 +67,24 @@ module Google
|
|
65
67
|
# table = dataset.table "my_table"
|
66
68
|
#
|
67
69
|
def self.new project_id: nil, credentials: nil, scope: nil, retries: nil,
|
68
|
-
timeout: nil, project: nil, keyfile: nil
|
69
|
-
project_id ||= (project || default_project_id)
|
70
|
+
timeout: nil, endpoint: nil, project: nil, keyfile: nil
|
70
71
|
scope ||= configure.scope
|
71
72
|
retries ||= configure.retries
|
72
73
|
timeout ||= configure.timeout
|
74
|
+
endpoint ||= configure.endpoint
|
73
75
|
credentials ||= (keyfile || default_credentials(scope: scope))
|
74
76
|
|
75
77
|
unless credentials.is_a? Google::Auth::Credentials
|
76
78
|
credentials = Bigquery::Credentials.new credentials, scope: scope
|
77
79
|
end
|
78
80
|
|
79
|
-
|
80
|
-
project_id ||= credentials.project_id
|
81
|
-
end
|
82
|
-
project_id = project_id.to_s # Always cast to a string
|
81
|
+
project_id = resolve_project_id(project_id || project, credentials)
|
83
82
|
raise ArgumentError, "project_id is missing" if project_id.empty?
|
84
83
|
|
85
84
|
Bigquery::Project.new(
|
86
85
|
Bigquery::Service.new(
|
87
|
-
project_id, credentials,
|
86
|
+
project_id, credentials,
|
87
|
+
retries: retries, timeout: timeout, host: endpoint
|
88
88
|
)
|
89
89
|
)
|
90
90
|
end
|
@@ -100,6 +100,8 @@ module Google
|
|
100
100
|
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
101
101
|
# Google::Auth::Credentials object. (See {Bigquery::Credentials}) (The
|
102
102
|
# parameter `keyfile` is considered deprecated, but may also be used.)
|
103
|
+
# * `endpoint` - (String) Override of the endpoint host name, or `nil`
|
104
|
+
# to use the default endpoint.
|
103
105
|
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
104
106
|
# the set of resources and operations that the connection can access.
|
105
107
|
# * `retries` - (Integer) Number of times to retry requests on server
|
@@ -115,6 +117,16 @@ module Google
|
|
115
117
|
Google::Cloud.configure.bigquery
|
116
118
|
end
|
117
119
|
|
120
|
+
##
|
121
|
+
# @private Resolve project.
|
122
|
+
def self.resolve_project_id given_project, credentials
|
123
|
+
project_id = given_project || default_project_id
|
124
|
+
if credentials.respond_to? :project_id
|
125
|
+
project_id ||= credentials.project_id
|
126
|
+
end
|
127
|
+
project_id.to_s # Always cast to a string
|
128
|
+
end
|
129
|
+
|
118
130
|
##
|
119
131
|
# @private Default project.
|
120
132
|
def self.default_project_id
|
@@ -335,6 +335,77 @@ module Google
|
|
335
335
|
patch_gapi! :labels
|
336
336
|
end
|
337
337
|
|
338
|
+
##
|
339
|
+
# The {EncryptionConfiguration} object that represents the default
|
340
|
+
# encryption method for all tables and models in the dataset. Once this
|
341
|
+
# property is set, all newly-created partitioned tables and models in
|
342
|
+
# the dataset will have their encryption set to this value, unless table
|
343
|
+
# creation request (or query) overrides it.
|
344
|
+
#
|
345
|
+
# Present only if this dataset is using custom default encryption.
|
346
|
+
#
|
347
|
+
# @see https://cloud.google.com/bigquery/docs/customer-managed-encryption
|
348
|
+
# Protecting Data with Cloud KMS Keys
|
349
|
+
#
|
350
|
+
# @return [EncryptionConfiguration, nil] The default encryption
|
351
|
+
# configuration.
|
352
|
+
#
|
353
|
+
# @!group Attributes
|
354
|
+
#
|
355
|
+
# @example
|
356
|
+
# require "google/cloud/bigquery"
|
357
|
+
#
|
358
|
+
# bigquery = Google::Cloud::Bigquery.new
|
359
|
+
# dataset = bigquery.dataset "my_dataset"
|
360
|
+
#
|
361
|
+
# encrypt_config = dataset.default_encryption
|
362
|
+
#
|
363
|
+
# @!group Attributes
|
364
|
+
#
|
365
|
+
def default_encryption
|
366
|
+
return nil if reference?
|
367
|
+
ensure_full_data!
|
368
|
+
return nil if @gapi.default_encryption_configuration.nil?
|
369
|
+
EncryptionConfiguration.from_gapi(
|
370
|
+
@gapi.default_encryption_configuration
|
371
|
+
).freeze
|
372
|
+
end
|
373
|
+
|
374
|
+
##
|
375
|
+
# Set the {EncryptionConfiguration} object that represents the default
|
376
|
+
# encryption method for all tables and models in the dataset. Once this
|
377
|
+
# property is set, all newly-created partitioned tables and models in
|
378
|
+
# the dataset will have their encryption set to this value, unless table
|
379
|
+
# creation request (or query) overrides it.
|
380
|
+
#
|
381
|
+
# If the dataset is not a full resource representation (see
|
382
|
+
# {#resource_full?}), the full representation will be retrieved before
|
383
|
+
# the update to comply with ETag-based optimistic concurrency control.
|
384
|
+
#
|
385
|
+
# @see https://cloud.google.com/bigquery/docs/customer-managed-encryption
|
386
|
+
# Protecting Data with Cloud KMS Keys
|
387
|
+
#
|
388
|
+
# @param [EncryptionConfiguration] value The new encryption config.
|
389
|
+
#
|
390
|
+
# @example
|
391
|
+
# require "google/cloud/bigquery"
|
392
|
+
#
|
393
|
+
# bigquery = Google::Cloud::Bigquery.new
|
394
|
+
# dataset = bigquery.dataset "my_dataset"
|
395
|
+
#
|
396
|
+
# key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"
|
397
|
+
# encrypt_config = bigquery.encryption kms_key: key_name
|
398
|
+
#
|
399
|
+
# dataset.default_encryption = encrypt_config
|
400
|
+
#
|
401
|
+
# @!group Attributes
|
402
|
+
#
|
403
|
+
def default_encryption= value
|
404
|
+
ensure_full_data!
|
405
|
+
@gapi.default_encryption_configuration = value.to_gapi
|
406
|
+
patch_gapi! :default_encryption_configuration
|
407
|
+
end
|
408
|
+
|
338
409
|
##
|
339
410
|
# Retrieves the access rules for a Dataset. The rules can be updated
|
340
411
|
# when passing a block, see {Dataset::Access} for all the methods
|
@@ -1953,9 +2024,18 @@ module Google
|
|
1953
2024
|
# the need to complete a load operation before the data can appear in
|
1954
2025
|
# query results.
|
1955
2026
|
#
|
2027
|
+
# Because BigQuery's streaming API is designed for high insertion rates,
|
2028
|
+
# modifications to the underlying table metadata are eventually
|
2029
|
+
# consistent when interacting with the streaming system. In most cases
|
2030
|
+
# metadata changes are propagated within minutes, but during this period
|
2031
|
+
# API responses may reflect the inconsistent state of the table.
|
2032
|
+
#
|
1956
2033
|
# @see https://cloud.google.com/bigquery/streaming-data-into-bigquery
|
1957
2034
|
# Streaming Data Into BigQuery
|
1958
2035
|
#
|
2036
|
+
# @see https://cloud.google.com/bigquery/troubleshooting-errors#metadata-errors-for-streaming-inserts
|
2037
|
+
# BigQuery Troubleshooting: Metadata errors for streaming inserts
|
2038
|
+
#
|
1959
2039
|
# @param [String] table_id The ID of the destination table.
|
1960
2040
|
# @param [Hash, Array<Hash>] rows A hash object or array of hash objects
|
1961
2041
|
# containing the data. Required.
|
@@ -2172,7 +2252,7 @@ module Google
|
|
2172
2252
|
# Load the complete representation of the dataset if it has been
|
2173
2253
|
# only partially loaded by a request to the API list method.
|
2174
2254
|
def ensure_full_data!
|
2175
|
-
reload!
|
2255
|
+
reload! unless resource_full?
|
2176
2256
|
end
|
2177
2257
|
|
2178
2258
|
def ensure_job_succeeded! job
|
@@ -1224,6 +1224,52 @@ module Google
|
|
1224
1224
|
frozen_check!
|
1225
1225
|
@gapi.google_sheets_options.skip_leading_rows = row_count
|
1226
1226
|
end
|
1227
|
+
|
1228
|
+
##
|
1229
|
+
# Range of a sheet to query from. Only used when non-empty. Typical
|
1230
|
+
# format: `{sheet_name}!{top_left_cell_id}:{bottom_right_cell_id}`.
|
1231
|
+
#
|
1232
|
+
# @return [String] Range of a sheet to query from.
|
1233
|
+
#
|
1234
|
+
# @example
|
1235
|
+
# require "google/cloud/bigquery"
|
1236
|
+
#
|
1237
|
+
# bigquery = Google::Cloud::Bigquery.new
|
1238
|
+
#
|
1239
|
+
# sheets_url = "https://docs.google.com/spreadsheets/d/1234567980"
|
1240
|
+
# sheets_table = bigquery.external sheets_url do |sheets|
|
1241
|
+
# sheets.range = "sheet1!A1:B20"
|
1242
|
+
# end
|
1243
|
+
#
|
1244
|
+
# sheets_table.range #=> "sheet1!A1:B20"
|
1245
|
+
#
|
1246
|
+
def range
|
1247
|
+
@gapi.google_sheets_options.range
|
1248
|
+
end
|
1249
|
+
|
1250
|
+
##
|
1251
|
+
# Set the range of a sheet to query from. Only used when non-empty.
|
1252
|
+
# Typical format:
|
1253
|
+
# `{sheet_name}!{top_left_cell_id}:{bottom_right_cell_id}`.
|
1254
|
+
#
|
1255
|
+
# @param [String] new_range New range of a sheet to query from.
|
1256
|
+
#
|
1257
|
+
# @example
|
1258
|
+
# require "google/cloud/bigquery"
|
1259
|
+
#
|
1260
|
+
# bigquery = Google::Cloud::Bigquery.new
|
1261
|
+
#
|
1262
|
+
# sheets_url = "https://docs.google.com/spreadsheets/d/1234567980"
|
1263
|
+
# sheets_table = bigquery.external sheets_url do |sheets|
|
1264
|
+
# sheets.range = "sheet1!A1:B20"
|
1265
|
+
# end
|
1266
|
+
#
|
1267
|
+
# sheets_table.range #=> "sheet1!A1:B20"
|
1268
|
+
#
|
1269
|
+
def range= new_range
|
1270
|
+
frozen_check!
|
1271
|
+
@gapi.google_sheets_options.range = new_range
|
1272
|
+
end
|
1227
1273
|
end
|
1228
1274
|
|
1229
1275
|
##
|
@@ -156,6 +156,20 @@ module Google
|
|
156
156
|
Hash[destinations.zip destinations_file_counts]
|
157
157
|
end
|
158
158
|
|
159
|
+
##
|
160
|
+
# If `#avro?` (`#format` is set to `"AVRO"`), this flag indicates
|
161
|
+
# whether to enable extracting applicable column types (such as
|
162
|
+
# `TIMESTAMP`) to their corresponding AVRO logical types
|
163
|
+
# (`timestamp-micros`), instead of only using their raw types
|
164
|
+
# (`avro-long`).
|
165
|
+
#
|
166
|
+
# @return [Boolean] `true` when applicable column types will use their
|
167
|
+
# corresponding AVRO logical types, `false` otherwise.
|
168
|
+
#
|
169
|
+
def use_avro_logical_types?
|
170
|
+
@gapi.configuration.extract.use_avro_logical_types
|
171
|
+
end
|
172
|
+
|
159
173
|
##
|
160
174
|
# Yielded to a block to accumulate changes for an API request.
|
161
175
|
class Updater < ExtractJob
|
@@ -175,11 +189,8 @@ module Google
|
|
175
189
|
storage_urls = Array(storage_files).map do |url|
|
176
190
|
url.respond_to?(:to_gs_url) ? url.to_gs_url : url
|
177
191
|
end
|
178
|
-
|
179
|
-
|
180
|
-
dest_format = Convert.derive_source_format storage_urls.first
|
181
|
-
end
|
182
|
-
req = Google::Apis::BigqueryV2::Job.new(
|
192
|
+
options[:format] ||= Convert.derive_source_format storage_urls.first
|
193
|
+
job = Google::Apis::BigqueryV2::Job.new(
|
183
194
|
job_reference: job_ref,
|
184
195
|
configuration: Google::Apis::BigqueryV2::JobConfiguration.new(
|
185
196
|
extract: Google::Apis::BigqueryV2::JobConfigurationExtract.new(
|
@@ -190,12 +201,24 @@ module Google
|
|
190
201
|
)
|
191
202
|
)
|
192
203
|
|
193
|
-
|
204
|
+
from_job_and_options job, options
|
205
|
+
end
|
206
|
+
|
207
|
+
##
|
208
|
+
# @private Create an Updater from a Job and options hash.
|
209
|
+
#
|
210
|
+
# @return [Google::Cloud::Bigquery::ExtractJob::Updater] A job
|
211
|
+
# configuration object for setting query options.
|
212
|
+
def self.from_job_and_options request, options = {}
|
213
|
+
updater = ExtractJob::Updater.new request
|
194
214
|
updater.compression = options[:compression]
|
195
215
|
updater.delimiter = options[:delimiter]
|
196
|
-
updater.format =
|
216
|
+
updater.format = options[:format]
|
197
217
|
updater.header = options[:header]
|
198
218
|
updater.labels = options[:labels] if options[:labels]
|
219
|
+
unless options[:use_avro_logical_types].nil?
|
220
|
+
updater.use_avro_logical_types = options[:use_avro_logical_types]
|
221
|
+
end
|
199
222
|
updater
|
200
223
|
end
|
201
224
|
|
@@ -300,6 +323,22 @@ module Google
|
|
300
323
|
@gapi.configuration.update! labels: value
|
301
324
|
end
|
302
325
|
|
326
|
+
##
|
327
|
+
# Indicate whether to enable extracting applicable column types (such
|
328
|
+
# as `TIMESTAMP`) to their corresponding AVRO logical types
|
329
|
+
# (`timestamp-micros`), instead of only using their raw types
|
330
|
+
# (`avro-long`).
|
331
|
+
#
|
332
|
+
# Only used when `#format` is set to `"AVRO"` (`#avro?`).
|
333
|
+
#
|
334
|
+
# @param [Boolean] value Whether applicable column types will use
|
335
|
+
# their corresponding AVRO logical types.
|
336
|
+
#
|
337
|
+
# @!group Attributes
|
338
|
+
def use_avro_logical_types= value
|
339
|
+
@gapi.configuration.extract.use_avro_logical_types = value
|
340
|
+
end
|
341
|
+
|
303
342
|
##
|
304
343
|
# @private Returns the Google API client library version of this job.
|
305
344
|
#
|
@@ -71,9 +71,9 @@ module Google
|
|
71
71
|
def next
|
72
72
|
return nil unless next?
|
73
73
|
ensure_service!
|
74
|
-
|
75
|
-
|
76
|
-
self.class.from_gapi
|
74
|
+
next_options = @options.merge token: token
|
75
|
+
next_gapi = @service.list_jobs next_options
|
76
|
+
self.class.from_gapi next_gapi, @service, next_options
|
77
77
|
end
|
78
78
|
|
79
79
|
##
|
@@ -141,17 +141,14 @@ module Google
|
|
141
141
|
##
|
142
142
|
# @private New Job::List from a Google API Client
|
143
143
|
# Google::Apis::BigqueryV2::JobList object.
|
144
|
-
def self.from_gapi gapi_list, service,
|
145
|
-
filter = nil
|
144
|
+
def self.from_gapi gapi_list, service, options = {}
|
146
145
|
jobs = List.new(Array(gapi_list.jobs).map do |gapi_object|
|
147
146
|
Job.from_gapi gapi_object, service
|
148
147
|
end)
|
149
|
-
jobs.instance_variable_set :@token,
|
150
|
-
jobs.instance_variable_set :@etag,
|
151
|
-
jobs.instance_variable_set :@service,
|
152
|
-
jobs.instance_variable_set :@
|
153
|
-
jobs.instance_variable_set :@max, max
|
154
|
-
jobs.instance_variable_set :@filter, filter
|
148
|
+
jobs.instance_variable_set :@token, gapi_list.next_page_token
|
149
|
+
jobs.instance_variable_set :@etag, gapi_list.etag
|
150
|
+
jobs.instance_variable_set :@service, service
|
151
|
+
jobs.instance_variable_set :@options, options
|
155
152
|
jobs
|
156
153
|
end
|
157
154
|
|
@@ -366,6 +366,82 @@ module Google
|
|
366
366
|
patch_gapi! labels: new_labels
|
367
367
|
end
|
368
368
|
|
369
|
+
##
|
370
|
+
# The {EncryptionConfiguration} object that represents the custom
|
371
|
+
# encryption method used to protect this model. If not set,
|
372
|
+
# {Dataset#default_encryption} is used.
|
373
|
+
#
|
374
|
+
# Present only if this model is using custom encryption.
|
375
|
+
#
|
376
|
+
# @see https://cloud.google.com/bigquery/docs/customer-managed-encryption
|
377
|
+
# Protecting Data with Cloud KMS Keys
|
378
|
+
#
|
379
|
+
# @return [EncryptionConfiguration, nil] The encryption configuration.
|
380
|
+
#
|
381
|
+
# @!group Attributes
|
382
|
+
#
|
383
|
+
# @example
|
384
|
+
# require "google/cloud/bigquery"
|
385
|
+
#
|
386
|
+
# bigquery = Google::Cloud::Bigquery.new
|
387
|
+
# dataset = bigquery.dataset "my_dataset"
|
388
|
+
# model = dataset.model "my_model"
|
389
|
+
#
|
390
|
+
# encrypt_config = model.encryption
|
391
|
+
#
|
392
|
+
# @!group Attributes
|
393
|
+
#
|
394
|
+
def encryption
|
395
|
+
return nil if reference?
|
396
|
+
return nil if @gapi_json[:encryptionConfiguration].nil?
|
397
|
+
# We have to create a gapic object from the hash because that is what
|
398
|
+
# EncryptionConfiguration is expecing.
|
399
|
+
json_cmek = @gapi_json[:encryptionConfiguration].to_json
|
400
|
+
gapi_cmek = \
|
401
|
+
Google::Apis::BigqueryV2::EncryptionConfiguration.from_json(
|
402
|
+
json_cmek
|
403
|
+
)
|
404
|
+
EncryptionConfiguration.from_gapi(gapi_cmek).freeze
|
405
|
+
end
|
406
|
+
|
407
|
+
##
|
408
|
+
# Set the {EncryptionConfiguration} object that represents the custom
|
409
|
+
# encryption method used to protect this model. If not set,
|
410
|
+
# {Dataset#default_encryption} is used.
|
411
|
+
#
|
412
|
+
# Present only if this model is using custom encryption.
|
413
|
+
#
|
414
|
+
# If the model is not a full resource representation (see
|
415
|
+
# {#resource_full?}), the full representation will be retrieved before
|
416
|
+
# the update to comply with ETag-based optimistic concurrency control.
|
417
|
+
#
|
418
|
+
# @see https://cloud.google.com/bigquery/docs/customer-managed-encryption
|
419
|
+
# Protecting Data with Cloud KMS Keys
|
420
|
+
#
|
421
|
+
# @param [EncryptionConfiguration] value The new encryption config.
|
422
|
+
#
|
423
|
+
# @example
|
424
|
+
# require "google/cloud/bigquery"
|
425
|
+
#
|
426
|
+
# bigquery = Google::Cloud::Bigquery.new
|
427
|
+
# dataset = bigquery.dataset "my_dataset"
|
428
|
+
# model = dataset.model "my_model"
|
429
|
+
#
|
430
|
+
# key_name = "projects/a/locations/b/keyRings/c/cryptoKeys/d"
|
431
|
+
# encrypt_config = bigquery.encryption kms_key: key_name
|
432
|
+
#
|
433
|
+
# model.encryption = encrypt_config
|
434
|
+
#
|
435
|
+
# @!group Attributes
|
436
|
+
#
|
437
|
+
def encryption= value
|
438
|
+
ensure_full_data!
|
439
|
+
# We have to create a hash from the gapic object's JSON because that
|
440
|
+
# is what Model is expecing.
|
441
|
+
json_cmek = JSON.parse value.to_gapi.to_json, symbolize_names: true
|
442
|
+
patch_gapi! encryptionConfiguration: json_cmek
|
443
|
+
end
|
444
|
+
|
369
445
|
##
|
370
446
|
# The input feature columns that were used to train this model.
|
371
447
|
#
|
@@ -1024,11 +1024,17 @@ module Google
|
|
1024
1024
|
# Retrieves the list of jobs belonging to the project.
|
1025
1025
|
#
|
1026
1026
|
# @param [Boolean] all Whether to display jobs owned by all users in the
|
1027
|
-
# project. The default is `false`.
|
1027
|
+
# project. The default is `false`. Optional.
|
1028
1028
|
# @param [String] token A previously-returned page token representing
|
1029
|
-
# part of the larger set of results to view.
|
1030
|
-
# @param [Integer] max Maximum number of jobs to return.
|
1031
|
-
# @param [String] filter A filter for job state.
|
1029
|
+
# part of the larger set of results to view. Optional.
|
1030
|
+
# @param [Integer] max Maximum number of jobs to return. Optional.
|
1031
|
+
# @param [String] filter A filter for job state. Optional.
|
1032
|
+
# @param [Time] min_created_at Min value for {Job#created_at}. When
|
1033
|
+
# provided, only jobs created after or at this time are returned.
|
1034
|
+
# Optional.
|
1035
|
+
# @param [Time] max_created_at Max value for {Job#created_at}. When
|
1036
|
+
# provided, only jobs created before or at this time are returned.
|
1037
|
+
# Optional.
|
1032
1038
|
#
|
1033
1039
|
# Acceptable values are:
|
1034
1040
|
#
|
@@ -1059,6 +1065,20 @@ module Google
|
|
1059
1065
|
# # process job
|
1060
1066
|
# end
|
1061
1067
|
#
|
1068
|
+
# @example Retrieve only jobs created within provided times:
|
1069
|
+
# require "google/cloud/bigquery"
|
1070
|
+
#
|
1071
|
+
# bigquery = Google::Cloud::Bigquery.new
|
1072
|
+
#
|
1073
|
+
# two_days_ago = Time.now - 60*60*24*2
|
1074
|
+
# three_days_ago = Time.now - 60*60*24*3
|
1075
|
+
#
|
1076
|
+
# jobs = bigquery.jobs min_created_at: three_days_ago,
|
1077
|
+
# max_created_at: two_days_ago
|
1078
|
+
# jobs.each do |job|
|
1079
|
+
# # process job
|
1080
|
+
# end
|
1081
|
+
#
|
1062
1082
|
# @example Retrieve all jobs: (See {Job::List#all})
|
1063
1083
|
# require "google/cloud/bigquery"
|
1064
1084
|
#
|
@@ -1069,11 +1089,15 @@ module Google
|
|
1069
1089
|
# # process job
|
1070
1090
|
# end
|
1071
1091
|
#
|
1072
|
-
def jobs all: nil, token: nil, max: nil, filter: nil
|
1092
|
+
def jobs all: nil, token: nil, max: nil, filter: nil,
|
1093
|
+
min_created_at: nil, max_created_at: nil
|
1073
1094
|
ensure_service!
|
1074
|
-
options = {
|
1095
|
+
options = {
|
1096
|
+
all: all, token: token, max: max, filter: filter,
|
1097
|
+
min_created_at: min_created_at, max_created_at: max_created_at
|
1098
|
+
}
|
1075
1099
|
gapi = service.list_jobs options
|
1076
|
-
Job::List.from_gapi gapi, service,
|
1100
|
+
Job::List.from_gapi gapi, service, options
|
1077
1101
|
end
|
1078
1102
|
|
1079
1103
|
##
|
@@ -19,7 +19,7 @@ require "google/cloud/errors"
|
|
19
19
|
require "google/apis/bigquery_v2"
|
20
20
|
require "pathname"
|
21
21
|
require "securerandom"
|
22
|
-
require "
|
22
|
+
require "mini_mime"
|
23
23
|
require "date"
|
24
24
|
|
25
25
|
module Google
|
@@ -39,15 +39,17 @@ module Google
|
|
39
39
|
attr_accessor :credentials
|
40
40
|
|
41
41
|
# @private
|
42
|
-
attr_reader :retries, :timeout
|
42
|
+
attr_reader :retries, :timeout, :host
|
43
43
|
|
44
44
|
##
|
45
45
|
# Creates a new Service instance.
|
46
|
-
def initialize project, credentials,
|
46
|
+
def initialize project, credentials,
|
47
|
+
retries: nil, timeout: nil, host: nil
|
47
48
|
@project = project
|
48
49
|
@credentials = credentials
|
49
50
|
@retries = retries
|
50
51
|
@timeout = timeout
|
52
|
+
@host = host
|
51
53
|
end
|
52
54
|
|
53
55
|
def service
|
@@ -65,6 +67,7 @@ module Google
|
|
65
67
|
service.request_options.header["x-goog-api-client"] = \
|
66
68
|
"gl-ruby/#{RUBY_VERSION} gccl/#{Google::Cloud::Bigquery::VERSION}"
|
67
69
|
service.authorization = @credentials.client
|
70
|
+
service.root_url = host if host
|
68
71
|
service
|
69
72
|
end
|
70
73
|
end
|
@@ -297,11 +300,15 @@ module Google
|
|
297
300
|
# been granted the READER job role.
|
298
301
|
def list_jobs options = {}
|
299
302
|
# The list operation is considered idempotent
|
303
|
+
min_creation_time = Convert.time_to_millis options[:min_created_at]
|
304
|
+
max_creation_time = Convert.time_to_millis options[:max_created_at]
|
300
305
|
execute backoff: true do
|
301
306
|
service.list_jobs \
|
302
307
|
@project, all_users: options[:all], max_results: options[:max],
|
303
308
|
page_token: options[:token], projection: "full",
|
304
|
-
state_filter: options[:filter]
|
309
|
+
state_filter: options[:filter],
|
310
|
+
min_creation_time: min_creation_time,
|
311
|
+
max_creation_time: max_creation_time
|
305
312
|
end
|
306
313
|
end
|
307
314
|
|
@@ -476,9 +483,9 @@ module Google
|
|
476
483
|
end
|
477
484
|
|
478
485
|
def mime_type_for file
|
479
|
-
mime_type =
|
480
|
-
return nil if mime_type.
|
481
|
-
mime_type
|
486
|
+
mime_type = MiniMime.lookup_by_filename Pathname(file).to_path
|
487
|
+
return nil if mime_type.nil?
|
488
|
+
mime_type.content_type
|
482
489
|
rescue StandardError
|
483
490
|
nil
|
484
491
|
end
|
@@ -325,6 +325,52 @@ module Google
|
|
325
325
|
patch_gapi! :time_partitioning
|
326
326
|
end
|
327
327
|
|
328
|
+
###
|
329
|
+
# Whether queries over this table require a partition filter that can be
|
330
|
+
# used for partition elimination to be specified. See [Partitioned
|
331
|
+
# Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
|
332
|
+
#
|
333
|
+
# @return [Boolean, nil] `true` when a partition filter will be
|
334
|
+
# required, `false` otherwise, or `nil` if the object is a reference
|
335
|
+
# (see {#reference?}).
|
336
|
+
#
|
337
|
+
# @!group Attributes
|
338
|
+
#
|
339
|
+
def require_partition_filter
|
340
|
+
return nil if reference?
|
341
|
+
ensure_full_data!
|
342
|
+
@gapi.require_partition_filter
|
343
|
+
end
|
344
|
+
|
345
|
+
##
|
346
|
+
# Sets whether queries over this table require a partition filter. See
|
347
|
+
# [Partitioned
|
348
|
+
# Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
|
349
|
+
#
|
350
|
+
# If the table is not a full resource representation (see
|
351
|
+
# {#resource_full?}), the full representation will be retrieved before
|
352
|
+
# the update to comply with ETag-based optimistic concurrency control.
|
353
|
+
#
|
354
|
+
# @param [Boolean] new_require Whether queries over this table require a
|
355
|
+
# partition filter.
|
356
|
+
#
|
357
|
+
# @example
|
358
|
+
# require "google/cloud/bigquery"
|
359
|
+
#
|
360
|
+
# bigquery = Google::Cloud::Bigquery.new
|
361
|
+
# dataset = bigquery.dataset "my_dataset"
|
362
|
+
# table = dataset.create_table "my_table" do |table|
|
363
|
+
# table.require_partition_filter = true
|
364
|
+
# end
|
365
|
+
#
|
366
|
+
# @!group Attributes
|
367
|
+
#
|
368
|
+
def require_partition_filter= new_require
|
369
|
+
reload! unless resource_full?
|
370
|
+
@gapi.require_partition_filter = new_require
|
371
|
+
patch_gapi! :require_partition_filter
|
372
|
+
end
|
373
|
+
|
328
374
|
###
|
329
375
|
# Checks if the table is clustered.
|
330
376
|
#
|
@@ -829,8 +875,8 @@ module Google
|
|
829
875
|
|
830
876
|
##
|
831
877
|
# The {EncryptionConfiguration} object that represents the custom
|
832
|
-
# encryption method used to protect the table. If not set,
|
833
|
-
#
|
878
|
+
# encryption method used to protect the table. If not set,
|
879
|
+
# {Dataset#default_encryption} is used.
|
834
880
|
#
|
835
881
|
# Present only if the table is using custom encryption.
|
836
882
|
#
|
@@ -851,8 +897,8 @@ module Google
|
|
851
897
|
|
852
898
|
##
|
853
899
|
# Set the {EncryptionConfiguration} object that represents the custom
|
854
|
-
# encryption method used to protect the table. If not set,
|
855
|
-
#
|
900
|
+
# encryption method used to protect the table. If not set,
|
901
|
+
# {Dataset#default_encryption} is used.
|
856
902
|
#
|
857
903
|
# Present only if the table is using custom encryption.
|
858
904
|
#
|
@@ -860,7 +906,6 @@ module Google
|
|
860
906
|
# {#resource_full?}), the full representation will be retrieved before
|
861
907
|
# the update to comply with ETag-based optimistic concurrency control.
|
862
908
|
#
|
863
|
-
#
|
864
909
|
# @see https://cloud.google.com/bigquery/docs/customer-managed-encryption
|
865
910
|
# Protecting Data with Cloud KMS Keys
|
866
911
|
#
|
@@ -1926,9 +1971,18 @@ module Google
|
|
1926
1971
|
# need to complete a load operation before the data can appear in query
|
1927
1972
|
# results.
|
1928
1973
|
#
|
1974
|
+
# Because BigQuery's streaming API is designed for high insertion rates,
|
1975
|
+
# modifications to the underlying table metadata are eventually
|
1976
|
+
# consistent when interacting with the streaming system. In most cases
|
1977
|
+
# metadata changes are propagated within minutes, but during this period
|
1978
|
+
# API responses may reflect the inconsistent state of the table.
|
1979
|
+
#
|
1929
1980
|
# @see https://cloud.google.com/bigquery/streaming-data-into-bigquery
|
1930
1981
|
# Streaming Data Into BigQuery
|
1931
1982
|
#
|
1983
|
+
# @see https://cloud.google.com/bigquery/troubleshooting-errors#metadata-errors-for-streaming-inserts
|
1984
|
+
# BigQuery Troubleshooting: Metadata errors for streaming inserts
|
1985
|
+
#
|
1932
1986
|
# @param [Hash, Array<Hash>] rows A hash object or array of hash objects
|
1933
1987
|
# containing the data. Required.
|
1934
1988
|
# @param [Array<String>] insert_ids A unique ID for each row. BigQuery
|
@@ -86,7 +86,8 @@ module Google
|
|
86
86
|
|
87
87
|
@batch = nil
|
88
88
|
|
89
|
-
@thread_pool = Concurrent::
|
89
|
+
@thread_pool = Concurrent::ThreadPoolExecutor.new \
|
90
|
+
max_threads: @threads
|
90
91
|
|
91
92
|
@cond = new_cond
|
92
93
|
|
@@ -99,6 +100,19 @@ module Google
|
|
99
100
|
# collected in batches and inserted together.
|
100
101
|
# See {Google::Cloud::Bigquery::Table#insert_async}.
|
101
102
|
#
|
103
|
+
# Because BigQuery's streaming API is designed for high insertion
|
104
|
+
# rates, modifications to the underlying table metadata are eventually
|
105
|
+
# consistent when interacting with the streaming system. In most cases
|
106
|
+
# metadata changes are propagated within minutes, but during this
|
107
|
+
# period API responses may reflect the inconsistent state of the
|
108
|
+
# table.
|
109
|
+
#
|
110
|
+
# @see https://cloud.google.com/bigquery/streaming-data-into-bigquery
|
111
|
+
# Streaming Data Into BigQuery
|
112
|
+
#
|
113
|
+
# @see https://cloud.google.com/bigquery/troubleshooting-errors#metadata-errors-for-streaming-inserts
|
114
|
+
# BigQuery Troubleshooting: Metadata errors for streaming inserts
|
115
|
+
#
|
102
116
|
# @param [Hash, Array<Hash>] rows A hash object or array of hash
|
103
117
|
# objects containing the data.
|
104
118
|
# @param [Array<String>] insert_ids A unique ID for each row. BigQuery
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-bigquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.16.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: 2019-
|
12
|
+
date: 2019-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0.
|
34
|
+
version: '0.31'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.31'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: googleauth
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,19 +74,19 @@ dependencies:
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.0'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
77
|
+
name: mini_mime
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.0'
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.0'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: minitest
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
293
|
- !ruby/object:Gem::Version
|
294
294
|
version: '0'
|
295
295
|
requirements: []
|
296
|
-
rubygems_version: 3.0.
|
296
|
+
rubygems_version: 3.0.4
|
297
297
|
signing_key:
|
298
298
|
specification_version: 4
|
299
299
|
summary: API Client library for Google BigQuery
|