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 +4 -4
- data/ChangeLog.md +8 -0
- data/lib/kura/client.rb +16 -10
- data/lib/kura/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a436e39cec7d1079d4b83e4deb84ce310c26ddc5798163f950cf3ab353d79b
|
4
|
+
data.tar.gz: 7f96eee9e1f02df06f0535b50dc188c8414f84a0e3f6ca28ab539cffe2f0eb9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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.
|
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:
|
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
|