sql2avro 0.3.1 → 0.3.2
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.
- data/lib/interface/mysql.rb +5 -1
- data/lib/sql2avro.rb +12 -1
- metadata +6 -6
data/lib/interface/mysql.rb
CHANGED
@@ -148,10 +148,14 @@ class MySql < DbInterface
|
|
148
148
|
#{db_name}
|
149
149
|
}
|
150
150
|
|
151
|
-
Open3.popen3(cmd) do |i, o, e|
|
151
|
+
Open3.popen3(cmd) do |i, o, e, wait_thr|
|
152
152
|
while (line = o.gets)
|
153
153
|
block.call(line.chop.split(MYSQL_BATCH_SEP))
|
154
154
|
end
|
155
|
+
|
156
|
+
if !wait_thr.value.success?
|
157
|
+
raise "Error querying mysql\n\nQuery: #{cmd}\nSTDERR: #{e.read}\nSTATUS: #{wait_thr.value}"
|
158
|
+
end
|
155
159
|
end
|
156
160
|
end
|
157
161
|
|
data/lib/sql2avro.rb
CHANGED
@@ -29,7 +29,7 @@ module Sql2Avro
|
|
29
29
|
# min_id specifies the value of the id column from which to start.
|
30
30
|
def Sql2Avro.avroize(database_config, table, min_id, max_rows_per_batch=nil)
|
31
31
|
raise "Database interface not specified." if !database_config.has_key? 'adapter'
|
32
|
-
raise "Database interface not supported: #{database_config['adapter']}"
|
32
|
+
raise "Database interface not supported: #{database_config['adapter']}" unless ['mysql', 'mysql2'].include? database_config['adapter']
|
33
33
|
|
34
34
|
interface = MySql.new(database_config)
|
35
35
|
|
@@ -50,6 +50,9 @@ module Sql2Avro
|
|
50
50
|
}
|
51
51
|
|
52
52
|
begin
|
53
|
+
prev_default_internal = Encoding.default_internal
|
54
|
+
Encoding.default_internal = nil
|
55
|
+
|
53
56
|
json_file = "#{filename}.json"
|
54
57
|
File.open(json_file, 'w') do |f|
|
55
58
|
interface.data(table, min_id, max_id_this_batch) do |datum|
|
@@ -58,10 +61,18 @@ module Sql2Avro
|
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
64
|
+
Encoding.default_internal = prev_default_internal
|
65
|
+
|
61
66
|
cmd = "java -jar #{AVRO_TOOLS_PATH} fromjson --codec snappy --schema '#{schema}' #{json_file} > #{filename}"
|
62
67
|
`#{cmd}`
|
68
|
+
if !$?.success?
|
69
|
+
raise "Error converting JSON to Avro.\n\nCommand: #{cmd}\nStatus: #{$?}"
|
70
|
+
end
|
63
71
|
|
64
72
|
`rm #{json_file}`
|
73
|
+
if !$?.success?
|
74
|
+
raise "Error deleting temporary JSON file #{json_file}"
|
75
|
+
end
|
65
76
|
rescue Exception => e
|
66
77
|
retval[:error] = "#{e}\n\n#{e.backtrace}"
|
67
78
|
end
|
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.3.
|
4
|
+
version: 0.3.2
|
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-21 00:00:00.
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70297282972760 !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: *70297282972760
|
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: -3119210657153955613
|
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: -3119210657153955613
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
67
|
rubygems_version: 1.8.10
|