Class: HbaseAdapter::Row
- Inherits:
-
Object
- Object
- HbaseAdapter::Row
- Defined in:
- lib/hbase_adapter/row.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #[](column, options = {}) ⇒ Object
- #cells(*columns) ⇒ Object
- #delete!(col, options = {}) ⇒ Object
-
#initialize(connection, table, key) ⇒ Row
constructor
A new instance of Row.
- #mutate!(options = {}, &blk) ⇒ Object
Constructor Details
#initialize(connection, table, key) ⇒ Row
Returns a new instance of Row.
8 9 10 11 12 |
# File 'lib/hbase_adapter/row.rb', line 8 def initialize(connection, table, key) @connection = connection @table = table @key = key end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/hbase_adapter/row.rb', line 6 def connection @connection end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/hbase_adapter/row.rb', line 6 def key @key end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/hbase_adapter/row.rb', line 6 def table @table end |
Instance Method Details
#[](column, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hbase_adapter/row.rb', line 14 def [](column, = {}) num_versions = [:num_versions] = [:timestamp] if num_versions.nil? && .nil? # One column, no options. Simple get. Return a single cell tcell = connection.client.get(table.name, key, column).first HbaseAdapter::Cell.new(connection, self, column, tcell) if tcell else if .nil? # One column, versions specified. getVer tcells = connection.client.getVer(table.name, key, column, num_versions) else # One column, versions specified, max time specified. getVerTs tcells = connection.client.getVerTs(table.name, key, column, .to_i64, num_versions) end tcells.compact.map {|tcell| HbaseAdapter::Cell.new(connection, self, column, tcell)} end end |
#cells(*columns) ⇒ Object
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 |
# File 'lib/hbase_adapter/row.rb', line 35 def cells(*columns) = columns.pop if columns.last.is_a?(Hash) ||= {} = [:timestamp] if columns.empty? if .nil? # getRow trow_results = connection.client.getRow(table.name, key) else # getRowTs trow_results = connection.client.getRowTs(table.name, key, .to_i64) end else if .nil? # getRowWithColumns trow_results = connection.client.getRowWithColumns(table.name, key, columns) else # getRowWithColumnsTs trow_results = connection.client.getRowWithColumnsTs(table.name, key, columns, .to_i64) end end unless trow_results.empty? trow_results.first.columns.inject({}) do |hash, (col_name, tcell)| hash[col_name.to_sym] = HbaseAdapter::Cell.new(connection, self, col_name, tcell) if tcell hash end end end |
#delete!(col, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/hbase_adapter/row.rb', line 66 def delete!(col, = {}) = [:timestamp] if .nil? connection.client.deleteAll(table.name, key.to_s, col.to_s) else connection.client.deleteAllTs(table.name, key.to_s, col.to_s, .to_i64) end end |
#mutate!(options = {}, &blk) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/hbase_adapter/row.rb', line 76 def mutate!( = {}, &blk) = [:timestamp] ml = HbaseAdapter::MutationList.new(&blk) if .nil? connection.client.mutateRow(table.name, key, ml.to_thrift) else connection.client.mutateRowTs(table.name, key, ml.to_thrift, .to_i64) end end |