Class: Sqoop

Inherits:
Object
  • Object
show all
Defined in:
lib/sqoop-ruby.rb

Instance Method Summary collapse

Constructor Details

#initialize(jdbc_conn, db_host, db_name, db_user, password, hdfs_url) ⇒ Sqoop

Returns a new instance of Sqoop.



3
4
5
6
7
# File 'lib/sqoop-ruby.rb', line 3

def initialize(jdbc_conn, db_host, db_name, db_user, password, hdfs_url)
  raise "HDFS URL must be a hdfs or s3 resource" unless ['hdfs','s3'].include?(hdfs_url.split(':')[0].downcase)
  @hdfs_url = hdfs_url
  @db_options = " --connect jdbc:#{jdbc_conn.downcase}://#{db_host}/#{db_name} --username #{db_user} --password #{password}"
end

Instance Method Details

#export(table) ⇒ Object



27
28
29
30
31
32
# File 'lib/sqoop-ruby.rb', line 27

def export(table)
  sqoop_command = "sqoop export" + @db_options + " --table #{table} --export-dir #{@hdfs_url}"
  output = system(sqoop_command)
  raise "Sqoop export failed" if output.nil?
  output  
end

#import(*table) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sqoop-ruby.rb', line 15

def import(*table)
  if table != []
    sqoop_command = "sqoop import" + @db_options + " --table #{table}"
  else
    sqoop_command = "sqoop import-all-tables " + @db_options
  end
  sqoop_command += " --target-dir #{@hdfs_url}"
  output = system(sqoop_command)
  raise "Sqoop import failed" if output.nil?
  output
end

#test_dbObject



9
10
11
12
13
# File 'lib/sqoop-ruby.rb', line 9

def test_db
  output = system("sqoop list-databases" + @db_options)
  raise "Database connection failed" if output.nil?
  output
end