kura 0.6.2 → 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: 2ea4ebb00dbb6f6c467dff7f4573d3627f433a4f02b55ba8b3d6b13c64c29508
4
- data.tar.gz: a26d9f4a2f0eb6fc60d7b4371cdfff674161bdc8da0ef695d55c680a1069be0f
3
+ metadata.gz: 15a436e39cec7d1079d4b83e4deb84ce310c26ddc5798163f950cf3ab353d79b
4
+ data.tar.gz: 7f96eee9e1f02df06f0535b50dc188c8414f84a0e3f6ca28ab539cffe2f0eb9c
5
5
  SHA512:
6
- metadata.gz: 3a0a5aa8fc5ee6d559f1e2b47be2bdde98726ac278a023238aaaa690e922ed5876d5ba732c3814db03074234123364a77ceb86b5d7097bdf6bcd8e88292b78ca
7
- data.tar.gz: 8503ea77b5e22e76f84eebe4391eb0e3757e11596c34ff53c2a450ca35d86995efd78b8017170f231a23de64100b000dfccf57a49738cf27bb9fd974d149f84d
6
+ metadata.gz: 3da32573e83e77d4268a5e4982aea642470222db5ee16ee61ea9708b1771784c651f76d68432158ab08fcddfd640d5f14123ba0dd1d23afdefb1e0895f1a61e4
7
+ data.tar.gz: 7e3f51be7307bcd248ffc4cedf9dfa45b0c37b4f4e490932f81bc0986e1e07e0386242a3f8b86579bb1bd3b44af1c3e1f4c06c8a66bfa369e61f809dba312aa1
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  # 0.6.2
2
10
 
3
11
  ## Enhancements
data/lib/kura/client.rb CHANGED
@@ -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($!)
data/lib/kura/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kura
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
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: 2021-07-09 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
14
  name: google-apis-bigquery_v2