kura 0.5.0 → 0.6.3

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: 6f06565ca49829ddf17062a4b3bc3a060a38e44c19d1d9f30636cec01aef67c3
4
- data.tar.gz: d5a577529bbd9313f3923f91298fa5897af42c8cc50db8a82af13179a3fb129f
3
+ metadata.gz: 15a436e39cec7d1079d4b83e4deb84ce310c26ddc5798163f950cf3ab353d79b
4
+ data.tar.gz: 7f96eee9e1f02df06f0535b50dc188c8414f84a0e3f6ca28ab539cffe2f0eb9c
5
5
  SHA512:
6
- metadata.gz: '08a14f0ec78b5e6635975cc5a9d39b5e85f9a25eca3041c6edd3e0034331284612bb4c4a869d413edee8f599f7b6b07a70d6958be2e82f493f8e7e2cc08a1136'
7
- data.tar.gz: e2eb76c7c84f1585bc474b6d7f4f8825b3f6a545de9e110faa5b868818e50ff591b75b80cf47332636d62632d9b9b64d6df01c05559e1fe1e0edb4b33e5cd35b
6
+ metadata.gz: 3da32573e83e77d4268a5e4982aea642470222db5ee16ee61ea9708b1771784c651f76d68432158ab08fcddfd640d5f14123ba0dd1d23afdefb1e0895f1a61e4
7
+ data.tar.gz: 7e3f51be7307bcd248ffc4cedf9dfa45b0c37b4f4e490932f81bc0986e1e07e0386242a3f8b86579bb1bd3b44af1c3e1f4c06c8a66bfa369e61f809dba312aa1
data/ChangeLog.md CHANGED
@@ -1,3 +1,31 @@
1
+ # 0.6.3
2
+
3
+ ## Changes
4
+
5
+ * Add `convert_numeric_to_float` keyword argument in `list_tabledata` method.
6
+ If `convert_numeric_to_float: true` is specified, the value from a NUMMERIC column will be converted to Float.
7
+ The default value for `convert_numeric_to_float` is true.
8
+
9
+ # 0.6.2
10
+
11
+ ## Enhancements
12
+
13
+ * Support ruby 3.0.
14
+ * Support range partitioning and time partitioning parameter for load job configuration.
15
+
16
+ # 0.6.1
17
+
18
+ ## Enhancements
19
+
20
+ * `job` method now accept `fields` keyword argument.
21
+
22
+ # 0.6.0
23
+
24
+ ## Changes
25
+
26
+ * Replace runtime dependency "google-api-client.gem" -> "google-apis-bigquery_v2".
27
+ See https://github.com/groovenauts/gcs-ruby/pull/2://github.com/googleapis/google-api-ruby-client/blob/master/google-api-client/OVERVIEW.md for more details.
28
+
1
29
  # 0.5.0
2
30
 
3
31
  ## Changes
data/kura.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 2.1'
23
23
 
24
- spec.add_runtime_dependency "google-api-client", [">= 0.28.6", "!= 0.29.1"]
24
+ spec.add_runtime_dependency "google-apis-bigquery_v2"
25
25
 
26
26
  spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake"
data/lib/kura/client.rb CHANGED
@@ -220,7 +220,7 @@ module Kura
220
220
  view: view,
221
221
  external_data_configuration: external_data_configuration)
222
222
  if time_partitioning
223
- table.time_partitioning = Google::Apis::BigqueryV2::TimePartitioning.new(time_partitioning)
223
+ table.time_partitioning = Google::Apis::BigqueryV2::TimePartitioning.new(**time_partitioning)
224
224
  end
225
225
  @api.insert_table(project_id, dataset_id, table, &blk)
226
226
  rescue
@@ -247,7 +247,7 @@ module Kura
247
247
  process_error($!)
248
248
  end
249
249
 
250
- def _convert_tabledata_field(x, field_info)
250
+ def _convert_tabledata_field(x, field_info, convert_numeric_to_float: true)
251
251
  if x.nil? and (field_info["mode"] == "NULLABLE" or field_info["mode"].nil?) # The tables created by New BigQuery Console could have schema without mode...
252
252
  return nil
253
253
  end
@@ -272,35 +272,41 @@ module Kura
272
272
  when "TIMESTAMP"
273
273
  Time.at(Float(x)).utc.iso8601(6)
274
274
  when "RECORD"
275
- _convert_tabledata_row(x, field_info["fields"])
275
+ _convert_tabledata_row(x, field_info["fields"], convert_numeric_to_float: convert_numeric_to_float)
276
+ when "NUMERIC"
277
+ if convert_numeric_to_float
278
+ Float(x)
279
+ else
280
+ x
281
+ end
276
282
  else
277
283
  x
278
284
  end
279
285
  end
280
286
 
281
- def _convert_tabledata_row(row, schema)
287
+ def _convert_tabledata_row(row, schema, convert_numeric_to_float: true)
282
288
  (row.respond_to?(:f) ? row.f : row["f"]).zip(schema).each_with_object({}) do |(v, s), tbl|
283
289
  v = JSON.parse(v.to_json)
284
290
  if s["mode"] == "REPEATED"
285
- tbl[s["name"]] = v["v"].map{|c| _convert_tabledata_field(c["v"], s) }
291
+ tbl[s["name"]] = v["v"].map{|c| _convert_tabledata_field(c["v"], s, convert_numeric_to_float: convert_numeric_to_float) }
286
292
  else
