kiba-plus 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d724aaf93a4a7d042ef123f220fe43427a382993
4
- data.tar.gz: 3a2b31601585be0e49b7cacf426f01c2a91f1a8b
3
+ metadata.gz: 39c5c1848a724492f99fb2472d5743e7c0848d35
4
+ data.tar.gz: 547f4f57babb41d3cd664fe873bd55f730ff4ce0
5
5
  SHA512:
6
- metadata.gz: 75b623813154f0983795517fd5d1740629326e263f7c14ba1d50acf2bae64d5ba552c5a5346b4d9a3714b1b07c963d8472a0bbc040c3b8b7a04eefa3d9084c3c
7
- data.tar.gz: 13d50fe54a0c0616c8c8217540f8fb131b480bc8fbb189cbb8b15ca622c929085b2d12c0e72d8de2d2056706f6d88668ec27221ae51dc6a5f19abbb26281e83d
6
+ metadata.gz: 778e4bad4aa95d371625962431790a74fbee12077dc4406cb962ca975629dbab850e2241141656802d71196dfaed0b8598b5bcc130e16af180c058c02b8a1e38
7
+ data.tar.gz: 45a9389410c08e7eedc594370b9ca70d1656662b87c13f70589cc86597ccc3470a12318499011a98521dff44f21dd154dbdc4716282bf18dafd11c524953f80a
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative 'init'
3
+
4
+ DEST_URL = 'mysql://root@localhost/crm2_dev'
5
+
6
+ destination Kiba::Plus::Destination::MysqlBulk, { :connect_url => DEST_URL,
7
+ :table_name => "customers",
8
+ :input_file => File.expand_path(File.dirname(__FILE__) + "/data/customer.csv"),
9
+ :truncate => true,
10
+ :columns => [:id, :email, :first_name, :last_name],
11
+ :incremental => false
12
+ }
13
+ post_process do
14
+ result = Mysql2::Client.new(connect_hash(DEST_URL)).query("SELECT COUNT(*) AS num FROM customers")
15
+ puts "Insert total: #{result.first['num']}"
16
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative 'init'
3
+
4
+ DEST_URL = 'postgresql://hooopo@localhost:5432/crm2_dev'
5
+
6
+ destination Kiba::Plus::Destination::PgBulk, { :connect_url => DEST_URL,
7
+ :table_name => "customers",
8
+ :input_file => File.expand_path(File.dirname(__FILE__) + "/data/customer.csv"),
9
+ :truncate => true,
10
+ :columns => [:id, :email, :first_name, :last_name],
11
+ :incremental => false
12
+ }
13
+ post_process do
14
+ result = PG.connect(DEST_URL).query("SELECT COUNT(*) AS num FROM customers")
15
+ puts "Insert total: #{result.first['num']}"
16
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require_relative 'init'
3
3
 
4
- SOURCE_URL = 'mysql://root@localhost/shopperplus'
4
+ DEST_URL = 'mysql://root@localhost/crm2_dev'
5
5
 
6
6
  source Kiba::Plus::Source::Mysql, :connect_url => SOURCE_URL,
7
7
  :query => %Q{SELECT id, email, 'hooopo' AS first_name, 'Wang' AS last_name FROM customers}
@@ -0,0 +1,10 @@
1
+ 224862,hello@excite.com,hooopo,Wang
2
+ 251732,hello@hotmail.ca,hooopo,Wang
3
+ 30797,hello@excite.com,hooopo,Wang
4
+ 59629,hello@rogers.com,hooopo,Wang
5
+ 133665,"hello@live.ca",hooopo,Wang
6
+ 199481,"hello@acanac.net",hooopo,Wang
7
+ 288980,hello@gmail.com,hooopo,Wang
8
+ 147067,hello@qc.aira.com,hooopo,Wang
9
+ 339972,hello@nahlene.com,hooopo,Wang
10
+ 307171,hello@gmail.com,hooopo,Wang
@@ -1,5 +1,7 @@
1
1
  Bundler.require(:default)
2
2
 
3
+ include Kiba::Plus::Helper
4
+
3
5
  source_files = File.expand_path(File.dirname(__FILE__) + "/sources/*.rb")
4
6
  destination_files = File.expand_path(File.dirname(__FILE__) + "/destinations/*.rb")
5
7
 
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Hooopo"]
10
10
  spec.email = ["hoooopo@gmail.com"]
11
11
 
12
- spec.summary = %q{kiba plus}
13
- spec.description = %q{kiba plus}
14
- spec.homepage = ""
12
+ spec.summary = %q{Kiba enhancement for Ruby ETL}
13
+ spec.description = %q{It connects to various data sources including relational, non-relational, and flat file, cloud services and HTTP resources. It has flexible load strategies including insert, bulk load and upsert.}
14
+ spec.homepage = "https://github.com/hooopo/kiba-plus"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -6,16 +6,44 @@ module Kiba::Plus::Destination
6
6
 
