google-cloud-bigquery 1.28.0 → 1.32.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +2 -1
  3. data/CHANGELOG.md +51 -0
  4. data/CONTRIBUTING.md +3 -4
  5. data/LOGGING.md +1 -1
  6. data/OVERVIEW.md +15 -14
  7. data/lib/google/cloud/bigquery/convert.rb +72 -76
  8. data/lib/google/cloud/bigquery/copy_job.rb +1 -0
  9. data/lib/google/cloud/bigquery/data.rb +2 -2
  10. data/lib/google/cloud/bigquery/dataset.rb +85 -53
  11. data/lib/google/cloud/bigquery/dataset/access.rb +3 -3
  12. data/lib/google/cloud/bigquery/dataset/list.rb +2 -2
  13. data/lib/google/cloud/bigquery/external.rb +9 -2619
  14. data/lib/google/cloud/bigquery/external/bigtable_source.rb +230 -0
  15. data/lib/google/cloud/bigquery/external/bigtable_source/column.rb +404 -0
  16. data/lib/google/cloud/bigquery/external/bigtable_source/column_family.rb +945 -0
  17. data/lib/google/cloud/bigquery/external/csv_source.rb +481 -0
  18. data/lib/google/cloud/bigquery/external/data_source.rb +771 -0
  19. data/lib/google/cloud/bigquery/external/json_source.rb +170 -0
  20. data/lib/google/cloud/bigquery/external/parquet_source.rb +148 -0
  21. data/lib/google/cloud/bigquery/external/sheets_source.rb +166 -0
  22. data/lib/google/cloud/bigquery/extract_job.rb +4 -2
  23. data/lib/google/cloud/bigquery/job.rb +9 -3
  24. data/lib/google/cloud/bigquery/job/list.rb +4 -4
  25. data/lib/google/cloud/bigquery/load_job.rb +178 -19
  26. data/lib/google/cloud/bigquery/model/list.rb +2 -2
  27. data/lib/google/cloud/bigquery/policy.rb +2 -1
  28. data/lib/google/cloud/bigquery/project.rb +46 -41
  29. data/lib/google/cloud/bigquery/project/list.rb +2 -2
  30. data/lib/google/cloud/bigquery/query_job.rb +84 -62
  31. data/lib/google/cloud/bigquery/routine.rb +1 -4
  32. data/lib/google/cloud/bigquery/routine/list.rb +2 -2
  33. data/lib/google/cloud/bigquery/schema.rb +39 -3
  34. data/lib/google/cloud/bigquery/schema/field.rb +63 -13
  35. data/lib/google/cloud/bigquery/service.rb +11 -13
  36. data/lib/google/cloud/bigquery/standard_sql.rb +15 -3
  37. data/lib/google/cloud/bigquery/table.rb +166 -33
  38. data/lib/google/cloud/bigquery/table/async_inserter.rb +44 -17
  39. data/lib/google/cloud/bigquery/table/list.rb +2 -2
  40. data/lib/google/cloud/bigquery/version.rb +1 -1
  41. metadata +28 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44443c8c7fdf80fdfc611bba7ffcad2469ef60ff3aef8899f56a07fb4ced8555
4
- data.tar.gz: 3b3f3020b6c4eebfa1a2a974f6d047068bd5d7f114b5d8c843c31401108b15b1
3
+ metadata.gz: 1189f91eb3d437aa9fa866f22bf19acaa4f5c1e1f6fec69e73ababe8d1297bdc
4
+ data.tar.gz: 8d448952cc259e89076d6edf501c5b9ea3caf6b20b21fae9bcfe8056016549e0
5
5
  SHA512:
6
- metadata.gz: 5fb27c2d28ebb83a3f28a11241b7b260373dceade40159df44e31d6ab5de016079a00ddeba6943a09a6c7f8d303d08a24ca665160cd480b95f314382c2e45943
7
- data.tar.gz: cf98a8d90c55cf065265c094a74ccf9f421a89e1c459b05189d4a7b33c8d97c9304c0e7256729de190a9bc7f74195fd6cff9170748cfb3bc4732a297f902b320
6
+ metadata.gz: 3f734ba5d4a6e7323ba88dd11c5ead491401e538b08c87fd91bc95ad069e61ab952cd8b3e8e6da0fa436f9ce9ff8338e81e274cfd97defe21a8981796049e6ba
7
+ data.tar.gz: ef0a1fba42f761d313d71eaaca71ddfbae322d18f5a747cc24a596a0a804625568cac87434390dc8f5ff208001487e33c824c1015d654ee0967d5bebcefa34d6
data/AUTHENTICATION.md CHANGED
@@ -77,7 +77,8 @@ bigquery = Google::Cloud::Bigquery.new
77
77
 
