Class: OkHbase::Concerns::Table::Batch
- Inherits:
-
Object
- Object
- OkHbase::Concerns::Table::Batch
- Defined in:
- lib/ok_hbase/concerns/table/batch.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#batch_wrapper ⇒ Object
Returns the value of attribute batch_wrapper.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #delete(row_key, columns = nil) ⇒ Object
-
#initialize(table, timestamp = nil, batch_size = nil, transaction = false, &batch_wrapper) ⇒ Batch
constructor
A new instance of Batch.
- #put(row_key, data) ⇒ Object
- #send_batch ⇒ Object
- #transaction {|_self| ... } ⇒ Object
Constructor Details
#initialize(table, timestamp = nil, batch_size = nil, transaction = false, &batch_wrapper) ⇒ Batch
Returns a new instance of Batch.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 9 def initialize(table, = nil, batch_size = nil, transaction = false, &batch_wrapper) raise TypeError.new "'timestamp' must be an integer or nil" if && !.is_a?(Integer) if batch_size raise ArgumentError.new "'transaction' cannot be used when 'batch_size' is specified" if transaction raise ValueError.new "'batch_size' must be > 0" unless batch_size > 0 end @table = table @batch_size = batch_size = @transaction = transaction @batch_wrapper = batch_wrapper @families = nil _reset_mutations() end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
7 8 9 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 7 def batch_size @batch_size end |
#batch_wrapper ⇒ Object
Returns the value of attribute batch_wrapper.
6 7 8 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 6 def batch_wrapper @batch_wrapper end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
7 8 9 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 7 def table @table end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 7 def end |
Instance Method Details
#delete(row_key, columns = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 52 def delete(row_key, columns = nil) columns ||= @families ||= @table.send(:_column_family_names) @mutations[row_key] ||= [] columns.each do |column| @mutations[row_key] << Apache::Hadoop::Hbase::Thrift::Mutation.new(isDelete: true, column: column) end @mutation_count += columns.size send_batch if @batch_size && @mutation_count > @batch_size end |
#put(row_key, data) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 38 def put(row_key, data) @mutations[row_key] ||= [] data.each_pair do |column, value| @mutations[row_key] << Apache::Hadoop::Hbase::Thrift::Mutation.new( isDelete: false, column: column, value: value ) end @mutation_count += data.size send_batch if @batch_size && @mutation_count > @batch_size end |
#send_batch ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 28 def send_batch() if batch_wrapper batch_wrapper.call(@mutations) do _send_batch end else _send_batch end end |
#transaction {|_self| ... } ⇒ Object
65 66 67 68 |
# File 'lib/ok_hbase/concerns/table/batch.rb', line 65 def transaction yield self send_batch end |