From 0673e2514a1c1480a0d24546b11c18237ec7ab03 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Wed, 22 Jul 2026 11:53:24 +0900 Subject: [PATCH] GH-50588: [Ruby] Add `ArrowFormat::Array#[]` --- .../lib/arrow-format/array.rb | 46 +++++++++++++++++++ .../lib/arrow-format/error.rb | 1 + .../red-arrow-format/lib/arrow-format/type.rb | 1 + .../test/test-binary-array.rb | 15 ++++++ .../test/test-boolean-array.rb | 15 ++++++ .../test/test-date32-array.rb | 12 +++++ .../test/test-date64-array.rb | 12 +++++ .../test/test-day-time-interval-array.rb | 19 ++++++++ .../test/test-duration-array.rb | 15 ++++++ .../test/test-float32-array.rb | 15 ++++++ .../test/test-float64-array.rb | 15 ++++++ .../red-arrow-format/test/test-int16-array.rb | 15 ++++++ .../red-arrow-format/test/test-int32-array.rb | 15 ++++++ .../red-arrow-format/test/test-int64-array.rb | 15 ++++++ ruby/red-arrow-format/test/test-int8-array.rb | 15 ++++++ .../test/test-large-binary-array.rb | 15 ++++++ .../test/test-large-utf8-array.rb | 15 ++++++ .../test-month-day-nano-interval-array.rb | 19 ++++++++ ruby/red-arrow-format/test/test-null-array.rb | 8 ++++ .../test/test-time32-array.rb | 12 +++++ .../test/test-time64-array.rb | 12 +++++ .../test/test-timestamp-array.rb | 16 +++++++ .../test/test-uint16-array.rb | 15 ++++++ .../test/test-uint32-array.rb | 15 ++++++ .../test/test-uint64-array.rb | 15 ++++++ .../red-arrow-format/test/test-uint8-array.rb | 15 ++++++ ruby/red-arrow-format/test/test-utf8-array.rb | 15 ++++++ .../test/test-year-month-interval-array.rb | 15 ++++++ 28 files changed, 413 insertions(+) diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb b/ruby/red-arrow-format/lib/arrow-format/array.rb index 0a25ebf6b3ba..d190cc29923e 100644 --- a/ruby/red-arrow-format/lib/arrow-format/array.rb +++ b/ruby/red-arrow-format/lib/arrow-format/array.rb @@ -61,6 +61,14 @@ def null?(i) not valid?(i) end + def [](i) + if valid?(i) + unpack_value(i) + else + nil + end + end + def n_nulls if @validity_buffer.nil? 0 @@ -167,6 +175,14 @@ def initialize(size) super(NullType.singleton, size, nil) end + def valid?(i) + false + end + + def null?(i) + true + end + def each_buffer return to_enum(__method__) unless block_given? end @@ -294,6 +310,11 @@ def pack_value(value, template, type) value = 0 if value.nil? [value].pack(template) end + + def unpack_value(i) + offset = element_size * (@offset + i) + @values_buffer.get_value(@type.buffer_type, offset) + end end class BooleanArray < PrimitiveArray @@ -362,6 +383,10 @@ def build_data(data, type) validity_buffer = validity_buffer_builder&.finish(n) return n, validity_buffer, values_buffer_builder.finish end + + def unpack_value(i) + values_bitmap[i] + end end class IntArray < PrimitiveArray @@ -600,6 +625,11 @@ def pack_value(value, template, type) value.pack(template) end end + + def unpack_value(i) + offset = element_size * (@offset + i) + @values_buffer.get_values([@type.buffer_type] * 2, offset) + end end class MonthDayNanoIntervalArray < IntervalArray @@ -661,6 +691,13 @@ def pack_value(value, template, type) value.pack(template) end end + + def unpack_value(i) + buffer_types = @type.buffer_types + value_size = IO::Buffer.size_of(buffer_types) + offset = value_size * (@offset + i) + @values_buffer.get_values(buffer_types, offset) + end end class DurationArray < TemporalArray @@ -768,6 +805,15 @@ def build_data(data) def offset_size IO::Buffer.size_of(@type.offset_buffer_type) end + + def unpack_value(i) + offset_types = [@type.offset_buffer_type] * 2 + offsets_offset = offset_size * (@offset + i) + offset, next_offset = @offsets_buffer.get_values(offset_types, + offsets_offset) + length = next_offset - offset + @values_buffer.get_string(offset, length, @type.encoding) + end end class BinaryArray < VariableSizeBinaryArray diff --git a/ruby/red-arrow-format/lib/arrow-format/error.rb b/ruby/red-arrow-format/lib/arrow-format/error.rb index f6aebb364552..b82d10e2ae46 100644 --- a/ruby/red-arrow-format/lib/arrow-format/error.rb +++ b/ruby/red-arrow-format/lib/arrow-format/error.rb @@ -1,3 +1,4 @@ +# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file diff --git a/ruby/red-arrow-format/lib/arrow-format/type.rb b/ruby/red-arrow-format/lib/arrow-format/type.rb index 4ba989515e8f..b52136769d47 100644 --- a/ruby/red-arrow-format/lib/arrow-format/type.rb +++ b/ruby/red-arrow-format/lib/arrow-format/type.rb @@ -1,3 +1,4 @@ +# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file diff --git a/ruby/red-arrow-format/test/test-binary-array.rb b/ruby/red-arrow-format/test/test-binary-array.rb index bcc122ccb042..78783b7996b7 100644 --- a/ruby/red-arrow-format/test/test-binary-array.rb +++ b/ruby/red-arrow-format/test/test-binary-array.rb @@ -16,6 +16,11 @@ # under the License. class TestBinaryArray < Test::Unit::TestCase + def setup + @values = ["\x00\x01".b, nil, "\xff\x10".b] + @array = ArrowFormat::BinaryArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = ["\x00\x01".b, "\xff\x10".b] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-boolean-array.rb b/ruby/red-arrow-format/test/test-boolean-array.rb index 36a3c53dafc8..d5357b081ca9 100644 --- a/ruby/red-arrow-format/test/test-boolean-array.rb +++ b/ruby/red-arrow-format/test/test-boolean-array.rb @@ -16,6 +16,11 @@ # under the License. class TestBooleanArray < Test::Unit::TestCase + def setup + @values = [true, nil, false] + @array = ArrowFormat::BooleanArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null assert_equal([true, false], @@ -53,4 +58,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-date32-array.rb b/ruby/red-arrow-format/test/test-date32-array.rb index ee9b95df3cab..ef98b8d902f7 100644 --- a/ruby/red-arrow-format/test/test-date32-array.rb +++ b/ruby/red-arrow-format/test/test-date32-array.rb @@ -19,6 +19,8 @@ class TestDate32Array < Test::Unit::TestCase def setup @date_2017_08_28 = 17406 @date_2025_12_09 = 20431 + @values = [@date_2017_08_28, nil, @date_2025_12_09] + @array = ArrowFormat::Date32Array.new(@values) end sub_test_case("#initialize") do @@ -57,4 +59,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-date64-array.rb b/ruby/red-arrow-format/test/test-date64-array.rb index 5dcbdfc2cd66..167911fe1cd3 100644 --- a/ruby/red-arrow-format/test/test-date64-array.rb +++ b/ruby/red-arrow-format/test/test-date64-array.rb @@ -19,6 +19,8 @@ class TestDate64Array < Test::Unit::TestCase def setup @date_2017_08_28_00_00_00 = 1503878400000 @date_2025_12_10_00_00_00 = 1765324800000 + @values = [@date_2017_08_28_00_00_00, nil, @date_2025_12_10_00_00_00] + @array = ArrowFormat::Date64Array.new(@values) end sub_test_case("#initialize") do @@ -57,4 +59,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-day-time-interval-array.rb b/ruby/red-arrow-format/test/test-day-time-interval-array.rb index 477dde7cba88..b7151190cda4 100644 --- a/ruby/red-arrow-format/test/test-day-time-interval-array.rb +++ b/ruby/red-arrow-format/test/test-day-time-interval-array.rb @@ -16,6 +16,15 @@ # under the License. class TestDayTimeIntervalArray < Test::Unit::TestCase + def setup + @values = [ + [1, 100], + nil, + [3, 300], + ] + @array = ArrowFormat::DayTimeIntervalArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [ @@ -85,4 +94,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-duration-array.rb b/ruby/red-arrow-format/test/test-duration-array.rb index 92362c2e4d89..24d0bd98a0b8 100644 --- a/ruby/red-arrow-format/test/test-duration-array.rb +++ b/ruby/red-arrow-format/test/test-duration-array.rb @@ -16,6 +16,11 @@ # under the License. class TestDurationArray < Test::Unit::TestCase + def setup + @values = [-(2 ** 63), nil, (2 ** 63) - 1] + @array = ArrowFormat::DurationArray.new(:second, @values) + end + sub_test_case("#initialize") do def test_no_null values = [-(2 ** 63), (2 ** 63) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-float32-array.rb b/ruby/red-arrow-format/test/test-float32-array.rb index 1769bb2d3fbb..243c46b23507 100644 --- a/ruby/red-arrow-format/test/test-float32-array.rb +++ b/ruby/red-arrow-format/test/test-float32-array.rb @@ -16,6 +16,11 @@ # under the License. class TestFloat32Array < Test::Unit::TestCase + def setup + @values = [-Float::INFINITY, nil, +Float::INFINITY] + @array = ArrowFormat::Float32Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-Float::INFINITY, -0.0, +0.0, +Float::INFINITY] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 5)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-float64-array.rb b/ruby/red-arrow-format/test/test-float64-array.rb index 22393637cfa9..92099f1cd06d 100644 --- a/ruby/red-arrow-format/test/test-float64-array.rb +++ b/ruby/red-arrow-format/test/test-float64-array.rb @@ -16,6 +16,11 @@ # under the License. class TestFloat64Array < Test::Unit::TestCase + def setup + @values = [-Float::INFINITY, nil, +Float::INFINITY] + @array = ArrowFormat::Float64Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-Float::INFINITY, -0.0, +0.0, +Float::INFINITY] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 5)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-int16-array.rb b/ruby/red-arrow-format/test/test-int16-array.rb index f98650895af6..ddfdcc5ddc53 100644 --- a/ruby/red-arrow-format/test/test-int16-array.rb +++ b/ruby/red-arrow-format/test/test-int16-array.rb @@ -16,6 +16,11 @@ # under the License. class TestInt16Array < Test::Unit::TestCase + def setup + @values = [-(2 ** 15), nil, (2 ** 15) - 1] + @array = ArrowFormat::Int16Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-(2 ** 15), (2 ** 15) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-int32-array.rb b/ruby/red-arrow-format/test/test-int32-array.rb index 343c2cc61064..9940a323f452 100644 --- a/ruby/red-arrow-format/test/test-int32-array.rb +++ b/ruby/red-arrow-format/test/test-int32-array.rb @@ -16,6 +16,11 @@ # under the License. class TestInt32Array < Test::Unit::TestCase + def setup + @values = [-(2 ** 31), nil, (2 ** 31) - 1] + @array = ArrowFormat::Int32Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-(2 ** 31), (2 ** 31) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-int64-array.rb b/ruby/red-arrow-format/test/test-int64-array.rb index d265b5da7184..b5db1d163c79 100644 --- a/ruby/red-arrow-format/test/test-int64-array.rb +++ b/ruby/red-arrow-format/test/test-int64-array.rb @@ -16,6 +16,11 @@ # under the License. class TestInt64Array < Test::Unit::TestCase + def setup + @values = [-(2 ** 63), nil, (2 ** 63) - 1] + @array = ArrowFormat::Int64Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-(2 ** 63), (2 ** 63) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-int8-array.rb b/ruby/red-arrow-format/test/test-int8-array.rb index 8c802a9b7f3d..459674f9fd20 100644 --- a/ruby/red-arrow-format/test/test-int8-array.rb +++ b/ruby/red-arrow-format/test/test-int8-array.rb @@ -16,6 +16,11 @@ # under the License. class TestInt8Array < Test::Unit::TestCase + def setup + @values = [-(2 ** 7), nil, (2 ** 7) - 1] + @array = ArrowFormat::Int8Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [-(2 ** 7), (2 ** 7) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-large-binary-array.rb b/ruby/red-arrow-format/test/test-large-binary-array.rb index 67e55dd1b68b..0fc7a1132808 100644 --- a/ruby/red-arrow-format/test/test-large-binary-array.rb +++ b/ruby/red-arrow-format/test/test-large-binary-array.rb @@ -16,6 +16,11 @@ # under the License. class TestLargeBinaryArray < Test::Unit::TestCase + def setup + @values = ["\x00\x01".b, nil, "\xff\x10".b] + @array = ArrowFormat::LargeBinaryArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = ["\x00\x01".b, "\xff\x10".b] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-large-utf8-array.rb b/ruby/red-arrow-format/test/test-large-utf8-array.rb index 1ee4a3994512..084f3b5ff9a0 100644 --- a/ruby/red-arrow-format/test/test-large-utf8-array.rb +++ b/ruby/red-arrow-format/test/test-large-utf8-array.rb @@ -16,6 +16,11 @@ # under the License. class TestLargeUTF8Array < Test::Unit::TestCase + def setup + @values = ["Hello", nil, "World"] + @array = ArrowFormat::LargeUTF8Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = ["Hello", "World"] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb b/ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb index 1c965c6813c1..26842d930246 100644 --- a/ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb +++ b/ruby/red-arrow-format/test/test-month-day-nano-interval-array.rb @@ -16,6 +16,15 @@ # under the License. class TestMonthDayNanoIntervalArray < Test::Unit::TestCase + def setup + @values = [ + [1, 1, 100], + nil, + [3, 3, 300], + ] + @array = ArrowFormat::MonthDayNanoIntervalArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [ @@ -90,4 +99,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-null-array.rb b/ruby/red-arrow-format/test/test-null-array.rb index 961f2cd8d49f..c66de5517ef3 100644 --- a/ruby/red-arrow-format/test/test-null-array.rb +++ b/ruby/red-arrow-format/test/test-null-array.rb @@ -16,6 +16,10 @@ # under the License. class TestNullArray < Test::Unit::TestCase + def setup + @array = ArrowFormat::NullArray.new(3) + end + def test_initialize assert_equal([nil] * 9, ArrowFormat::NullArray.new(9).to_a) @@ -34,4 +38,8 @@ def test_sliced assert_equal(array1, array2.slice(1, 3)) end end + + def test_aref + assert_nil(@array[1]) + end end diff --git a/ruby/red-arrow-format/test/test-time32-array.rb b/ruby/red-arrow-format/test/test-time32-array.rb index 98e865d9e25c..74a01dc6d75e 100644 --- a/ruby/red-arrow-format/test/test-time32-array.rb +++ b/ruby/red-arrow-format/test/test-time32-array.rb @@ -19,6 +19,8 @@ class TestTime32Array < Test::Unit::TestCase def setup @time_00_00_10 = 10 @time_00_01_10 = 60 + 10 + @values = [@time_00_00_10, nil, @time_00_01_10] + @array = ArrowFormat::Time32Array.new(:second, @values) end sub_test_case("#initialize") do @@ -57,4 +59,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-time64-array.rb b/ruby/red-arrow-format/test/test-time64-array.rb index 3625a1917f27..dd7a08ad2fd3 100644 --- a/ruby/red-arrow-format/test/test-time64-array.rb +++ b/ruby/red-arrow-format/test/test-time64-array.rb @@ -19,6 +19,8 @@ class TestTime64Array < Test::Unit::TestCase def setup @time_00_00_10_000_000 = 10 * 1_000_000 @time_00_01_10_000_000 = (60 + 10) * 1_000_000 + @values = [@time_00_00_10_000_000, nil, @time_00_01_10_000_000] + @array = ArrowFormat::Time64Array.new(:microsecond, @values) end sub_test_case("#initialize") do @@ -57,4 +59,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-timestamp-array.rb b/ruby/red-arrow-format/test/test-timestamp-array.rb index 397a01a64f02..c2f73e366c07 100644 --- a/ruby/red-arrow-format/test/test-timestamp-array.rb +++ b/ruby/red-arrow-format/test/test-timestamp-array.rb @@ -19,6 +19,12 @@ class TestTimestampArray < Test::Unit::TestCase def setup @timestamp_2019_11_17_15_09_11 = 1574003351 @timestamp_2025_12_16_05_33_58 = 1765863238 + @values = [ + @timestamp_2019_11_17_15_09_11, + nil, + @timestamp_2025_12_16_05_33_58, + ] + @array = ArrowFormat::TimestampArray.new(:second, @values) end sub_test_case("#initialize") do @@ -83,4 +89,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-uint16-array.rb b/ruby/red-arrow-format/test/test-uint16-array.rb index 736cb7494a47..3c5ad6aceab5 100644 --- a/ruby/red-arrow-format/test/test-uint16-array.rb +++ b/ruby/red-arrow-format/test/test-uint16-array.rb @@ -16,6 +16,11 @@ # under the License. class TestUInt16Array < Test::Unit::TestCase + def setup + @values = [0, nil, (2 ** 16) - 1] + @array = ArrowFormat::UInt16Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [0, (2 ** 16) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-uint32-array.rb b/ruby/red-arrow-format/test/test-uint32-array.rb index ab6188d7b6eb..079a96cbf59b 100644 --- a/ruby/red-arrow-format/test/test-uint32-array.rb +++ b/ruby/red-arrow-format/test/test-uint32-array.rb @@ -16,6 +16,11 @@ # under the License. class TestUInt32Array < Test::Unit::TestCase + def setup + @values = [0, nil, (2 ** 32) - 1] + @array = ArrowFormat::UInt32Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [0, (2 ** 32) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-uint64-array.rb b/ruby/red-arrow-format/test/test-uint64-array.rb index 781bc6376d15..c43808273577 100644 --- a/ruby/red-arrow-format/test/test-uint64-array.rb +++ b/ruby/red-arrow-format/test/test-uint64-array.rb @@ -16,6 +16,11 @@ # under the License. class TestUInt64Array < Test::Unit::TestCase + def setup + @values = [0, nil, (2 ** 64) - 1] + @array = ArrowFormat::UInt64Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [0, (2 ** 64) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-uint8-array.rb b/ruby/red-arrow-format/test/test-uint8-array.rb index ae33f910ef21..bd03aa0efbc9 100644 --- a/ruby/red-arrow-format/test/test-uint8-array.rb +++ b/ruby/red-arrow-format/test/test-uint8-array.rb @@ -16,6 +16,11 @@ # under the License. class TestUInt8Array < Test::Unit::TestCase + def setup + @values = [0, nil, (2 ** 8) - 1] + @array = ArrowFormat::UInt8Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [0, (2 ** 8) - 1] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-utf8-array.rb b/ruby/red-arrow-format/test/test-utf8-array.rb index 2970d77793e2..eb6e669e2e5a 100644 --- a/ruby/red-arrow-format/test/test-utf8-array.rb +++ b/ruby/red-arrow-format/test/test-utf8-array.rb @@ -16,6 +16,11 @@ # under the License. class TestUTF8Array < Test::Unit::TestCase + def setup + @values = ["Hello", nil, "World"] + @array = ArrowFormat::UTF8Array.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = ["Hello", "World"] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end diff --git a/ruby/red-arrow-format/test/test-year-month-interval-array.rb b/ruby/red-arrow-format/test/test-year-month-interval-array.rb index 5004dfb9b02c..29bd61a1ef6c 100644 --- a/ruby/red-arrow-format/test/test-year-month-interval-array.rb +++ b/ruby/red-arrow-format/test/test-year-month-interval-array.rb @@ -16,6 +16,11 @@ # under the License. class TestYearMonthIntervalArray < Test::Unit::TestCase + def setup + @values = [0, nil, 100] + @array = ArrowFormat::YearMonthIntervalArray.new(@values) + end + sub_test_case("#initialize") do def test_no_null values = [0, 100] @@ -52,4 +57,14 @@ def test_sliced_different_content assert_not_equal(array1, array2.slice(1, 3)) end end + + sub_test_case("#[]") do + def test_valid + assert_equal(@values[3], @array[3]) + end + + def test_null + assert_nil(@array[1]) + end + end end