7
7
  def initialize(options = {})
8
8
  @options = options
9
- @options.assert_valid_keys(:output_file)
10
- @csv = CSV.open(output_file, 'w', {col_sep: delimiter})
9
+ @options.assert_valid_keys(
10
+ :output_file,
11
+ :row_sep,
12
+ :col_sep,
13
+ :force_quotes,
14
+ :quote_char,
15
+ :mode
16
+ )
17
+ @csv = CSV.open(output_file, mode, {
18
+ :col_sep => col_sep,
19
+ :quote_char => quote_char,
20
+ :force_quotes => force_quotes,
21
+ :row_sep => row_sep
22
+ })
23
+ end
24
+
25
+ def mode
26
+ options.fetch(:mode, "w")
11
27
  end
12
28
 
13
29
  def output_file
14
30
  options.fetch(:output_file)
15
31
  end
16
32
 
17
- def delimiter
18
- ","
33
+ def col_sep
34
+ options.fetch(:col_sep, ",")
35
+ end
36
+
37
+ def quote_char
38
+ options.fetch(:quote_char, '"')
39
+ end
40
+
41
+ def force_quotes
42
+ options.fetch(:force_quotes, false)
43
+ end
44
+
45
+ def row_sep
46
+ options.fetch(:row_sep, "\n")
19
47
  end
20
48
 
21
49
  def write(row)
@@ -12,7 +12,10 @@ module Kiba::Plus::Destination
12
12
  :input_file,
13
13
  :connect_url,
14
14
  :truncate,
15
- :incremental
15
+ :incremental,
16
+ :delimited_by,
17
+ :enclosed_by,
18
+ :ignore_lines
16
19
  )
17
20
 
18
21
  @client = Mysql2::Client.new(connect_hash(connect_url).merge(local_infile: true))
@@ -26,6 +29,18 @@ module Kiba::Plus::Destination
26
29
  options.fetch(:table_name)
27
30
  end
28
31
 
32
+ def delimited_by
33
+ options.fetch(:delimited_by, ",")
34
+ end
35
+
36
+ def enclosed_by
37
+ options.fetch(:enclosed_by, '"')
38
+ end
39
+
40
+ def ignore_lines
41
+ options.fetch(:ignore_lines, 0)
42
+ end
43
+
29
44
  def write(row)
30
45
  end
31
46
 
@@ -52,7 +67,15 @@ module Kiba::Plus::Destination
52
67
  @client.query(truncate_sql)
53
68
  end
54
69
 
55
- bulk_sql = "LOAD DATA LOCAL INFILE '#{input_file}' REPLACE INTO TABLE #{table_name} FIELDS TERMINATED BY ', ' (#{columns.join(',')})"
70
+ bulk_sql = <<-SQL
71
+ LOAD DATA LOCAL INFILE '#{input_file}'
72
+ REPLACE INTO TABLE #{table_name}
73
+ FIELDS
74
+ TERMINATED BY '#{delimited_by}'
75
+ ENCLOSED BY '#{enclosed_by}'
76
+ IGNORE #{ignore_lines} LINES
77
+ (#{columns.join(',')})
78
+ SQL
56
79
  Kiba::Plus.logger.info bulk_sql
57
80
  @client.query(bulk_sql)
58
81
 
@@ -1,5 +1,5 @@
1
1
  module Kiba
2
2
  module Plus
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiba-plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kiba
@@ -94,7 +94,9 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.0'
97
- description: kiba plus
97
+ description: It connects to various data sources including relational, non-relational,
98
+ and flat file, cloud services and HTTP resources. It has flexible load strategies
99
+ including insert, bulk load and upsert.
98
100
  email:
99
101
  - hoooopo@gmail.com
100
102
  executables: []
@@ -112,8 +114,11 @@ files:
112
114
  - bin/setup
113
115
  - examples/Gemfile
114
116
  - examples/Gemfile.lock
117
+ - examples/customer_csv_to_mysql.etl
118
+ - examples/customer_csv_to_pg.etl
115
119
  - examples/customer_mysql_to_csv.etl
116
120
  - examples/customer_mysql_to_pg.etl
121
+ - examples/data/customer.csv
117
122
  - examples/init.rb
118
123
  - examples/sources/customer.rb
119
124
  - kiba-plus.gemspec
@@ -129,7 +134,7 @@ files:
129
134
  - lib/kiba/plus/logger.rb
130
135
  - lib/kiba/plus/source/mysql.rb
131
136
  - lib/kiba/plus/version.rb
132
- homepage: ''
137
+ homepage: https://github.com/hooopo/kiba-plus
133
138
  licenses:
134
139
  - MIT
135
140
  metadata:
@@ -153,5 +158,5 @@ rubyforge_project:
153
158
  rubygems_version: 2.4.5.1
154
159
  signing_key:
155
160
  specification_version: 4
156
- summary: kiba plus
161
+ summary: Kiba enhancement for Ruby ETL
157
162
  test_files: []