sql2avro 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +3 -3
- data/lib/interface/mysql.rb +2 -2
- data/lib/sql2avro.rb +11 -7
- metadata +6 -6
data/Makefile
CHANGED
data/lib/interface/mysql.rb
CHANGED
@@ -151,8 +151,8 @@ class MySql < DbInterface
|
|
151
151
|
#{db_name}
|
152
152
|
}
|
153
153
|
|
154
|
-
Open3.popen3(cmd) do |
|
155
|
-
while (line =
|
154
|
+
Open3.popen3(cmd) do |i, o, e|
|
155
|
+
while (line = o.gets)
|
156
156
|
block.call(line.chop.split(MYSQL_BATCH_SEP))
|
157
157
|
end
|
158
158
|
end
|
data/lib/sql2avro.rb
CHANGED
@@ -4,7 +4,7 @@ require 'yajl'
|
|
4
4
|
require_relative 'interface/mysql'
|
5
5
|
|
6
6
|
module Sql2Avro
|
7
|
-
AVRO_TOOLS_PATH = File.expand_path('
|
7
|
+
AVRO_TOOLS_PATH = File.expand_path('../../vendor/avro-tools-1.7.4.jar', __FILE__)
|
8
8
|
|
9
9
|
|
10
10
|
# Pulls data from the given database table starting from the given id.
|
@@ -45,16 +45,20 @@ module Sql2Avro
|
|
45
45
|
}
|
46
46
|
|
47
47
|
begin
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
json_file = "#{filename}.json"
|
49
|
+
File.open(json_file, 'w') do |f|
|
51
50
|
interface.data(table, min_id, max_id).each do |datum|
|
52
|
-
Yajl::Encoder.encode(datum,
|
53
|
-
|
51
|
+
Yajl::Encoder.encode(datum, f)
|
52
|
+
f.write "\n"
|
54
53
|
end
|
55
54
|
end
|
55
|
+
|
56
|
+
cmd = "java -jar #{AVRO_TOOLS_PATH} fromjson --codec snappy --schema '#{schema}' #{json_file} > #{filename}"
|
57
|
+
`#{cmd}`
|
58
|
+
|
59
|
+
`rm #{json_file}`
|
56
60
|
rescue
|
57
|
-
retval[:error] =
|
61
|
+
retval[:error] = $!.to_s
|
58
62
|
end
|
59
63
|
|
60
64
|
retval
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql2avro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70268699282980 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70268699282980
|
25
25
|
description: sql2avro extracts data from a specified SQL database table and transforms
|
26
26
|
it into an Avro file with a schema based on the database table's schema. The intended
|
27
27
|
use case is to incrementally load data out of an SQL database and into HDFS for
|
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
52
|
version: '0'
|
53
53
|
segments:
|
54
54
|
- 0
|
55
|
-
hash: -
|
55
|
+
hash: -933336779340994961
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
version: '0'
|
62
62
|
segments:
|
63
63
|
- 0
|
64
|
-
hash: -
|
64
|
+
hash: -933336779340994961
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
67
|
rubygems_version: 1.8.10
|