kura 0.4.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +36 -0
- data/kura.gemspec +1 -1
- data/lib/kura/client.rb +122 -38
- data/lib/kura/version.rb +1 -1
- metadata +9 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 431faddd3518e447e4966d6eaf19e9ede9adb9ea6d4fb9d03a8715487021689d
|
4
|
+
data.tar.gz: f64c6c2fddcc66bde5cafca6b26a9f2e023f3627d9107fb69c23f3b15dbb41e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bac5621aa3c792ce93b67b0238aa0e82fcef2ae72d2260d163c987b9f47a267f338b13fd34c6bb689e2c69d42419551c5fc96de3f147f1632a4e21298385231
|
7
|
+
data.tar.gz: cc903378660c1a9b080210c8f339d4cf4e574b197dbfd59b135f3dd94274e152884ccf2a5545c3610c3df531c783b44ae1b13774760a512d30fd3005907635af
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
# 0.6.1
|
2
|
+
|
3
|
+
## Enhancements
|
4
|
+
|
5
|
+
* `job` method now accept `fields` keyword argument.
|
6
|
+
|
7
|
+
# 0.6.0
|
8
|
+
|
9
|
+
## Changes
|
10
|
+
|
11
|
+
* Replace runtime dependency "google-api-client.gem" -> "google-apis-bigquery_v2".
|
12
|
+
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.
|
13
|
+
|
14
|
+
# 0.5.0
|
15
|
+
|
16
|
+
## Changes
|
17
|
+
|
18
|
+
* `Kura::Client#list_tabledata` now return TIMESTAMP value in ISO 8601 format String.
|
19
|
+
|
20
|
+
## Enhancements
|
21
|
+
|
22
|
+
* Accept description field in schema specification at insert&load table.
|
23
|
+
|
24
|
+
# 0.4.4
|
25
|
+
|
26
|
+
## Enhancements
|
27
|
+
|
28
|
+
* Support [Routines API](https://cloud.google.com/bigquery/docs/reference/rest/v2/routines/).
|
29
|
+
|
30
|
+
# 0.4.3
|
31
|
+
|
32
|
+
## Fixes
|
33
|
+
|
34
|
+
* Query job with SCRIPT type could contain `status.errorResult` without `status.errors` property.
|
35
|
+
Fix to handle this case properly.
|
36
|
+
|
1
37
|
# 0.4.2
|
2
38
|
|
3
39
|
## Enhancements
|
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-
|
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
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require "time"
|
3
4
|
require "json"
|
4
5
|
require "google/apis/bigquery_v2"
|
5
6
|
require "googleauth"
|
@@ -268,6 +269,8 @@ module Kura
|
|
268
269
|
end
|
269
270
|
when "BOOLEAN"
|
270
271
|
x.to_s == "true"
|
272
|
+
when "TIMESTAMP"
|
273
|
+
Time.at(Float(x)).utc.iso8601(6)
|
271
274
|
when "RECORD"
|
272
275
|
_convert_tabledata_row(x, field_info["fields"])
|
273
276
|
else
|
@@ -409,16 +412,16 @@ module Kura
|
|
409
412
|
wait: nil,
|
410
413
|
dry_run: false,
|
411
414
|
&blk)
|
412
|
-
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
413
|
-
query: Google::Apis::BigqueryV2::JobConfigurationQuery.new(
|
415
|
+
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
416
|
+
query: Google::Apis::BigqueryV2::JobConfigurationQuery.new(
|
414
417
|
query: sql,
|
415
418
|
allow_large_results: normalize_parameter(allow_large_results),
|
416
419
|
flatten_results: normalize_parameter(flatten_results),
|
417
420
|
priority: priority,
|
418
421
|
use_query_cache: normalize_parameter(use_query_cache),
|
419
422
|
use_legacy_sql: use_legacy_sql,
|
420
|
-
|
421
|
-
|
423
|
+
)
|
424
|
+
)
|
422
425
|
if mode
|
423
426
|
configuration.query.write_disposition = mode_to_write_disposition(mode)
|
424
427
|
end
|
@@ -433,15 +436,15 @@ module Kura
|
|
433
436
|
configuration.query.maximum_bytes_billed = maximum_bytes_billed
|
434
437
|
end
|
435
438
|
if dataset_id and table_id
|
436
|
-
configuration.query.destination_table = Google::Apis::BigqueryV2::TableReference.new(
|
439
|
+
configuration.query.destination_table = Google::Apis::BigqueryV2::TableReference.new(project_id: project_id, dataset_id: dataset_id, table_id: table_id)
|
437
440
|
end
|
438
441
|
if user_defined_function_resources
|
439
442
|
configuration.query.user_defined_function_resources = Array(user_defined_function_resources).map do |r|
|
440
443
|
r = r.to_s
|
441
444
|
if r.start_with?("gs://")
|
442
|
-
Google::Apis::BigqueryV2::UserDefinedFunctionResource.new(
|
445
|
+
Google::Apis::BigqueryV2::UserDefinedFunctionResource.new(resource_uri: r)
|
443
446
|
else
|
444
|
-
Google::Apis::BigqueryV2::UserDefinedFunctionResource.new(
|
447
|
+
Google::Apis::BigqueryV2::UserDefinedFunctionResource.new(inline_code: r)
|
445
448
|
end
|
446
449
|
end
|
447
450
|
end
|
@@ -459,6 +462,9 @@ module Kura
|
|
459
462
|
type: (s[:type] || s["type"]),
|
460
463
|
mode: (s[:mode] || s["mode"]),
|
461
464
|
}
|
465
|
+
if (desc = (s[:description] || s["description"]))
|
466
|
+
f[:description] = desc
|
467
|
+
end
|
462
468
|
if (sub_fields = (s[:fields] || s["fields"]))
|
463
469
|
f[:fields] = normalize_schema(sub_fields)
|
464
470
|
end
|
@@ -468,6 +474,9 @@ module Kura
|
|
468
474
|
type: s.type,
|
469
475
|
mode: s.mode,
|
470
476
|
}
|
477
|
+
if s.respond_to?(:description)
|
478
|
+
f[:description] = s.description
|
479
|
+
end
|
471
480
|
if (sub_fields = s.fields)
|
472
481
|
f[:fields] = normalize_schema(sub_fields)
|
473
482
|
end
|
@@ -493,26 +502,26 @@ module Kura
|
|
493
502
|
&blk)
|
494
503
|
write_disposition = mode_to_write_disposition(mode)
|
495
504
|
source_uris = [source_uris] if source_uris.is_a?(String)
|
496
|
-
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
497
|
-
load: Google::Apis::BigqueryV2::JobConfigurationLoad.new(
|
498
|
-
destination_table: Google::Apis::BigqueryV2::TableReference.new(
|
505
|
+
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
506
|
+
load: Google::Apis::BigqueryV2::JobConfigurationLoad.new(
|
507
|
+
destination_table: Google::Apis::BigqueryV2::TableReference.new(
|
499
508
|
project_id: project_id,
|
500
509
|
dataset_id: dataset_id,
|
501
510
|
table_id: table_id,
|
502
|
-
|
511
|
+
),
|
503
512
|
write_disposition: write_disposition,
|
504
513
|
allow_jagged_rows: normalize_parameter(allow_jagged_rows),
|
505
514
|
max_bad_records: max_bad_records,
|
506
515
|
ignore_unknown_values: normalize_parameter(ignore_unknown_values),
|
507
516
|
source_format: source_format,
|
508
|
-
|
509
|
-
|
517
|
+
)
|
518
|
+
)
|
510
519
|
if dry_run
|
511
520
|
configuration.dry_run = true
|
512
521
|
wait = nil
|
513
522
|
end
|
514
523
|
if schema
|
515
|
-
configuration.load.schema = Google::Apis::BigqueryV2::TableSchema.new(
|
524
|
+
configuration.load.schema = Google::Apis::BigqueryV2::TableSchema.new(fields: normalize_schema(schema))
|
516
525
|
end
|
517
526
|
if source_format == "CSV"
|
518
527
|
configuration.load.field_delimiter = field_delimiter
|
@@ -541,18 +550,18 @@ module Kura
|
|
541
550
|
dry_run: false,
|
542
551
|
&blk)
|
543
552
|
dest_uris = [ dest_uris ] if dest_uris.is_a?(String)
|
544
|
-
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
545
|
-
extract: Google::Apis::BigqueryV2::JobConfigurationExtract.new(
|
553
|
+
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
554
|
+
extract: Google::Apis::BigqueryV2::JobConfigurationExtract.new(
|
546
555
|
compression: compression,
|
547
556
|
destination_format: destination_format,
|
548
|
-
source_table: Google::Apis::BigqueryV2::TableReference.new(
|
557
|
+
source_table: Google::Apis::BigqueryV2::TableReference.new(
|
549
558
|
project_id: project_id,
|
550
559
|
dataset_id: dataset_id,
|
551
560
|
table_id: table_id,
|
552
|
-
|
561
|
+
),
|
553
562
|
destination_uris: dest_uris,
|
554
|
-
|
555
|
-
|
563
|
+
)
|
564
|
+
)
|
556
565
|
if dry_run
|
557
566
|
configuration.dry_run = true
|
558
567
|
wait = nil
|
@@ -574,21 +583,21 @@ module Kura
|
|
574
583
|
dry_run: false,
|
575
584
|
&blk)
|
576
585
|
write_disposition = mode_to_write_disposition(mode)
|
577
|
-
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
578
|
-
copy: Google::Apis::BigqueryV2::JobConfigurationTableCopy.new(
|
579
|
-
destination_table: Google::Apis::BigqueryV2::TableReference.new(
|
586
|
+
configuration = Google::Apis::BigqueryV2::JobConfiguration.new(
|
587
|
+
copy: Google::Apis::BigqueryV2::JobConfigurationTableCopy.new(
|
588
|
+
destination_table: Google::Apis::BigqueryV2::TableReference.new(
|
580
589
|
project_id: dest_project_id,
|
581
590
|
dataset_id: dest_dataset_id,
|
582
591
|
table_id: dest_table_id,
|
583
|
-
|
584
|
-
source_table: Google::Apis::BigqueryV2::TableReference.new(
|
592
|
+
),
|
593
|
+
source_table: Google::Apis::BigqueryV2::TableReference.new(
|
585
594
|
project_id: src_project_id,
|
586
595
|
dataset_id: src_dataset_id,
|
587
596
|
table_id: src_table_id,
|
588
|
-
|
597
|
+
),
|
589
598
|
write_disposition: write_disposition,
|
590
|
-
|
591
|
-
|
599
|
+
)
|
600
|
+
)
|
592
601
|
if dry_run
|
593
602
|
configuration.dry_run = true
|
594
603
|
wait = nil
|
@@ -617,14 +626,14 @@ module Kura
|
|
617
626
|
state_filter: state_filter)
|
618
627
|
end
|
619
628
|
|
620
|
-
def job(job_id, location: nil, project_id: @default_project_id, &blk)
|
629
|
+
def job(job_id, location: nil, project_id: @default_project_id, fields: nil, &blk)
|
621
630
|
if blk
|
622
|
-
@api.get_job(project_id, job_id, location: location) do |j, e|
|
631
|
+
@api.get_job(project_id, job_id, location: location, fields: fields) do |j, e|
|
623
632
|
j.kura_api = self if j
|
624
633
|
blk.call(j, e)
|
625
634
|
end
|
626
635
|
else
|
627
|
-
@api.get_job(project_id, job_id, location: location).tap{|j| j.kura_api = self if j }
|
636
|
+
@api.get_job(project_id, job_id, location: location, fields: fields).tap{|j| j.kura_api = self if j }
|
628
637
|
end
|
629
638
|
rescue
|
630
639
|
process_error($!)
|
@@ -654,13 +663,21 @@ module Kura
|
|
654
663
|
def job_finished?(r)
|
655
664
|
if r.status.state == "DONE"
|
656
665
|
if r.status.error_result
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
666
|
+
if r.status.errors
|
667
|
+
raise Kura::ApiError.new(r.status.errors.map(&:reason).join(","),
|
668
|
+
r.status.errors.map{|e|
|
669
|
+
msg = "reason=#{e.reason} message=#{e.message}"
|
670
|
+
msg += " location=#{e.location}" if e.location
|
671
|
+
msg += " debug_info=#{e.debug_info}" if e.debug_info
|
672
|
+
msg
|
673
|
+
}.join("\n"))
|
674
|
+
else
|
675
|
+
e = r.status.error_result
|
676
|
+
msg = "reason=#{e.reason} message=#{e.message}"
|
677
|
+
msg += " location=#{e.location}" if e.location
|
678
|
+
msg += " debug_info=#{e.debug_info}" if e.debug_info
|
679
|
+
raise Kura::ApiError.new(e.reason, msg)
|
680
|
+
end
|
664
681
|
end
|
665
682
|
return true
|
666
683
|
end
|
@@ -729,5 +746,72 @@ module Kura
|
|
729
746
|
return nil if $!.respond_to?(:status_code) and $!.status_code == 404
|
730
747
|
process_error($!)
|
731
748
|
end
|
749
|
+
|
750
|
+
# Routines API
|
751
|
+
def routines(dataset_id, project_id: @default_project_id, limit: 1000, page_token: nil, &blk)
|
752
|
+
if blk
|
753
|
+
@api.list_routines(project_id, dataset_id, max_results: limit, page_token: page_token) do |result, err|
|
754
|
+
result &&= (result.routines || [])
|
755
|
+
blk.call(result, err)
|
756
|
+
end
|
757
|
+
else
|
758
|
+
@api.list_routines(project_id, dataset_id, max_results: limit, page_token: page_token)
|
759
|
+
end
|
760
|
+
rescue
|
761
|
+
process_error($!)
|
762
|
+
end
|
763
|
+
|
764
|
+
def routine(dataset_id, routine_id, project_id: @default_project_id, &blk)
|
765
|
+
if blk
|
766
|
+
@api.get_routine(project_id, dataset_id, routine_id) do |result, err|
|
767
|
+
if err.respond_to?(:status_code) and err.status_code == 404
|
768
|
+
result = nil
|
769
|
+
err = nil
|
770
|
+
end
|
771
|
+
blk.call(result, err)
|
772
|
+
end
|
773
|
+
else
|
774
|
+
@api.get_routine(project_id, dataset_id, routine_id)
|
775
|
+
end
|
776
|
+
rescue
|
777
|
+
return nil if $!.respond_to?(:status_code) and $!.status_code == 404
|
778
|
+
process_error($!)
|
779
|
+
end
|
780
|
+
|
781
|
+
def delete_routine(dataset_id, routine_id, project_id: @default_project_id, &blk)
|
782
|
+
@api.delete_routine(project_id, dataset_id, routine_id, &blk)
|
783
|
+
rescue
|
784
|
+
return nil if $!.respond_to?(:status_code) and $!.status_code == 404
|
785
|
+
process_error($!)
|
786
|
+
end
|
787
|
+
|
788
|
+
def insert_routine(dataset_id,
|
789
|
+
routine_id,
|
790
|
+
body,
|
791
|
+
project_id: @default_project_id,
|
792
|
+
routine_type: "PROCEDURE",
|
793
|
+
language: "SQL",
|
794
|
+
arguments: [],
|
795
|
+
return_type: nil,
|
796
|
+
imported_libraries: [],
|
797
|
+
description: nil)
|
798
|
+
@api.insert_routine(
|
799
|
+
project_id,
|
800
|
+
dataset_id,
|
801
|
+
Google::Apis::BigqueryV2::Routine.new(
|
802
|
+
routine_reference: Google::Apis::BigqueryV2::RoutineReference.new(
|
803
|
+
project_id: project_id,
|
804
|
+
dataset_id: dataset_id,
|
805
|
+
routine_id: routine_id
|
806
|
+
),
|
807
|
+
arguments: arguments,
|
808
|
+
definition_body: body,
|
809
|
+
imported_libraries: imported_libraries,
|
810
|
+
language: language,
|
811
|
+
return_type: return_type,
|
812
|
+
routine_type: routine_type,
|
813
|
+
description: description
|
814
|
+
))
|
815
|
+
end
|
732
816
|
end
|
733
817
|
end
|
data/lib/kura/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chikanaga Tomoyuki
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: google-
|
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
|
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
|
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
|
@@ -139,7 +133,7 @@ homepage: https://github.com/nagachika/kura/
|
|
139
133
|
licenses:
|
140
134
|
- MIT
|
141
135
|
metadata: {}
|
142
|
-
post_install_message:
|
136
|
+
post_install_message:
|
143
137
|
rdoc_options: []
|
144
138
|
require_paths:
|
145
139
|
- lib
|
@@ -154,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
148
|
- !ruby/object:Gem::Version
|
155
149
|
version: '0'
|
156
150
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
158
|
-
signing_key:
|
151
|
+
rubygems_version: 3.2.15
|
152
|
+
signing_key:
|
159
153
|
specification_version: 4
|
160
154
|
summary: Interface to BigQuery API v2.
|
161
155
|
test_files: []
|