| 16 | # under the License. |
| 17 | |
| 18 | class TestDictionaryArrayBuilder < Test::Unit::TestCase |
| 19 | include Helper::Buildable |
| 20 | |
| 21 | def setup |
| 22 | @values = [ |
| 23 | *%w(foo bar foo), |
| 24 | nil, |
| 25 | *%w(foo baz bar baz baz) |
| 26 | ] |
| 27 | end |
| 28 | |
| 29 | sub_test_case("BinaryDictionaryArrayBuilder") do |
| 30 | sub_test_case("constructed from empty") do |
| 31 | def setup |
| 32 | super |
| 33 | |
| 34 | @dictionary = %w(foo bar baz) |
| 35 | @dictionary_array = build_binary_array(@dictionary) |
| 36 | @indices = @values.map {|x| x ? @dictionary.index(x) : nil } |
| 37 | @indices_array = build_int8_array(@indices) |
| 38 | @data_type = Arrow::DictionaryDataType.new(@indices_array.value_data_type, |
| 39 | @dictionary_array.value_data_type, |
| 40 | false) |
| 41 | @expected_array = Arrow::DictionaryArray.new(@data_type, |
| 42 | @indices_array, |
| 43 | @dictionary_array) |
| 44 | @builder = Arrow::BinaryDictionaryArrayBuilder.new |
| 45 | @values.each do |value| |
| 46 | if value |
| 47 | @builder.append_value_bytes(value) |
| 48 | else |
| 49 | @builder.append_null |
| 50 | end |
| 51 | end |
| 52 | end |
| 53 | |
| 54 | test("append_value") do |
| 55 | dictionary_array = build_binary_array([*@dictionary, "qux"]) |
| 56 | indices_array = build_int8_array([*@indices, 3]) |
| 57 | expected_array = Arrow::DictionaryArray.new(@data_type, |
| 58 | indices_array, |
| 59 | dictionary_array) |
| 60 | |
| 61 | @builder.append_value("qux") |
| 62 | assert_equal(expected_array, @builder.finish) |
| 63 | end |
| 64 | |
| 65 | test("append_value_bytes") do |
| 66 | dictionary_array = build_binary_array([*@dictionary, "qux"]) |
| 67 | indices_array = build_int8_array([*@indices, 3]) |
| 68 | expected_array = Arrow::DictionaryArray.new(@data_type, |
| 69 | indices_array, |
| 70 | dictionary_array) |
| 71 | |
| 72 | @builder.append_value_bytes("qux") |
| 73 | assert_equal(expected_array, @builder.finish) |
| 74 | end |
| 75 |
nothing calls this directly
no test coverage detected