Module Sip::Utils
In: lib/sip/utils.rb

Methods

Public Class methods

[Source]

# File lib/sip/utils.rb, line 14
    def self.hostname
      Socket.gethostname
    end

[Source]

# 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

[Source]

# File lib/sip/utils.rb, line 54
    def self.sanity_check(config)
      # eventually, check for table structure differences, etc
    end

look for tfile - return nil if not found

[Source]

# 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.expand_path path
      test('f', path) ? path : nil
    end

[Source]

# 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

[Validate]