78
78
  ### Configuration
79
79
 
80
- The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
80
+ The **Project ID** and the path to the **Credentials JSON** file can be configured
81
+ instead of placing them in environment variables or providing them as arguments.
81
82
 
82
83
  ```ruby
83
84
  require "google/cloud/bigquery"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Release History
2
2
 
3
+ ### 1.32.1 / 2021-07-08
4
+
5
+ #### Documentation
6
+
7
+ * Update AUTHENTICATION.md in handwritten packages
8
+
9
+ ### 1.32.0 / 2021-06-21
10
+
11
+ #### Features
12
+
13
+ * Add support for Parquet options
14
+ * feat(bigquery): Add Bigquery::External::ParquetSource
15
+ * Add Parquet options to LoadJob
16
+ * Add LoadJob#parquet_options?
17
+ * Add LoadJob#parquet_enable_list_inference?
18
+ * Add LoadJob#parquet_enum_as_string?
19
+ * Add LoadJob::Updater#parquet_enable_list_inference=
20
+ * Add LoadJob::Updater#parquet_enum_as_string=
21
+
22
+ #### Bug Fixes
23
+
24
+ * Expand googleauth dependency to support future 1.x versions
25
+
26
+ ### 1.31.0 / 2021-04-28
27
+
28
+ #### Features
29
+
30
+ * Add support for mutable clustering configuration
31
+ * Add Table#clustering_fields=
32
+
33
+ ### 1.30.0 / 2021-04-20
34
+
35
+ #### Features
36
+
37
+ * Add support for BIGNUMERIC data type
38
+ * Add support for BIGNUMERIC data insert.
39
+ * Add support for BIGNUMERIC query params.
40
+ * Add #bignumeric to Schema, Table, LoadJob::Updater and Field.
41
+ * Update types tables in docs.
42
+
43
+ #### Bug Fixes
44
+
45
+ * Fix Table#time_partitioning_expiration=
46
+ * Accept nil argument.
47
+
48
+ ### 1.29.0 / 2021-03-10
49
+
50
+ #### Features
51
+
52
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
53
+
3
54
  ### 1.28.0 / 2021-03-09
4
55
 
5
56
  #### Features
data/CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
24
24
  In order to use the google-cloud-bigquery console and run the project's tests,
25
25
  there is a small amount of setup:
26
26
 
27
- 1. Install Ruby. google-cloud-bigquery requires Ruby 2.4+. You may choose to
27
+ 1. Install Ruby. google-cloud-bigquery requires Ruby 2.5+. You may choose to
28
28
  manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
29
  [rbenv](https://github.com/rbenv/rbenv), or
30
30
  [chruby](https://github.com/postmodern/chruby).
@@ -119,15 +119,14 @@ If you alter an example's title, you may encounter breaking tests.
119
119
  ### BigQuery Acceptance Tests
120
120
 
121
121
  The BigQuery acceptance tests interact with the live service API. Follow the
122
- instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
122
+ instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
123
123
  the BigQuery API. Occasionally, some API features may not yet be generally
124
124
  available, making it difficult for some contributors to successfully run the
125
125
  entire acceptance test suite. However, please ensure that you do successfully
126
126
  run acceptance tests for any code areas covered by your pull request.
127
127
 
128
128
  To run the acceptance tests, first create and configure a project in the Google
129
- Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
- guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
130
  the KEYFILE location on your system.
132
131
 
133
132
  Before you can run the BigQuery acceptance tests, you must first create indexes
data/LOGGING.md CHANGED
@@ -4,7 +4,7 @@ To enable logging for this library, set the logger for the underlying [Google
4
4
  API
5
5
  Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging)
6
6
  library. The logger that you set may be a Ruby stdlib
7
- [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as
7
+ [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
8
8
  shown below, or a
9
9
  [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
10
10
  that will write logs to [Stackdriver
data/OVERVIEW.md CHANGED
@@ -155,20 +155,21 @@ more complex types such as `ARRAY` and `STRUCT`.
155
155
 
156
156
  The BigQuery data types are converted to and from Ruby types as follows:
157
157
 
158
- | BigQuery | Ruby | Notes |
159
- |-------------|----------------|---|
160
- | `BOOL` | `true`/`false` | |
161
- | `INT64` | `Integer` | |
162
- | `FLOAT64` | `Float` | |
163
- | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
164
- | `STRING` | `String` | |
165
- | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
166
- | `DATE` | `Date` | |
167
- | `TIMESTAMP` | `Time` | |
168
- | `TIME` | `Google::Cloud::BigQuery::Time` | |
169
- | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
170
- | `ARRAY` | `Array` | Nested arrays and `nil` values are not supported. |
171
- | `STRUCT` | `Hash` | Hash keys may be strings or symbols. |
158
+ | BigQuery | Ruby | Notes |
159
+ |------------- |--------------------------------------|--------------------------------------------------------------|
160
+ | `BOOL` | `true`/`false` | |
161
+ | `INT64` | `Integer` | |
162
+ | `FLOAT64` | `Float` | |
163
+ | `NUMERIC` | `BigDecimal` | `BigDecimal` values will be rounded to scale 9. |
164
+ | `BIGNUMERIC` | converted to `BigDecimal` | Pass data as `String` and map query param values in `types`. |
165
+ | `STRING` | `String` | |
166
+ | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
167
+ | `DATE` | `Date` | |
168
+ | `TIMESTAMP` | `Time` | |
169
+ | `TIME` | `Google::Cloud::BigQuery::Time` | |
170
+ | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
171
+ | `ARRAY` | `Array` | Nested arrays, `nil` values are not supported. |
172
+ | `STRUCT` | `Hash` | Hash keys may be strings or symbols. |
172
173
 
173
174
  See [Data
174
175
  Types](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types)
@@ -23,30 +23,28 @@ require "date"
23
23
  module Google
24
24
  module Cloud
25
25
  module Bigquery
26
- # rubocop:disable Metrics/ModuleLength
27
-
28
26
  ##
29
27
  # @private
30
28
  #
31
- # Internal conversion of raw data values to/from Bigquery values
29
+ # Internal conversion of raw data values to/from BigQuery values
30
+ #
31
+ # | BigQuery | Ruby | Notes |
32
+ # |--------------|--------------------------------------|----------------------------------------------------|
33
+ # | `BOOL` | `true`/`false` | |
34
+ # | `INT64` | `Integer` | |
35
+ # | `FLOAT64` | `Float` | |
36
+ # | `NUMERIC` | `BigDecimal` | `BigDecimal` values will be rounded to scale 9. |
37
+ # | `BIGNUMERIC` | converted to `BigDecimal` | Pass data as `String`; map query params in `types`.|
38
+ # | `STRING` | `String` | |
39
+ # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
40
+ # | `DATE` | `Date` | |
41
+ # | `TIMESTAMP` | `Time` | |
42
+ # | `TIME` | `Google::Cloud::BigQuery::Time` | |
43
+ # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
44
+ # | `ARRAY` | `Array` | Nested arrays, `nil` values are not supported. |
45
+ # | `STRUCT` | `Hash` | Hash keys may be strings or symbols. |
32
46
  #
33
- # | BigQuery | Ruby | Notes |
34
- # |-------------|----------------|---|
35
- # | `BOOL` | `true`/`false` | |
36
- # | `INT64` | `Integer` | |
37
- # | `FLOAT64` | `Float` | |
38
- # | `NUMERIC` | `BigDecimal` | Will be rounded to 9 decimal places |
39
- # | `STRING` | `String` | |
40
- # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
41
- # | `DATE` | `Date` | |
42
- # | `TIMESTAMP` | `Time` | |
43
- # | `TIME` | `Google::Cloud::BigQuery::Time` | |
44
- # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
45
- # | `ARRAY` | `Array` | Nested arrays, `nil` values are not supported. |
46
- # | `STRUCT` | `Hash` | Hash keys may be strings or symbols. |
47
47
  module Convert
48
- ##
49
- # @private
50
48
  def self.format_rows rows, fields
51
49
  Array(rows).map do |row|
52
50
  # convert TableRow to hash to handle nested TableCell values
@@ -54,8 +52,6 @@ module Google
54
52
  end
55
53
  end
56
54
 
57
- ##
58
- # @private
59
55
  def self.format_row row, fields
60
56
  row_pairs = fields.zip(row[:f]).map do |f, v|
61
57
  [f.name.to_sym, format_value(v, f)]
@@ -92,6 +88,8 @@ module Google
92
88
  end
93
89
  elsif field.type == "NUMERIC"
94
90
  BigDecimal value[:v]
91
+ elsif field.type == "BIGNUMERIC"
92
+ BigDecimal value[:v]
95
93
  elsif field.type == "BOOLEAN"
96
94
  (value[:v] == "true" ? true : (value[:v] == "false" ? false : nil))
97
95
  elsif field.type == "BYTES"
@@ -109,30 +107,21 @@ module Google
109
107
  end
110
108
  end
111
109
 
112
- ##
113
- # @private
114
- def self.to_query_param param, type = nil
115
- type ||= default_query_param_type_for param
116
-
117
- Google::Apis::BigqueryV2::QueryParameter.new(
118
- parameter_type: to_query_param_type(type),
119
- parameter_value: to_query_param_value(param)
120
- )
121
- end
110
+ # rubocop:enable all
122
111
 
123
- ##
124
- # @private
125
- def self.to_query_param_value value
112
+ def self.to_query_param_value value, type = nil
126
113
  return Google::Apis::BigqueryV2::QueryParameterValue.new value: nil if value.nil?
127
114
 
128
- json_value = to_json_value value
115
+ json_value = to_json_value value, type
129
116
 
130
- if Array === json_value
131
- array_values = json_value.map { |v| to_query_param_value v }
117
+ case json_value
118
+ when Array
119
+ type = extract_array_type type
120
+ array_values = json_value.map { |v| to_query_param_value v, type }
132
121
  Google::Apis::BigqueryV2::QueryParameterValue.new array_values: array_values
133
- elsif Hash === json_value
134
- struct_pairs = json_value.map do |key, value|
135
- [String(key), to_query_param_value(value)]
122
+ when Hash
123
+ struct_pairs = json_value.map do |k, v|
124
+ [String(k), to_query_param_value(v, type)]
136
125
  end
137
126
  struct_values = Hash[struct_pairs]
138
127
  Google::Apis::BigqueryV2::QueryParameterValue.new struct_values: struct_values
@@ -143,12 +132,13 @@ module Google
143
132
  end
144
133
 
145
134
  def self.to_query_param_type type
146
- if Array === type
135
+ case type
136
+ when Array
147
137
  Google::Apis::BigqueryV2::QueryParameterType.new(
148
138
  type: "ARRAY".freeze,
149
139
  array_type: to_query_param_type(type.first)
150
140
  )
151
- elsif Hash === type
141
+ when Hash
152
142
  Google::Apis::BigqueryV2::QueryParameterType.new(
153
143
  type: "STRUCT".freeze,
154
144
  struct_types: type.map do |key, val|
@@ -159,10 +149,14 @@ module Google
159
149
  end
160
150
  )
161
151
  else
162
- Google::Apis::BigqueryV2::QueryParameterType.new(type: type.to_s.freeze)
152
+ Google::Apis::BigqueryV2::QueryParameterType.new type: type.to_s.freeze
163
153
  end
164
154
  end
165
155
 
156
+ # rubocop:disable Lint/DuplicateBranch
157
+ # rubocop:disable Metrics/CyclomaticComplexity
158
+ # rubocop:disable Style/GuardClause
159
+
166
160
  def self.default_query_param_type_for param
167
161
  raise ArgumentError, "nil params are not supported, must assign optional type" if param.nil?
168
162
 
@@ -202,9 +196,9 @@ module Google
202
196
  end
203
197
  [non_nil_values.first]
204
198
  when Hash
205
- Hash[param.map do |key, value|
206
- [key, default_query_param_type_for(value)]
207
- end]
199
+ param.transform_values do |value|
200
+ default_query_param_type_for value
201
+ end
208
202
  else
209
203
  if param.respond_to?(:read) && param.respond_to?(:rewind)
210
204
  :BYTES
@@ -214,9 +208,11 @@ module Google
214
208
  end
215
209
  end
216
210
 
217
- ##
218
- # @private
219
- def self.to_json_value value
211
+ # rubocop:enable Lint/DuplicateBranch
212
+ # rubocop:enable Metrics/CyclomaticComplexity
213
+ # rubocop:enable Style/GuardClause
214
+
215
+ def self.to_json_value value, type = nil
220
216
  if DateTime === value
221
217
  value.strftime "%Y-%m-%d %H:%M:%S.%6N"
222
218
  elsif Date === value
@@ -226,30 +222,46 @@ module Google
226
222
  elsif Bigquery::Time === value
227
223
  value.value
228
224
  elsif BigDecimal === value
229
- # Round to precision of 9
230
- value.finite? ? value.round(9).to_s("F") : value.to_s
225
+ if value.finite?
226
+ # Round to precision of 9 unless explicit `BIGNUMERIC`
227
+ bigdecimal = type == :BIGNUMERIC ? value : value.round(9)
228
+ bigdecimal.to_s "F"
229
+ else
230
+ value.to_s
231
+ end
231
232
  elsif value.respond_to?(:read) && value.respond_to?(:rewind)
232
233
  value.rewind
233
- Base64.strict_encode64(value.read.force_encoding("ASCII-8BIT"))
234
+ Base64.strict_encode64 value.read.force_encoding("ASCII-8BIT")
234
235
  elsif Array === value
235
- value.map { |v| to_json_value v }
236
+ type = extract_array_type type
237
+ value.map { |x| to_json_value x, type }
236
238
  elsif Hash === value
237
- Hash[value.map { |k, v| [k.to_s, to_json_value(v)] }]
239
+ Hash[value.map { |k, v| [k.to_s, to_json_value(v, type)] }]
238
240
  else
239
241
  value
240
242
  end
241
243
  end
242
244
 
243
- # rubocop:enable all
245
+ def self.to_query_param param, type = nil
246
+ type ||= default_query_param_type_for param
244
247
 
245
- ##
246
- # @private
247
- def self.to_json_rows rows
248
- rows.map { |row| to_json_row row }
248
+ Google::Apis::BigqueryV2::QueryParameter.new(
249
+ parameter_type: to_query_param_type(type),
250
+ parameter_value: to_query_param_value(param, type)
251
+ )
249
252
  end
250
253
 
251
254
  ##
252
- # @private
255
+ # Lists are specified by providing the type code in an array. For example, an array of integers are specified as
256
+ # `[:INT64]`. Extracts the symbol.
257
+ def self.extract_array_type type
258
+ return nil if type.nil?
259
+ unless type.is_a?(Array) && type.count == 1 && type.first.is_a?(Symbol)
260
+ raise ArgumentError, "types Array #{type.inspect} should include only a single symbol element."
261
+ end
262
+ type.first
263
+ end
264
+
253
265
  def self.to_json_row row
254
266
  Hash[row.map { |k, v| [k.to_s, to_json_value(v)] }]
255
267
  end
@@ -261,8 +273,6 @@ module Google
261
273
  end
262
274
 
263
275
  ##
264
- # @private
265
- #
266
276
  # Converts create disposition strings to API values.
267
277
  #
268
278
  # @return [String] API representation of create disposition.
@@ -281,8 +291,6 @@ module Google
281
291
  end
282
292
 
283
293
  ##
284
- # @private
285
- #
286
294
  # Converts write disposition strings to API values.
287
295
  #
288
296
  # @return [String] API representation of write disposition.
@@ -303,8 +311,6 @@ module Google
303
311
  end
304
312
 
305
313
  ##
306
- # @private
307
- #
308
314
  # Converts source format strings to API values.
309
315
  #
310
316
  # @return [String] API representation of source format.
@@ -327,8 +333,6 @@ module Google
327
333
  end
328
334
 
329
335
  ##
330
- # @private
331
- #
332
336
  # Converts file paths into source format by extension.
333
337
  #
334
338
  # @return [String] API representation of source format.
@@ -339,8 +343,6 @@ module Google
339
343
  end
340
344
 
341
345
  ##
342
- # @private
343
- #
344
346
  # Converts file path into source format by extension.
345
347
  #
346
348
  # @return [String] API representation of source format.
@@ -355,8 +357,6 @@ module Google
355
357
  end
356
358
 
357
359
  ##
358
- # @private
359
- #
360
360
  # Converts a primitive time value in milliseconds to a Ruby Time object.
361
361
  #
362
362
  # @return [Time, nil] The Ruby Time object, or nil if the given argument
@@ -367,8 +367,6 @@ module Google
367
367
  end
368
368
 
369
369
  ##
370
- # @private
371
- #
372
370
  # Converts a Ruby Time object to a primitive time value in milliseconds.
373
371
  #
374
372
  # @return [Integer, nil] The primitive time value in milliseconds, or
@@ -378,8 +376,6 @@ module Google
378
376
  (time_obj.to_i * 1000) + (time_obj.nsec / 1_000_000)
379
377
  end
380
378
  end
381
-
382
- # rubocop:enable Metrics/ModuleLength
383
379
  end
384
380
  end
385
381
  end
@@ -144,6 +144,7 @@ module Google
144
144
  ##
145
145
  # @private Create an Updater object.
146
146
  def initialize gapi
147
+ super()
147
148
  @gapi = gapi
148
149
  end
149
150