diff --git a/lib/aerospike/batch_read.rb b/lib/aerospike/batch_read.rb index ef0f093..2e10156 100644 --- a/lib/aerospike/batch_read.rb +++ b/lib/aerospike/batch_read.rb @@ -68,7 +68,7 @@ def self.ops(key, ops, opt = {}) # For internal use only. def ==(other) # :nodoc: other && other.instance_of?(self.class) && - @bin_names.sort == other.bin_names.sort && @ops.sort == other.ops.sort && + @bin_names&.sort == other.bin_names&.sort && @ops == other.ops && @policy == other.policy && @read_all_bins == other.read_all_bins end @@ -88,7 +88,7 @@ def size # :nodoc: raise AerospikeException.new(ResultCode::PARAMETER_ERROR, "Write operations not allowed in batch read") end size += op.bin_name.bytesize + Aerospike::OPERATION_HEADER_SIZE - size += op.value.estimate_size + size += op.bin_value.estimate_size end size diff --git a/lib/aerospike/command/batch_operate_command.rb b/lib/aerospike/command/batch_operate_command.rb index db816e8..c16b3ee 100644 --- a/lib/aerospike/command/batch_operate_command.rb +++ b/lib/aerospike/command/batch_operate_command.rb @@ -92,7 +92,7 @@ def write_buffer if record.bin_names&.length&.> 0 write_batch_bin_names(key, record.bin_names, attr, attr.filter_exp) elsif record.ops&.length&.> 0 - attr.adjust_read(br.ops) + attr.adjust_read(record.ops) write_batch_operations(key, record.ops, attr, attr.filter_exp) else attr.adjust_read_all_bins(record.read_all_bins) diff --git a/spec/aerospike/batch_operate_spec.rb b/spec/aerospike/batch_operate_spec.rb index a165f8e..5ad2d12 100644 --- a/spec/aerospike/batch_operate_spec.rb +++ b/spec/aerospike/batch_operate_spec.rb @@ -61,6 +61,23 @@ expect(records[0].record.bins.length).to eql 3 end + it 'returns bins specified with operations' do + ops = [ + Aerospike::Operation.get("idx"), + Aerospike::Operation.get("rnd") + ] + records = [ + Aerospike::BatchRead.ops(keys.first, ops), + Aerospike::BatchRead.ops(keys.last, ops) + ] + client.batch_operate(records, batch_policy) + + expect(records[0].result_code).to eql(0) + expect(records[1].result_code).to eql(0) + expect(records[0].record.bins).to eql({ "idx"=>0, "rnd"=>99 }) + expect(records[1].record.bins).to eql({ "idx"=>2, "rnd"=>99 }) + end + it 'filter out' do records = [Aerospike::BatchRead.read_all_bins(keys.first)] client.batch_operate(records, opts)