Module: Sip::Utils
- Defined in:
- lib/sip/utils.rb
Class Method Summary collapse
- .hostname ⇒ Object
- .load_template(name, config) ⇒ Object
- .sanity_check(config) ⇒ Object
-
.tfile_path(path = nil) ⇒ Object
look for tfile - return nil if not found.
- .write_script(sipper, host, select, dbname, tablename, transpart_opts) ⇒ Object
Class Method Details
.hostname ⇒ Object
14 15 16 |
# File 'lib/sip/utils.rb', line 14 def self.hostname Socket.gethostname end |
.load_template(name, config) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/sip/utils.rb', line 7 def self.load_template(name, config) path = File.join(File.dirname(__FILE__), "templates", name) temp = ERB.new File.open(path, 'r') { |f| f.read } klass = Struct.new *config.keys.map { |k| k.intern } temp.result klass.new(*config.values).get_binding end |
.sanity_check(config) ⇒ Object
54 55 56 |
# File 'lib/sip/utils.rb', line 54 def self.sanity_check(config) # eventually, check for table structure differences, etc end |
.tfile_path(path = nil) ⇒ Object
look for tfile - return nil if not found
45 46 47 48 49 50 51 52 |
# File 'lib/sip/utils.rb', line 45 def self.tfile_path(path=nil) if path.nil? path = (`which transpart`).strip path = "./bin/transpart" if path == "" end path = File. path test('f', path) ? path : nil end |
.write_script(sipper, host, select, dbname, tablename, transpart_opts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sip/utils.rb', line 18 def self.write_script(sipper, host, select, dbname, tablename, transpart_opts) hive_table_name = sipper.config.tconf(dbname, tablename)['hive_table_name'] args = { 'host' => host, 'debug' => (sipper.config[:debug] ? '1' : '0'), 'tfile' => sipper.config['tfile'], 'topts' => transpart_opts.to_s, 'tmpdir' => sipper.config['tmpdir'], 'hdfs_tmpdir' => sipper.config['hdfs_tmpdir'], 'output_dir' => transpart_opts['o'], 'query' => select, 'hive_table_name' => sipper.config['databases'][dbname]['tables'][tablename]['hive_table_name'], 'hadoop_home' => ENV['HADOOP_HOME'], 'hive_home' => ENV['HIVE_HOME'], 'overwrite' => (sipper.config[:overwrite] ? '1' : '0') } script = Utils::load_template('export.sh', args) d = File.join(sipper.config['tmpdir'], 'scripts') FileUtils.mkdir_p d fname = File.join(d, "#{host}-#{tablename}.sh") open(fname, 'w') { |f| f.write(script) } sipper.log "just wrote import script to #{fname}" fname end |