sqoop-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "simplecov", ">= 0"
14
+ end
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.6)
11
+ multi_json (1.2.0)
12
+ rake (0.9.2.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ shoulda (3.0.1)
16
+ shoulda-context (~> 1.0.0)
17
+ shoulda-matchers (~> 1.0.0)
18
+ shoulda-context (1.0.0)
19
+ shoulda-matchers (1.0.0)
20
+ simplecov (0.6.1)
21
+ multi_json (~> 1.0)
22
+ simplecov-html (~> 0.5.3)
23
+ simplecov-html (0.5.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ jeweler (~> 1.8.3)
31
+ rdoc (~> 3.12)
32
+ shoulda
33
+ simplecov
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ian Morgan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ = sqoop-ruby
2
+
3
+ Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool.
4
+
5
+
6
+ == Requirements and installation
7
+
8
+ Requires Sqoop tool and applicable JDBC Jars. Installable via Cloudera's repos or https://github.com/cloudera/sqoop/wiki
9
+
10
+ gem install sqoop-ruby
11
+
12
+
13
+ == Examples
14
+
15
+ Create Sqoop object
16
+
17
+ sqoop = Sqoop.new("mysql", "mysql.company.com", "company_db", "dbuser", "dbpassword", "hdfs://name-node/path/to/dir")
18
+
19
+ Import all tables to HDFS
20
+
21
+ sqoop.import
22
+
23
+ Export HDFS dataset to Relation database
24
+
25
+ sqoop.export("customers")
26
+
27
+
28
+ == Contributing to sqoop-ruby
29
+
30
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
31
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
32
+ * Fork the project.
33
+ * Start a feature/bugfix branch.
34
+ * Commit and push until you are happy with your contribution.
35
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
36
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2012 Ian Morgan. See LICENSE.txt for
41
+ further details.
42
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sqoop-ruby"
18
+ gem.homepage = "http://github.com/seeingidog/sqoop-ruby"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool}
21
+ gem.description = %Q{Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool}
22
+ gem.email = "ian@ruby-code.com"
23
+ gem.authors = ["Ian Morgan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+
29
+ task :default => :test
30
+
31
+ require 'rdoc/task'
32
+ Rake::RDocTask.new do |rdoc|
33
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
34
+
35
+ rdoc.rdoc_dir = 'rdoc'
36
+ rdoc.title = "sqoop-ruby #{version}"
37
+ rdoc.rdoc_files.include('README*')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,34 @@
1
+ class Sqoop
2
+
3
+ def initialize(jdbc_conn, db_host, db_name, db_user, password, hdfs_url)
4
+ raise "HDFS URL must be a hdfs or s3 resource" unless ['hdfs','s3'].include?(hdfs_url.split(':')[0].downcase)
5
+ @hdfs_url = hdfs_url
6
+ @db_options = " --connect jdbc:#{jdbc_conn.downcase}://#{db_host}/#{db_name} --username #{db_user} --password #{password}"
7
+ end
8
+
9
+ def test_db
10
+ output = system("sqoop list-databases" + @db_options)
11
+ raise "Database connection failed" if output.nil?
12
+ output
13
+ end
14
+
15
+ def import(*table)
16
+ if table != []
17
+ sqoop_command = "sqoop import" + @db_options + " --table #{table}"
18
+ else
19
+ sqoop_command = "sqoop import-all-tables " + @db_options
20
+ end
21
+ sqoop_command += " --target-dir #{@hdfs_url}"
22
+ output = system(sqoop_command)
23
+ raise "Sqoop import failed" if output.nil?
24
+ output
25
+ end
26
+
27
+ def export(table)
28
+ sqoop_command = "sqoop export" + @db_options + " --table #{table} --export-dir #{@hdfs_url}"
29
+ output = system(sqoop_command)
30
+ raise "Sqoop export failed" if output.nil?
31
+ output
32
+ end
33
+
34
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sqoop-ruby'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Sqoop" do
4
+ it "should test database connection" do
5
+ sqoop = Sqoop.new("mysql", "mysql.company.com", "company_db", "dbuser", "dbpassword", "hdfs://name-node/path/to/dir")
6
+ sqoop.test_db
7
+ end
8
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sqoop-ruby"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ian Morgan"]
12
+ s.date = "2012-04-12"
13
+ s.description = "Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool"
14
+ s.email = "ian@ruby-code.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/sqoop-ruby.rb",
28
+ "spec/spec_helper.rb",
29
+ "spec/sqoop-ruby_spec.rb",
30
+ "sqoop-ruby.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_sqoop-ruby.rb"
33
+ ]
34
+ s.homepage = "http://github.com/seeingidog/sqoop-ruby"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
54
+ s.add_dependency(%q<simplecov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
61
+ s.add_dependency(%q<simplecov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sqoop-ruby'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSqoopRuby < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqoop-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Morgan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: &2158134220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2158134220
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &2158133740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2158133740
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &2158133260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2158133260
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &2158132780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2158132780
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &2158132300 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2158132300
69
+ description: Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool
70
+ email: ian@ruby-code.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - VERSION
84
+ - lib/sqoop-ruby.rb
85
+ - spec/spec_helper.rb
86
+ - spec/sqoop-ruby_spec.rb
87
+ - sqoop-ruby.gemspec
88
+ - test/helper.rb
89
+ - test/test_sqoop-ruby.rb
90
+ homepage: http://github.com/seeingidog/sqoop-ruby
91
+ licenses:
92
+ - MIT
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 2672374732184098970
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.10
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Simple Ruby wrapper for Sqoop JDBC <-> HDFS import/export tool
118
+ test_files: []