Class: Embulk::InputHBase

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input_hbase.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, schema, index, page_builder) ⇒ InputHBase

Returns a new instance of InputHBase.



20
21
22
# File 'lib/embulk/input_hbase.rb', line 20

def initialize(task, schema, index, page_builder)
  super
end

Class Method Details

.transaction(config, &control) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/embulk/input_hbase.rb', line 7

def self.transaction(config, &control)
  task = {
    'host' => config.param('host', :string, default: 'localhost'),
    'table' => config.param('table', :string)
  }
  threads = 1
  columns = config.param('columns', :array).map.with_index { |column, i|
    Column.new(i, column['name'], column['type'].to_sym)
  }
  commit_reports = yield(task, columns, threads)
  return {}
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/embulk/input_hbase.rb', line 24

def run
  HBase.resolve_dependency! '0.98'
  hbase = HBase.new('hbase.zookeeper.quorum' => @task['host'])
  table = hbase.table(@task['table'])
  table.each { |row|
    @page_builder.add(@schema.map { |column|
      value = row[column.name]
      case column.type
      when :long
        if value
          HBase::Util::from_bytes(:long, value)
        else
          0
        end
      when :string
        if value
          HBase::Util::from_bytes(:string, value)
        else
          ''
        end
      else
        value
      end
    })
  }
  @page_builder.finish
  commit_report = {
  }
  return commit_report
end