google-cloud-bigquery 1.27.0 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -0
  3. data/CONTRIBUTING.md +3 -4
  4. data/LOGGING.md +1 -1
  5. data/OVERVIEW.md +15 -14
  6. data/lib/google/cloud/bigquery/convert.rb +72 -76
  7. data/lib/google/cloud/bigquery/copy_job.rb +1 -0
  8. data/lib/google/cloud/bigquery/data.rb +2 -2
  9. data/lib/google/cloud/bigquery/dataset.rb +181 -62
  10. data/lib/google/cloud/bigquery/dataset/access.rb +3 -3
  11. data/lib/google/cloud/bigquery/dataset/list.rb +2 -2
  12. data/lib/google/cloud/bigquery/external.rb +9 -2619
  13. data/lib/google/cloud/bigquery/external/bigtable_source.rb +230 -0
  14. data/lib/google/cloud/bigquery/external/bigtable_source/column.rb +404 -0
  15. data/lib/google/cloud/bigquery/external/bigtable_source/column_family.rb +945 -0
  16. data/lib/google/cloud/bigquery/external/csv_source.rb +481 -0
  17. data/lib/google/cloud/bigquery/external/data_source.rb +771 -0
  18. data/lib/google/cloud/bigquery/external/json_source.rb +170 -0
  19. data/lib/google/cloud/bigquery/external/parquet_source.rb +148 -0
  20. data/lib/google/cloud/bigquery/external/sheets_source.rb +166 -0
  21. data/lib/google/cloud/bigquery/extract_job.rb +4 -2
  22. data/lib/google/cloud/bigquery/job.rb +9 -3
  23. data/lib/google/cloud/bigquery/job/list.rb +4 -4
  24. data/lib/google/cloud/bigquery/load_job.rb +178 -19
  25. data/lib/google/cloud/bigquery/model/list.rb +2 -2
  26. data/lib/google/cloud/bigquery/policy.rb +2 -1
  27. data/lib/google/cloud/bigquery/project.rb +47 -43
  28. data/lib/google/cloud/bigquery/project/list.rb +2 -2
  29. data/lib/google/cloud/bigquery/query_job.rb +84 -62
  30. data/lib/google/cloud/bigquery/routine.rb +1 -4
  31. data/lib/google/cloud/bigquery/routine/list.rb +2 -2
  32. data/lib/google/cloud/bigquery/schema.rb +39 -3
  33. data/lib/google/cloud/bigquery/schema/field.rb +63 -13
  34. data/lib/google/cloud/bigquery/service.rb +11 -13
  35. data/lib/google/cloud/bigquery/standard_sql.rb +15 -3
  36. data/lib/google/cloud/bigquery/table.rb +312 -69
  37. data/lib/google/cloud/bigquery/table/async_inserter.rb +44 -17
  38. data/lib/google/cloud/bigquery/table/list.rb +2 -2
  39. data/lib/google/cloud/bigquery/version.rb +1 -1
  40. metadata +28 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 334d37be375f513da083f7338e1324413409a6c30554456c08290ed1337c2701
4
- data.tar.gz: f21c7793b5a9f82d0c3840aa5915fd10ef43644ccc1d9ea996a63860fa8b16ed
3
+ metadata.gz: 36bd68946313d76f828e1fdbfb66606e7495ff876e25da7925772ad324ea8da3
4
+ data.tar.gz: b75c3a1b4d585c64c048bb073d0e3c0ab0231a666e8df6d350b98a0b282150d4
5
5
  SHA512:
6
- metadata.gz: 187d0549552613c40f85001fdf82197db01af5b5e285dfd6f7615a64c62ed74807c0ea31ac560d2a1516dae0c91f14fcc08b143882fcf8437b8d7c964f256348
7
- data.tar.gz: e6b80ed9ccff8ffb2f8537a009a6d41a7930ee080f50800001b0afa9f7706a85af58180d091051f34a2499d66ca15f5c084a74cbbff244d8c22d266fc62713db
6
+ metadata.gz: 823a1a0dd34a02c1278df3620270225fd9d592e0577f6812ad9df48722a2132c05e4799e5acd7aafc1973874ab60cd6f6c1a90b48382e1a55a52e8a0a38a8cb4
7
+ data.tar.gz: 9f3ab6425237255aa466637fe62911ed6253a13033205929e3e43d5948a0ad30943dc5deffcae74329dc94c782358305eb545767a9a5352e135ea2b38d3705a5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # Release History
2
2
 
3
+ ### 1.32.0 / 2021-06-21
4
+
5
+ #### Features
6
+
7
+ * Add support for Parquet options
8
+ * feat(bigquery): Add Bigquery::External::ParquetSource
9
+ * Add Parquet options to LoadJob
10
+ * Add LoadJob#parquet_options?
11
+ * Add LoadJob#parquet_enable_list_inference?
12
+ * Add LoadJob#parquet_enum_as_string?
13
+ * Add LoadJob::Updater#parquet_enable_list_inference=
14
+ * Add LoadJob::Updater#parquet_enum_as_string=
15
+
16
+ #### Bug Fixes
17
+
18
+ * Expand googleauth dependency to support future 1.x versions
19
+
20
+ ### 1.31.0 / 2021-04-28
21
+
22
+ #### Features
23
+
24
+ * Add support for mutable clustering configuration
25
+ * Add Table#clustering_fields=
26
+
27
+ ### 1.30.0 / 2021-04-20
28
+
29
+ #### Features
30
+
31
+ * Add support for BIGNUMERIC data type
32
+ * Add support for BIGNUMERIC data insert.
33
+ * Add support for BIGNUMERIC query params.
34
+ * Add #bignumeric to Schema, Table, LoadJob::Updater and Field.
35
+ * Update types tables in docs.
36
+
37
+ #### Bug Fixes
38
+
39
+ * Fix Table#time_partitioning_expiration=
40
+ * Accept nil argument.
41
+
42
+ ### 1.29.0 / 2021-03-10
43
+
44
+ #### Features
45
+
46
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
47
+
48
+ ### 1.28.0 / 2021-03-09
49
+
50
+ #### Features
51
+
52
+ * Add Materialized View support
53
+ * Add Dataset#create_materialized_view
54
+ * Add Table#materialized_view?
55
+ * Add Table#enable_refresh?
56
+ * Add Table#enable_refresh=
57
+ * Add Table#last_refresh_time
58
+ * Add Table#refresh_interval_ms
59
+ * Add Table#refresh_interval_ms=
60
+
3
61
  ### 1.27.0 / 2021-02-10
4
62
 
5
63
  #### 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