287
- tbl[s["name"]] = _convert_tabledata_field(v["v"], s)
293
+ tbl[s["name"]] = _convert_tabledata_field(v["v"], s, convert_numeric_to_float: convert_numeric_to_float)
288
294
  end
289
295
  end
290
296
  end
291
297
 
292
- def format_tabledata(r, schema)
298
+ def format_tabledata(r, schema, convert_numeric_to_float: true)
293
299
  {
294
300
  total_rows: r.total_rows.to_i,
295
301
  next_token: r.page_token,
296
302
  rows: (r.rows || []).map do |row|
297
- _convert_tabledata_row(row, schema)
303
+ _convert_tabledata_row(row, schema, convert_numeric_to_float: convert_numeric_to_float)
298
304
  end
299
305
  }
300
306
  end
301
307
  private :format_tabledata
302
308
 
303
- def list_tabledata(dataset_id, table_id, project_id: @default_project_id, start_index: 0, max_result: 100, page_token: nil, schema: nil, &blk)
309
+ def list_tabledata(dataset_id, table_id, project_id: @default_project_id, start_index: 0, max_result: 100, page_token: nil, schema: nil, convert_numeric_to_float: true, &blk)
304
310
  if schema.nil?
305
311
  _t = table(dataset_id, table_id, project_id: project_id)
306
312
  if _t
@@ -314,13 +320,13 @@ module Kura
314
320
  if blk
315
321
  @api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token) do |r, err|
316
322
  if r
317
- r = format_tabledata(r, schema)
323
+ r = format_tabledata(r, schema, convert_numeric_to_float: convert_numeric_to_float)
318
324
  end
319
325
  blk.call(r, err)
320
326
  end
321
327
  else
322
328
  r = @api.list_table_data(project_id, dataset_id, table_id, max_results: max_result, start_index: start_index, page_token: page_token)
323
- format_tabledata(r, schema)
329
+ format_tabledata(r, schema, convert_numeric_to_float: convert_numeric_to_float)
324
330
  end
325
331
  rescue
326
332
  process_error($!)
@@ -494,6 +500,8 @@ module Kura
494
500
  quote: '"', skip_leading_rows: 0,
495
501
  source_format: "CSV",
496
502
  autodetect: false,
503
+ range_partitioning: nil,
504
+ time_partitioning: nil,
497
505
  project_id: @default_project_id,
498
506
  job_project_id: @default_project_id,
499
507
  job_id: nil,
@@ -502,6 +510,14 @@ module Kura
502
510
  &blk)
503
511
  write_disposition = mode_to_write_disposition(mode)
504
512
  source_uris = [source_uris] if source_uris.is_a?(String)
513
+ case range_partitioning
514
+ when Hash
515
+ range_partitioning = Google::Apis::BigqueryV2::RangePartitioning.new(**range_partitioning)
516
+ end
517
+ case time_partitioning
518
+ when Hash
519
+ time_partitioning = Google::Apis::BigqueryV2::TimePartitioning.new(**time_partitioning)
520
+ end
505
521
  configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
506
522
  load: Google::Apis::BigqueryV2::JobConfigurationLoad.new(
507
523
  destination_table: Google::Apis::BigqueryV2::TableReference.new(
@@ -514,6 +530,8 @@ module Kura
514
530
  max_bad_records: max_bad_records,
515
531
  ignore_unknown_values: normalize_parameter(ignore_unknown_values),
516
532
  source_format: source_format,
533
+ range_partitioning: range_partitioning,
534
+ time_partitioning: time_partitioning,
517
535
  )
518
536
  )
519
537
  if dry_run
@@ -626,14 +644,14 @@ module Kura
626
644
  state_filter: state_filter)
627
645
  end
628
646
 
629
- def job(job_id, location: nil, project_id: @default_project_id, &blk)
647
+ def job(job_id, location: nil, project_id: @default_project_id, fields: nil, &blk)
630
648
  if blk
631
- @api.get_job(project_id, job_id, location: location) do |j, e|
649
+ @api.get_job(project_id, job_id, location: location, fields: fields) do |j, e|
632
650
  j.kura_api = self if j
633
651
  blk.call(j, e)
634
652
  end
635
653
  else
636
- @api.get_job(project_id, job_id, location: location).tap{|j| j.kura_api = self if j }
654
+ @api.get_job(project_id, job_id, location: location, fields: fields).tap{|j| j.kura_api = self if j }
637
655
  end
638
656
  rescue
639
657
  process_error($!)
data/lib/kura/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kura
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chikanaga Tomoyuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: google-api-client
14
+ name: google-apis-bigquery_v2
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.28.6
20
- - - "!="
21
- - !ruby/object:Gem::Version
22
- version: 0.29.1
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.28.6
30
- - - "!="
31
- - !ruby/object:Gem::Version
32
- version: 0.29.1
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -154,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
148
  - !ruby/object:Gem::Version
155
149
  version: '0'
156
150
  requirements: []
157
- rubygems_version: 3.1.4
151
+ rubygems_version: 3.2.15
158
152
  signing_key:
159
153
  specification_version: 4
160
154
  summary: Interface to BigQuery API v2.