google-cloud-bigquery 1.25.0 → 1.30.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae4b6e4d7c37a945f027fe56425698b19b430f5e75451ce82f2156f2dae96719
4
- data.tar.gz: d50284a47bf96d5221b574590a60b3af0f77b3a8943d201fd473d78f41a46670
3
+ metadata.gz: 316b03a95fd406a6382fb89e031e8cfe3388d7b244e53d0f3cc6749037437387
4
+ data.tar.gz: 00f3a68186e380fe588c7effb03e2f4ff9d4ca830d96f136df83d6df014abdc4
5
5
  SHA512:
6
- metadata.gz: 56c0b2d3214b385efb3866e502faa0b0c28c2fffc0c3d2ca3c5e1ad05f4d69e0638e68d59d8310c68d01c26c3db55b42225944379bfb8f6ad7a57eec558ced3a
7
- data.tar.gz: 0562b98e65e880a40d634f541285241823354a966f4d05a559463a23eacca54addf8843f89b32731d313a56d91dfe2984f6098630c4126d7dbc97033d3dc6a81
6
+ metadata.gz: 7015cbe609aabf7f2bd57ee97f292c430733de8349b8349f97205de4a4192a3fc9b39d0163c626f393d1256a3354786b72e7f9f1dd94e2b262432c33c8287ad5
7
+ data.tar.gz: 843994c37a342681c9e53f3bde97dabcec668b313c73b3caf054ccf7ed6f422c8c48a6f2d947d097a6dfaf9803d96f110969096e22f47737b1a6fef8b8b494b2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # Release History
2
2
 
3
+ ### 1.30.0 / 2021-04-20
4
+
5
+ #### Features
6
+
7
+ * Add support for BIGNUMERIC data type
8
+ * Add support for BIGNUMERIC data insert.
9
+ * Add support for BIGNUMERIC query params.
10
+ * Add #bignumeric to Schema, Table, LoadJob::Updater and Field.
11
+ * Update types tables in docs.
12
+
13
+ #### Bug Fixes
14
+
15
+ * Fix Table#time_partitioning_expiration=
16
+ * Accept nil argument.
17
+
18
+ ### 1.29.0 / 2021-03-10
19
+
20
+ #### Features
21
+
22
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
23
+
24
+ ### 1.28.0 / 2021-03-09
25
+
26
+ #### Features
27
+
28
+ * Add Materialized View support
29
+ * Add Dataset#create_materialized_view
30
+ * Add Table#materialized_view?
31
+ * Add Table#enable_refresh?
32
+ * Add Table#enable_refresh=
33
+ * Add Table#last_refresh_time
34
+ * Add Table#refresh_interval_ms
35
+ * Add Table#refresh_interval_ms=
36
+
37
+ ### 1.27.0 / 2021-02-10
38
+
39
+ #### Features
40
+
41
+ * Add Job#reservation_usage
42
+ * Add Routine#determinism_level
43
+ * Add Routine#determinism_level
44
+ * Add Routine#determinism_level=
45
+ * Add Routine#determinism_level_deterministic?
46
+ * Add Routine#determinism_level_not_deterministic?
47
+ * Add Routine::Updater#determinism_level=
48
+
49
+ ### 1.26.0 / 2021-01-13
50
+
51
+ #### Features
52
+
53
+ * Add support for Hive Partitioning
54
+ * Add hive partitioning options to External::DataSource
55
+ * Add hive partitioning options to LoadJob and LoadJob::Updater
56
+ * Replace google-api-client with google-apis-bigquery_v2
57
+
3
58
  ### 1.25.0 / 2020-11-16
4
59
 
5
60
  #### 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).
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-bigquery/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
@@ -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