Class: HBase::Table
- Inherits:
-
Object
- Object
- HBase::Table
- Defined in:
- lib/hbase/table.rb
Constant Summary collapse
- TRANSLATION =
{ :start => :start_row, :end => :end_row }
Instance Attribute Summary collapse
-
#stargate ⇒ Object
readonly
Returns the value of attribute stargate.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #get(key, with_timestamps = false) ⇒ Object (also: #[])
- #include?(key) ⇒ Boolean (also: #exist?)
-
#initialize(stargate, table_name) ⇒ Table
constructor
A new instance of Table.
- #metadata ⇒ Object
- #scan(options = {}) ⇒ Object
- #update(key, attributes) ⇒ Object (also: #[]=)
Constructor Details
#initialize(stargate, table_name) ⇒ Table
Returns a new instance of Table.
5 6 7 |
# File 'lib/hbase/table.rb', line 5 def initialize(stargate, table_name) @stargate, @table_name = stargate, table_name end |
Instance Attribute Details
#stargate ⇒ Object (readonly)
Returns the value of attribute stargate.
3 4 5 |
# File 'lib/hbase/table.rb', line 3 def stargate @stargate end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
3 4 5 |
# File 'lib/hbase/table.rb', line 3 def table_name @table_name end |
Instance Method Details
#delete(key) ⇒ Object
34 35 36 |
# File 'lib/hbase/table.rb', line 34 def delete(key) stargate.delete_row table_name, key end |
#get(key, with_timestamps = false) ⇒ Object Also known as: []
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hbase/table.rb', line 9 def get(key, = false) begin record = Record.new record.id = key old_row = stargate.show_row(table_name, key) old_row.columns.each do |old_cell| record.cells[old_cell.name] = Cell.new old_cell.value, old_cell. end record rescue Stargate::RowNotFoundError nil end end |
#include?(key) ⇒ Boolean Also known as: exist?
38 39 40 |
# File 'lib/hbase/table.rb', line 38 def include?(key) !!get(key) end |
#metadata ⇒ Object
43 44 45 |
# File 'lib/hbase/table.rb', line 43 def stargate.show_table table_name end |
#scan(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hbase/table.rb', line 51 def scan( = {}) .symbolize_keys = {} .each do |k, v| [TRANSLATION[k] || k] = v end scanner = stargate.open_scanner(table_name, ) begin old_rows = stargate.get_rows(scanner) records = [] old_rows.each do |old_row| record = Record.new record.id = old_row.name old_row.columns.each do |old_cell| record.cells[old_cell.name] = Cell.new old_cell.value, old_cell. end records << record end records ensure stargate.close_scanner(scanner) if scanner end end |
#update(key, attributes) ⇒ Object Also known as: []=
24 25 26 27 28 29 30 31 |
# File 'lib/hbase/table.rb', line 24 def update(key, attributes) raise "ivalid usage, attributes should be a hash!" unless attributes.is_a? Hash = attributes.delete(:timestamp) || attributes.delete('timestamp') # || Time.now.to_i attr_in_driver_format = attributes.to_a.collect do |attr_name, attr_value| {:name => attr_name, :value => attr_value} end stargate.create_row(table_name, key, , attr_in_driver_format) end |