Class: HBaseRb::Table

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

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Table

Returns a new instance of Table.



4
5
6
7
# File 'lib/hbaserb/table.rb', line 4

def initialize(client, name)
  @client = client
  @name = name
end

Instance Method Details

#atomic_increment(row, column, value = 1) ⇒ Object



44
45
46
# File 'lib/hbaserb/table.rb', line 44

def atomic_increment(row, column, value=1)
  call :atomicIncrement, row.to_s, column, value
end

#column_familiesObject



9
10
11
# File 'lib/hbaserb/table.rb', line 9

def column_families
  call :getColumnDescriptors
end

#create_scanner(start_row = nil, end_row = nil, *columns, &block) ⇒ Object

pass in no params to scan whole table



49
50
51
52
53
54
# File 'lib/hbaserb/table.rb', line 49

def create_scanner(start_row=nil, end_row=nil, *columns, &block)
  columns = (columns.length > 0) ? columns : column_families.keys 

  sid = call :scannerOpenWithStop, start_row.to_s, end_row.to_s, columns
  Scanner.new @client, sid, &block
end

#deleteObject



31
32
33
34
# File 'lib/hbaserb/table.rb', line 31

def delete
  call :disableTable
  call :deleteTable
end

#delete_cells(row, column) ⇒ Object



40
41
42
# File 'lib/hbaserb/table.rb', line 40

def delete_cells(row, column)
  call :deleteAll, row.to_s, column
end

#delete_row(row) ⇒ Object



36
37
38
# File 'lib/hbaserb/table.rb', line 36

def delete_row(row)
  call :deleteAllRow, row.to_s
end

#get(row, column) ⇒ Object



17
18
19
# File 'lib/hbaserb/table.rb', line 17

def get(row, column)
  call :get, row.to_s, column
end

#get_last(row, column, default = nil) ⇒ Object

get the last value for the given row / column



22
23
24
25
# File 'lib/hbaserb/table.rb', line 22

def get_last(row, column, default=nil)
  r = get(row, column)
  (r.length > 0) ? r.first.value : default
end

#get_row(row) ⇒ Object



27
28
29
# File 'lib/hbaserb/table.rb', line 27

def get_row(row)
  call :getRow, row.to_s
end

#mutate_row(row, mutations) ⇒ Object

mutations is a key / value pair to insert / update for the given row the keys are in the form “family:column”



58
59
60
61
# File 'lib/hbaserb/table.rb', line 58

def mutate_row(row, mutations)
  mutations = mutations.map { |k,v| Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => k, :value => v, :isDelete => v.nil?) }
  call :mutateRow, row, mutations
end

#regionsObject



13
14
15
# File 'lib/hbaserb/table.rb', line 13

def regions
  call :getTableRegions
end

#to_sObject



63
64
65
66
67
68
69
70
# File 'lib/hbaserb/table.rb', line 63

def to_s
  s = ""
  create_scanner { |r|
    cols = r.columns.map { |k,v| "#{k}: #{v.value}" }.join(", ")
    s += "#{r.row}: #{cols}\n"
  }
  s
end