Class: Hbase::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hbase_thrift_ruby.rb

Instance Method Summary collapse

Instance Method Details

#get(table, columns, filters, obj = {}) ⇒ Object



22
23
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
54
55
56
# File 'lib/hbase_thrift_ruby.rb', line 22

def get(table,columns,filters,obj={})
  scan = HBase::TScan.new
  scan.filterString = filters
  scanner = scannerOpenWithScan(table, scan, obj)
  
  results = []
  scan_end = false
  rows = []
  
  while !scan_end
    scan_result = scannerGet(scanner)
    if scan_result.length > 0
      rows << scan_result[0].row
    else
      scan_end = true
    end
  end
  
  rows.each do |row|
    row_results = []
    if columns[0] == '*'
      getRow(table,row,{})[0].columns.each do |val|
        row_results << val[1].value
      end
    else
      columns.each do |col|
        col = "#{col}:" if col.match(/:/).nil?
        row_results << getRow(table,row,{})[0].columns[col].value rescue row_results << nil
      end
    end
    results << row_results
  end
  
  results
end

#incrementRow(table_name, amount) ⇒ Object



16
17
18
19
20
21
# File 'lib/hbase_thrift_ruby.rb', line 16

def incrementRow(table_name,amount)
  c_row = get('table_indices','0',table_name,{})[0].value.to_i
  n_row = c_row+amount
  mutateRow('table_indices','0',[HBase::Mutation.new(column: table_name, value: n_row.to_s)],{})
  c_row
end