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.



26
27
28
# File 'lib/embulk/input_hbase.rb', line 26

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

Class Method Details

.transaction(config, &control) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/embulk/input_hbase.rb', line 13

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/embulk/input_hbase.rb', line 30

def run
  conf = HBaseConfiguration.create
  conf.set('hbase.zookeeper.quorum', @task['host'])
  connection = HConnectionManager.createConnection(conf)
  table = connection.getTable(@task['table'])
  scan = Scan.new
  scanner = table.getScanner(scan)
  scanner.each { |result|
    @page_builder.add(@schema.map { |column|
      family, qualifier = column.name.split(':').map {|e|
        Bytes.toBytes(e)
      }
      raw = nil
      if result.containsColumn(family, qualifier) then
        cell = result.getColumnLatestCell(family, qualifier)
        raw = CellUtil.cloneValue(cell)
      end
      if raw then
        case column.type
        when :long
          Bytes.toLong(raw)
        when :string
          Bytes.toString(raw)
        else
          raw
        end
      else
        nil
      end
    })
  }
  @page_builder.finish
  commit_report = {
  }
  return commit_report
end