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 +4 -4
- data/examples/customer_csv_to_mysql.etl +16 -0
- data/examples/customer_csv_to_pg.etl +16 -0
- data/examples/customer_mysql_to_csv.etl +1 -1
- data/examples/data/customer.csv +10 -0
- data/examples/init.rb +2 -0
- data/kiba-plus.gemspec +3 -3
- data/lib/kiba/plus/destination/csv.rb +32 -4
- data/lib/kiba/plus/destination/mysql_bulk.rb +25 -2
- data/lib/kiba/plus/version.rb +1 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c5c1848a724492f99fb2472d5743e7c0848d35
|
4
|
+
data.tar.gz: 547f4f57babb41d3cd664fe873bd55f730ff4ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/examples/init.rb
CHANGED
data/kiba-plus.gemspec
CHANGED
@@ -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{
|
13
|
-
spec.description = %q{
|
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(
|
10
|
-
|
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
|
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 =
|
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
|
|
data/lib/kiba/plus/version.rb
CHANGED
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.
|
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-
|
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:
|
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:
|
161
|
+
summary: Kiba enhancement for Ruby ETL
|
157
162
|
test_files: []
|