| 16 | # under the License. |
| 17 | |
| 18 | class RecordBatchTest < Test::Unit::TestCase |
| 19 | sub_test_case(".new") do |
| 20 | def setup |
| 21 | @schema = Arrow::Schema.new(visible: :boolean, |
| 22 | count: :uint32) |
| 23 | end |
| 24 | |
| 25 | test("[raw_table]") do |
| 26 | raw_table = { |
| 27 | visible: [true, nil, false], |
| 28 | count: [1, nil, 3], |
| 29 | } |
| 30 | record_batch = Arrow::RecordBatch.new(raw_table) |
| 31 | assert_equal([ |
| 32 | {"visible" => true, "count" => 1}, |
| 33 | {"visible" => nil, "count" => nil}, |
| 34 | {"visible" => false, "count" => 3}, |
| 35 | ], |
| 36 | record_batch.each_record.collect(&:to_h)) |
| 37 | end |
| 38 | |
| 39 | test("[Schema, records]") do |
| 40 | records = [ |
| 41 | {visible: true, count: 1}, |
| 42 | nil, |
| 43 | [false, 3], |
| 44 | ] |
| 45 | record_batch = Arrow::RecordBatch.new(@schema, records) |
| 46 | assert_equal([ |
| 47 | {"visible" => true, "count" => 1}, |
| 48 | {"visible" => nil, "count" => nil}, |
| 49 | {"visible" => false, "count" => 3}, |
| 50 | ], |
| 51 | record_batch.each_record.collect(&:to_h)) |
| 52 | end |
| 53 | |
| 54 | test("[Schema, columns]") do |
| 55 | columns = { |
| 56 | visible: [true, nil, false], |
| 57 | count: [1, 2, nil], |
| 58 | } |
| 59 | record_batch = Arrow::RecordBatch.new(@schema, columns) |
| 60 | assert_equal([ |
| 61 | {"visible" => true, "count" => 1}, |
| 62 | {"visible" => nil, "count" => 2}, |
| 63 | {"visible" => false, "count" => nil}, |
| 64 | ], |
| 65 | record_batch.each_record.collect(&:to_h)) |
| 66 | end |
| 67 | |
| 68 | test("[Schema, n_rows, columns]") do |
| 69 | columns = [ |
| 70 | Arrow::BooleanArray.new([true, nil, false]), |
| 71 | Arrow::UInt32Array.new([1, 2, nil]), |
| 72 | ] |
| 73 | n_rows = columns[0].length |
| 74 | record_batch = Arrow::RecordBatch.new(@schema, n_rows, columns) |
| 75 | assert_equal([ |