Sha256: 08a1a80f989ac59618bbeec6a7542701c6e157a15af6dac0b5191977df8139f5

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'util'

module HadoopDsl
  class MapRedFactory
    def self.dsl_name(script)
      read_file(script).each_line do |line|
        dsl_name = $1 if line =~ /^use\s*'(\w*)'/
        return dsl_name
      end
    end

    def self.require_dsl_lib(dsl_name)
      require snake_case(dsl_name)
    end
  end

  class MapperFactory < MapRedFactory
    def self.create(script, key, value)
      dsl_name = self.dsl_name(script)
      require_dsl_lib(dsl_name)
      mapper_class = "HadoopDsl::#{dsl_name}::#{dsl_name}Mapper" 
      return eval(mapper_class).new(script, key, value)
    end
  end

  class ReducerFactory < MapRedFactory
    def self.create(script, key, values)
      dsl_name = self.dsl_name(script)
      require_dsl_lib(dsl_name)
      reducer_class = "HadoopDsl::#{dsl_name}::#{dsl_name}Reducer" 
      return eval(reducer_class).new(script, key, values)
    end
  end

  class SetupFactory < MapRedFactory
    def self.create(script, conf)
      dsl_name = self.dsl_name(script)
      require_dsl_lib(dsl_name)
      setup_class = "HadoopDsl::#{dsl_name}::#{dsl_name}Setup" 
      eval(setup_class).new(script, conf) rescue HadoopDsl::BaseSetup.new(script, conf)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hadoop-rubydsl-0.0.3 lib/mapred_factory.rb
hadoop-rubydsl-0.0.2 lib/mapred_factory.rb
hadoop-rubydsl-0.0.1 lib/mapred_factory.rb