This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 154962c364 GH-50588: [Ruby] Add `ArrowFormat::Array#[]` (#50589)
154962c364 is described below
commit 154962c364bc210c10ef16680f54a115b624b400
Author: Sutou Kouhei <[email protected]>
AuthorDate: Wed Jul 22 13:42:25 2026 +0900
GH-50588: [Ruby] Add `ArrowFormat::Array#[]` (#50589)
### Rationale for this change
It's a convenient API to get a value at the given index.
### What changes are included in this PR?
Add `ArrowFormat::Array#[]`.
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
* GitHub Issue: #50588
Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow-format/lib/arrow-format/array.rb | 46 ++++++++++++++++++++++
ruby/red-arrow-format/lib/arrow-format/error.rb | 1 +
ruby/red-arrow-format/lib/arrow-format/type.rb | 1 +
ruby/red-arrow-format/test/test-binary-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-boolean-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-date32-array.rb | 12 ++++++
ruby/red-arrow-format/test/test-date64-array.rb | 12 ++++++
.../test/test-day-time-interval-array.rb | 19 +++++++++
ruby/red-arrow-format/test/test-duration-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-float32-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-float64-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-int16-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-int32-array.rb | 15 +++++++
ruby/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 +++++++
.../red-arrow-format/test/test-large-utf8-array.rb | 15 +++++++
.../test/test-month-day-nano-interval-array.rb | 19 +++++++++
ruby/red-arrow-format/test/test-null-array.rb | 8 ++++
ruby/red-arrow-format/test/test-time32-array.rb | 12 ++++++
ruby/red-arrow-format/test/test-time64-array.rb | 12 ++++++
ruby/red-arrow-format/test/test-timestamp-array.rb | 16 ++++++++
ruby/red-arrow-format/test/test-uint16-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-uint32-array.rb | 15 +++++++
ruby/red-arrow-format/test/test-uint64-array.rb | 15 +++++++
ruby/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 0a25ebf6b3..d190cc2992 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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 @@ module ArrowFormat
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 f6aebb3645..b82d10e2ae 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 4ba989515e..b52136769d 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 bcc122ccb0..78783b7996 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 @@ class TestBinaryArray < Test::Unit::TestCase
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 36a3c53daf..d5357b081c 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 @@ class TestBooleanArray < Test::Unit::TestCase
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 ee9b95df3c..ef98b8d902 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 @@ class TestDate32Array < Test::Unit::TestCase
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 5dcbdfc2cd..167911fe1c 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 @@ class TestDate64Array < Test::Unit::TestCase
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 477dde7cba..b7151190cd 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 @@ class TestDayTimeIntervalArray < Test::Unit::TestCase
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 92362c2e4d..24d0bd98a0 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 @@ class TestDurationArray < Test::Unit::TestCase
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 1769bb2d3f..243c46b235 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 @@ class TestFloat32Array < Test::Unit::TestCase
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 22393637cf..92099f1cd0 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 @@ class TestFloat64Array < Test::Unit::TestCase
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 f98650895a..ddfdcc5ddc 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 @@ class TestInt16Array < Test::Unit::TestCase
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 343c2cc610..9940a323f4 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 @@ class TestInt32Array < Test::Unit::TestCase
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 d265b5da71..b5db1d163c 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 @@ class TestInt64Array < Test::Unit::TestCase
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 8c802a9b7f..459674f9fd 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 @@ class TestInt8Array < Test::Unit::TestCase
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 67e55dd1b6..0fc7a11328 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 @@ class TestLargeBinaryArray < Test::Unit::TestCase
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 1ee4a39945..084f3b5ff9 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 @@ class TestLargeUTF8Array < Test::Unit::TestCase
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 1c965c6813..26842d9302 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 @@ class TestMonthDayNanoIntervalArray < Test::Unit::TestCase
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 961f2cd8d4..c66de5517e 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 @@ class TestNullArray < Test::Unit::TestCase
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 98e865d9e2..74a01dc6d7 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 @@ class TestTime32Array < Test::Unit::TestCase
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 3625a1917f..dd7a08ad2f 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 @@ class TestTime64Array < Test::Unit::TestCase
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 397a01a64f..c2f73e366c 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 @@ class TestTimestampArray < Test::Unit::TestCase
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 736cb7494a..3c5ad6acea 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 @@ class TestUInt16Array < Test::Unit::TestCase
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 ab6188d7b6..079a96cbf5 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 @@ class TestUInt32Array < Test::Unit::TestCase
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 781bc6376d..c438082735 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 @@ class TestUInt64Array < Test::Unit::TestCase
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 ae33f910ef..bd03aa0efb 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 @@ class TestUInt8Array < Test::Unit::TestCase
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 2970d77793..eb6e669e2e 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 @@ class TestUTF8Array < Test::Unit::TestCase
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 5004dfb9b0..29bd61a1ef 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 @@ class TestYearMonthIntervalArray < Test::Unit::TestCase
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