samidare 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 63ca3ecfca7bdd2d9928119a4565520a6cb43e3a
4
- data.tar.gz: 9f8ba50115e2d24ec87cf0bf18a049a8cdf2cc0e
3
+ metadata.gz: b5773b739c82c8896501f93a28c8f9f16780fbcb
4
+ data.tar.gz: dcdf41eb57238dc34b6f399a0b7fc707d25549c4
5
5
  SHA512:
6
- metadata.gz: 6b215d706b0ba77f13587597e5c79268176e79410b171f17a8d6f49c755569432699ddedb406d57d75ff6d86d357cc0829e2f6f1c5b4a1e57f1bfbc084509c6c
7
- data.tar.gz: 0b171bee1aa063719c4e4c87c7d311df09f611c9153ea11f4202ddc91777e1a035b91c3aa689ad12c6cd8c02001776daa3ef3bd866d8adb39c4bd54f7f46d44c
6
+ metadata.gz: 0bf4586c4a43e98bd24e36515ae2ac2cdebc072e6c089ca0ac71914bece5266c2ec6f338fedd16cbddaf87f6fae86acb57c9851c8a46b1af34db4ebdc4540da0
7
+ data.tar.gz: 116af87aeae963a54116730a1d14e54d62323a96d39f5790028fd9e33e681ff2d1d3d5f793a746b54946bd0f3b62893c854f2be57118d175a1ab26a49cb804fd
data/README.md CHANGED
@@ -31,8 +31,9 @@ config = {
31
31
  'auth_method' => 'private_key'
32
32
  }
33
33
 
34
- Samidare.generate_config(config)
35
- Samidare.embulk_run(config)
34
+ client = Samidare::EmbulkClient.new
35
+ client.generate_config(config)
36
+ client.run(config)
36
37
  ```
37
38
 
38
39
  ## Contributing
data/lib/samidare.rb CHANGED
@@ -2,12 +2,12 @@ require 'samidare/version'
2
2
  require 'samidare/embulk_utility'
3
3
 
4
4
  module Samidare
5
- class << self
5
+ class EmbulkClient
6
6
  def generate_config(config)
7
7
  Samidare::EmbulkUtility::ConfigGenerator.new(config).generate_config
8
8
  end
9
9
 
10
- def embulk_run(config)
10
+ def run(config)
11
11
  db_infos = Samidare::EmbulkUtility::DBInfo.generate_db_infos
12
12
  table_infos = Samidare::EmbulkUtility::TableInfo.generate_table_infos
13
13
  db_infos.keys.each do |db_name|
@@ -1,9 +1,38 @@
1
1
  require 'json'
2
2
  require 'erb'
3
3
  require 'big_query'
4
+ require 'unindent'
4
5
 
5
6
  module Samidare
6
7
  class BigQueryUtility
8
+ CONTENTS = <<-EOS.unindent
9
+ in:
10
+ type: mysql
11
+ user: <%= user %>
12
+ password: <%= password %>
13
+ database: <%= database %>
14
+ host: <%= host %>
15
+ query: |
16
+ <%= query %>
17
+ out:
18
+ type: bigquery
19
+ project: <%= project %>
20
+ p12_keyfile_path: <%= p12_keyfile_path %>
21
+ service_account_email: <%= service_account_email %>
22
+ dataset: <%= dataset %>
23
+ table: <%= table_name %>
24
+ schema_path: <%= schema_path %>
25
+ auto_create_table: 1
26
+ path_prefix: <%= path_prefix %>
27
+ source_format: NEWLINE_DELIMITED_JSON
28
+ file_ext: .json.gz
29
+ delete_from_local_when_job_end: 1
30
+ formatter:
31
+ type: jsonl
32
+ encoders:
33
+ - {type: gzip}
34
+ EOS
35
+
7
36
  def initialize(config)
8
37
  @config = config.dup
9
38
  end
@@ -33,7 +62,8 @@ module Samidare
33
62
  schema_path = "#{@config['schema_dir']}/#{db_name}/#{table_info.name}.json"
34
63
  path_prefix = "/var/tmp/embulk_#{db_name}_#{table_info.name}"
35
64
 
36
- File.open('lib/samidare/embulk_config.erb') { |f| ERB.new(f.read).result(binding) }
65
+ #File.open('lib/samidare/embulk_config.erb') { |f| ERB.new(f.read).result(binding) }
66
+ ERB.new(CONTENTS).result(binding)
37
67
  end
38
68
 
39
69
  def delete_table(dataset, table_name)
@@ -1,6 +1,7 @@
1
1
  require 'mysql2-cs-bind'
2
2
  require 'json'
3
3
  require 'yaml'
4
+ require 'fileutils'
4
5
  require 'samidare/bigquery_utility'
5
6
 
6
7
  module Samidare
@@ -1,3 +1,3 @@
1
1
  module Samidare
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samidare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryoji Kobori
@@ -180,7 +180,6 @@ files:
180
180
  - Rakefile
181
181
  - lib/samidare.rb
182
182
  - lib/samidare/bigquery_utility.rb
183
- - lib/samidare/embulk_config.erb
184
183
  - lib/samidare/embulk_utility.rb
185
184
  - lib/samidare/version.rb
186
185
  - samidare.gemspec
@@ -217,4 +216,3 @@ test_files:
217
216
  - spec/samidare/embulk_utility_spec.rb
218
217
  - spec/samidare_spec.rb
219
218
  - spec/spec_helper.rb
220
- has_rdoc:
@@ -1,25 +0,0 @@
1
- in:
2
- type: mysql
3
- user: <%= user %>
4
- password: <%= password %>
5
- database: <%= database %>
6
- host: <%= host %>
7
- query: |
8
- <%= query %>
9
- out:
10
- type: bigquery
11
- project: <%= project %>
12
- p12_keyfile_path: <%= p12_keyfile_path %>
13
- service_account_email: <%= service_account_email %>
14
- dataset: <%= dataset %>
15
- table: <%= table_name %>
16
- schema_path: <%= schema_path %>
17
- auto_create_table: 1
18
- path_prefix: <%= path_prefix %>
19
- source_format: NEWLINE_DELIMITED_JSON
20
- file_ext: .json.gz
21
- delete_from_local_when_job_end: 1
22
- formatter:
23
- type: jsonl
24
- encoders:
25
- - {type: gzip}