Class: MassiveRecord::Adapters::Thrift::Row
- Inherits:
-
Object
- Object
- MassiveRecord::Adapters::Thrift::Row
- Defined in:
- lib/massive_record/adapters/thrift/row.rb
Instance Attribute Summary collapse
-
#column_families ⇒ Object
Returns the value of attribute column_families.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#id ⇒ Object
Returns the value of attribute id.
-
#new_record ⇒ Object
Returns the value of attribute new_record.
-
#table ⇒ Object
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
- #atomic_decrement(column_name, by = 1) ⇒ Object
- #atomic_increment(column_name, by = 1) ⇒ Object
- #column_names ⇒ Object
- #destroy ⇒ Object
- #fetch_all_column_families ⇒ Object
- #fetch_column_families(list) ⇒ Object
-
#initialize(opts = {}) ⇒ Row
constructor
A new instance of Row.
- #new_record? ⇒ Boolean
- #prev ⇒ Object
- #read_atomic_integer_value(column_name) ⇒ Object
-
#save ⇒ Object
Parse columns cells and save them.
- #update_column(column_family_name, column_name, value) ⇒ Object
- #update_columns(data = {}) ⇒ Object
- #updated_at ⇒ Object
-
#values ⇒ Object
Parse columns / cells and create a Hash from them.
- #values=(data) ⇒ Object
-
#values_hash ⇒ Object
Returns values as a nested hash.
- #values_raw_data_hash ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Row
Returns a new instance of Row.
8 9 10 11 12 13 14 15 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 8 def initialize(opts = {}) @id = opts[:id] self.values = opts[:values] || {} @table = opts[:table] @column_families = opts[:column_families] || [] @columns = opts[:columns] || {} @new_record = true end |
Instance Attribute Details
#column_families ⇒ Object
Returns the value of attribute column_families.
6 7 8 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 6 def column_families @column_families end |
#columns ⇒ Object
Returns the value of attribute columns.
6 7 8 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 6 def columns @columns end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 6 def id @id end |
#new_record ⇒ Object
Returns the value of attribute new_record.
6 7 8 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 6 def new_record @new_record end |
#table ⇒ Object
Returns the value of attribute table.
6 7 8 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 6 def table @table end |
Class Method Details
.populate_from_trow_result(result, connection, table_name, column_families = []) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 128 def self.populate_from_trow_result(result, connection, table_name, column_families = []) row = self.new row.id = result.row row.new_record = false row.table = Table.new(connection, table_name) row.column_families = column_families result.columns.each do |name, value| row.columns[name] = MassiveRecord::Wrapper::Cell.populate_from_tcell(value) end row end |
Instance Method Details
#atomic_decrement(column_name, by = 1) ⇒ Object
120 121 122 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 120 def atomic_decrement(column_name, by = 1) atomic_increment(column_name, -by) end |
#atomic_increment(column_name, by = 1) ⇒ Object
116 117 118 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 116 def atomic_increment(column_name, by = 1) @table.client.atomicIncrement(@table.name, id.to_s, column_name, by) end |
#column_names ⇒ Object
17 18 19 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 17 def column_names columns.keys end |
#destroy ⇒ Object
142 143 144 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 142 def destroy @table.client.deleteAllRow(@table.name, @id).nil? end |
#fetch_all_column_families ⇒ Object
21 22 23 24 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 21 def fetch_all_column_families @table.fetch_column_family fetch_column_families(@table.column_family_names) end |
#fetch_column_families(list) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 26 def fetch_column_families(list) @column_families = table.column_families.collect do |column_name, description| MassiveRecord::Wrapper::ColumnFamily.new(column_name.split(":").first, { :row => self, :name => description.name, :max_versions => description.maxVersions, :compression => description.compression, :in_memory => description.inMemory # bloomFilterType, bloomFilterVectorSize, bloomFilterNbHashes, blockCacheEnabled, timeToLive }) end end |
#new_record? ⇒ Boolean
146 147 148 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 146 def new_record? @new_record end |
#prev ⇒ Object
150 151 152 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 150 def prev self end |
#read_atomic_integer_value(column_name) ⇒ Object
124 125 126 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 124 def read_atomic_integer_value(column_name) atomic_increment(column_name, 0) end |
#save ⇒ Object
Parse columns cells and save them
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 98 def save mutations = [] @columns.each do |column_name, cell| mutations << Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => column_name).tap do |mutation| if new_value = cell.value_to_thrift mutation.value = new_value else mutation.isDelete = true end end end @table.client.mutateRow(@table.name, id.to_s.dup.force_encoding(Encoding::BINARY), mutations).nil? end |
#update_column(column_family_name, column_name, value) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 87 def update_column(column_family_name, column_name, value) column = "#{column_family_name}:#{column_name}" if @columns[column].nil? @columns[column] = MassiveRecord::Wrapper::Cell.new({:value => value, :created_at => Time.now}) else @columns[column].value = value end end |
#update_columns(data = {}) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 79 def update_columns(data = {}) data.each do |column_family_name, columns| columns.each do |column_name, values| update_column(column_family_name, column_name, values) end end end |
#updated_at ⇒ Object
154 155 156 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 154 def updated_at columns.values.collect(&:created_at).max end |
#values ⇒ Object
Parse columns / cells and create a Hash from them
40 41 42 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 40 def values @columns.inject({"id" => id}) {|h, (column_name, cell)| h[column_name] = cell.value; h} end |
#values=(data) ⇒ Object
74 75 76 77 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 74 def values=(data) @values = {} update_columns(data) end |
#values_hash ⇒ Object
Returns values as a nested hash.
{
'family' => {
'attr1' => 'value'
'attr2' => 'value'
},
...
}
I think maybe that values should return this instead, as it is what the values= expects to receive.
56 57 58 59 60 61 62 63 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 56 def values_hash Hash.new { |hash, key| hash[key] = {} }.tap do |hash| @columns.each do |key, column| column_family, name = key.split(':') hash[column_family][name] = column.value end end end |
#values_raw_data_hash ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/massive_record/adapters/thrift/row.rb', line 65 def values_raw_data_hash Hash.new { |hash, key| hash[key] = {} }.tap do |hash| @columns.each do |key, column| column_family, name = key.split(':') hash[column_family][name] = MassiveRecord::ORM::RawData.new_with_data_from column end end end |