Class: HbaseAdapter::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, table_name) ⇒ Table

Returns a new instance of Table.



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

def initialize(connection, table_name)
  @connection = connection
  @table_name = table_name
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/hbase_adapter/table.rb', line 6

def connection
  @connection
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/hbase_adapter/table.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#[](row_key) ⇒ Object



48
49
50
# File 'lib/hbase_adapter/table.rb', line 48

def [](row_key)
  HbaseAdapter::Row.new(connection, self, row_key)
end

#columnsObject



37
38
39
40
41
42
# File 'lib/hbase_adapter/table.rb', line 37

def columns
  connection.client.getColumnDescriptors(table_name).inject({}) do|hash, (col_name, col)|
    hash[col_name.to_sym] = HbaseAdapter::ColumnFamily.new(col)
    hash
  end
end

#compact!Object



29
30
31
# File 'lib/hbase_adapter/table.rb', line 29

def compact!
  connection.client.compact(table_name)
end

#delete_row!(key, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/hbase_adapter/table.rb', line 52

def delete_row!(key, options = {})
  timestamp = options[:timestamp]
  
  if timestamp.nil?
    connection.client.deleteAllRow(table_name, key.to_s)
  else
    connection.client.deleteAllRowTs(table_name, key.to_s, timestamp.to_i64)
  end
end

#disable!Object



21
22
23
# File 'lib/hbase_adapter/table.rb', line 21

def disable!
  connection.client.disableTable(table_name)
end

#enable!Object



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

def enable!
  connection.client.enableTable(table_name)
end

#enabled?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/hbase_adapter/table.rb', line 25

def enabled?
  connection.client.isTableEnabled(table_name)
end

#major_compact!Object



33
34
35
# File 'lib/hbase_adapter/table.rb', line 33

def major_compact!
  connection.client.majorCompact(table_name)
end

#mutate!(options = {}, &blk) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hbase_adapter/table.rb', line 62

def mutate!(options = {}, &blk)
  timestamp = options[:timestamp]
  
  ml = HbaseAdapter::MutationList.new(&blk)
  
  if timestamp.nil?
    connection.client.mutateRows(table_name, ml.to_thrift)
  else
    connection.client.mutateRowsTs(table_name, ml.to_thrift, timestamp.to_i64)
  end
end

#nameObject



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

def name
  table_name
end

#regionsObject



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

def regions
  connection.client.getTableRegions(table_name)
end