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 e191b95db5 GH-50432: [Ruby] Add `ArrowFormat::{Array,Bitmap}#==`
(#50433)
e191b95db5 is described below
commit e191b95db55571d31e15c404c2d2c453477919ba
Author: Sutou Kouhei <[email protected]>
AuthorDate: Thu Jul 9 15:15:10 2026 +0900
GH-50432: [Ruby] Add `ArrowFormat::{Array,Bitmap}#==` (#50433)
### Rationale for this change
Comparing 2 bitmaps/arrays is a common operation. We should provide content
based (not identity based) comparition feature.
### What changes are included in this PR?
* Add `ArrowFormat::Bitmap#==`
* Add `ArrowFormat::Bitmap#offset`
* Add `ArrowFormat::Bitmap#size`
* Add `ArrowFormat::Bitmap#length`
* Make `ArrowFormat::Array` enumerable
* Add `ArrowFormat::Array#==`
* Add `ArrowFormat::NullArray#each`
* Add `ArrowFormat::PrimiveArray#each`
* Add `ArrowFormat::BooleanArray#each`
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
* GitHub Issue: #50432
Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow-format/lib/arrow-format/array.rb | 82 +++++++++++++++++--
ruby/red-arrow-format/lib/arrow-format/bitmap.rb | 30 +++++--
ruby/red-arrow-format/test/test-bitmap.rb | 34 ++++++++
ruby/red-arrow-format/test/test-boolean-array.rb | 56 +++++++++++++
ruby/red-arrow-format/test/test-float32-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-float64-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-int16-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-int32-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-int64-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-int8-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-null-array.rb | 37 +++++++++
ruby/red-arrow-format/test/test-primitive-array.rb | 94 ----------------------
ruby/red-arrow-format/test/test-uint16-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-uint32-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-uint64-array.rb | 55 +++++++++++++
ruby/red-arrow-format/test/test-uint8-array.rb | 55 +++++++++++++
16 files changed, 779 insertions(+), 104 deletions(-)
diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb
b/ruby/red-arrow-format/lib/arrow-format/array.rb
index 37ed813590..2cccb7013b 100644
--- a/ruby/red-arrow-format/lib/arrow-format/array.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/array.rb
@@ -24,6 +24,8 @@ module ArrowFormat
using FlatBuffers::AppendAsBytes if
FlatBuffers.const_defined?(:AppendAsBytes)
class Array
+ include Enumerable
+
attr_reader :type
attr_reader :size
alias_method :length, :size
@@ -64,6 +66,16 @@ module ArrowFormat
@size.zero?
end
+ def ==(other)
+ return false unless other.is_a?(self.class)
+ return false unless @size == other.size
+ return true if @validity_buffer.nil? and other.validity_buffer.nil?
+ if @offset == other.offset and @validity_buffer == other.validity_buffer
+ return true
+ end
+ validity_bitmap == other.validity_bitmap
+ end
+
protected
def slice!(offset, size)
@offset = offset
@@ -71,11 +83,11 @@ module ArrowFormat
clear_cache
end
- private
def validity_bitmap
@validity_bitmap ||= Bitmap.new(@validity_buffer, @offset, @size)
end
+ private
def apply_validity(array)
return array if @validity_buffer.nil?
validity_bitmap.each_with_index do |is_valid, i|
@@ -159,11 +171,20 @@ module ArrowFormat
def to_a
[nil] * @size
end
+
+ def each
+ return to_enum(__method__) unless block_given?
+
+ @size.times do
+ yield(nil)
+ end
+ end
end
class PrimitiveArray < Array
include BufferAlignable
+ attr_reader :values_buffer
def initialize(*args)
n_args = args.size
if self.class.respond_to?(:type)
@@ -192,8 +213,30 @@ module ArrowFormat
apply_validity(@values_buffer.values(@type.buffer_type, offset, @size))
end
+ def each(&block)
+ return to_enum(__method__) {@size} unless block_given?
+
+ each_value = Enumerator.new(@size) do |yielder|
+ offset = element_size * @offset
+ @values_buffer.each(@type.buffer_type, offset, @size) do |_, value|
+ yielder << value
+ end
+ end
+ if @validity_buffer.nil?
+ each_value.each(&block)
+ else
+ validity_bitmap.zip(each_value) do |is_valid, value|
+ if is_valid
+ yield(value)
+ else
+ yield(nil)
+ end
+ end
+ end
+ end
+
def each_buffer
- return to_enum(__method__) unless block_given?
+ return to_enum(__method__) {2} unless block_given?
yield(slice_bitmap_buffer(:validity, @validity_buffer))
yield(slice_fixed_element_size_buffer(:values,
@@ -201,6 +244,16 @@ module ArrowFormat
element_size))
end
+ def ==(other)
+ return false unless super(other)
+ if @offset == other.offset and @values_buffer == other.values_buffer
+ return true
+ end
+ lazy.zip(other).all? do |value, other_value|
+ value == other_value
+ end
+ end
+
private
def element_size
IO::Buffer.size_of(@type.buffer_type)
@@ -238,19 +291,38 @@ module ArrowFormat
def to_a
return [] if empty?
- @values_bitmap ||= Bitmap.new(@values_buffer, @offset, @size)
- values = @values_bitmap.to_a
+ values = values_bitmap.to_a
apply_validity(values)
end
+ def each(&block)
+ return to_enum(__method__) {@size} unless block_given?
+
+ if @validity_buffer.nil?
+ values_bitmap.each(&block)
+ else
+ validity_bitmap.zip(values_bitmap) do |is_valid, value|
+ if is_valid
+ yield(value)
+ else
+ yield(nil)
+ end
+ end
+ end
+ end
+
def each_buffer
- return to_enum(__method__) unless block_given?
+ return to_enum(__method__) {2} unless block_given?
yield(slice_bitmap_buffer(:validity, @validity_buffer))
yield(slice_bitmap_buffer(:values, @values_buffer))
end
private
+ def values_bitmap
+ @values_bitmap ||= Bitmap.new(@values_buffer, @offset, @size)
+ end
+
def clear_cache
super
@values_bitmap = nil
diff --git a/ruby/red-arrow-format/lib/arrow-format/bitmap.rb
b/ruby/red-arrow-format/lib/arrow-format/bitmap.rb
index 450bb25651..1a10b4f1c8 100644
--- a/ruby/red-arrow-format/lib/arrow-format/bitmap.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/bitmap.rb
@@ -19,23 +19,43 @@ module ArrowFormat
class Bitmap
include Enumerable
- def initialize(buffer, offset, n_values)
+ attr_reader :offset
+ attr_reader :size
+ alias_method :length, :size
+ def initialize(buffer, offset, size)
@buffer = buffer
@offset = offset
- @n_values = n_values
+ @size = size
+ end
+
+ def ==(other)
+ return false unless other.is_a?(self.class)
+ return false unless @size == other.size
+ lazy.zip(other).all? do |bit, other_bit|
+ bit == other_bit
+ end
end
def [](i)
+ return false if @buffer.nil?
+
i += @offset
(@buffer.get_value(:U8, i / 8) & (1 << (i % 8))) > 0
end
def each
- return to_enum(__method__) unless block_given?
+ return to_enum(__method__) {@size} unless block_given?
+
+ if @buffer.nil?
+ @size.times do
+ yield(false)
+ end
+ return
+ end
# TODO: Optimize
current = -1
- n_bytes = (@offset + @n_values) / 8
+ n_bytes = (@offset + @size) / 8
@buffer.each(:U8, 0, n_bytes) do |offset, value|
8.times do |i|
current += 1
@@ -43,7 +63,7 @@ module ArrowFormat
yield((value & (1 << (i % 8))) > 0)
end
end
- remained_bits = (@offset + @n_values) % 8
+ remained_bits = (@offset + @size) % 8
unless remained_bits.zero?
value = @buffer.get_value(:U8, n_bytes)
remained_bits.times do |i|
diff --git a/ruby/red-arrow-format/test/test-bitmap.rb
b/ruby/red-arrow-format/test/test-bitmap.rb
new file mode 100644
index 0000000000..e3aeafee8f
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-bitmap.rb
@@ -0,0 +1,34 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestBitmap < Test::Unit::TestCase
+ sub_test_case("#==") do
+ def test_no_slice
+ buffer1 = IO::Buffer.for("\xf0")
+ buffer2 = IO::Buffer.for("\xf0")
+ assert_equal(ArrowFormat::Bitmap.new(buffer1, 0, 8),
+ ArrowFormat::Bitmap.new(buffer2, 0, 8))
+ end
+
+ def test_sliced
+ buffer1 = IO::Buffer.for("\xf0")
+ buffer2 = IO::Buffer.for("\x00\xf0")
+ assert_equal(ArrowFormat::Bitmap.new(buffer1, 0, 8),
+ ArrowFormat::Bitmap.new(buffer2, 8, 8))
+ 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
new file mode 100644
index 0000000000..36a3c53daf
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-boolean-array.rb
@@ -0,0 +1,56 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestBooleanArray < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ assert_equal([true, false],
+ ArrowFormat::BooleanArray.new([true, false]).to_a)
+ end
+
+ def test_null_multiple_bytes
+ values = [true] * 8 + [nil, false]
+ assert_equal(values,
+ ArrowFormat::BooleanArray.new(values).to_a)
+ end
+
+ def test_mixed
+ assert_equal([true, nil, false],
+ ArrowFormat::BooleanArray.new([true, nil, false]).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ array1 = ArrowFormat::BooleanArray.new([true, nil, false])
+ array2 = ArrowFormat::BooleanArray.new([true, nil, false])
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ array1 = ArrowFormat::BooleanArray.new([true, nil, false])
+ array2 = ArrowFormat::BooleanArray.new([true, true, nil, false, true])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ array1 = ArrowFormat::BooleanArray.new([true, nil, false])
+ array2 = ArrowFormat::BooleanArray.new([true, false, nil, false, true])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..76de94a650
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-float32-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFloat32Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-Float::INFINITY, -0.0, +0.0, +Float::INFINITY]
+ assert_equal(values,
+ ArrowFormat::Float32Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ assert_equal(values,
+ ArrowFormat::Float32Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float32Array.new(values)
+ array2 = ArrowFormat::Float32Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float32Array.new(values)
+ array2 = ArrowFormat::Float32Array.new([0.0] + values + [0.0])
+ assert_equal(array1, array2.slice(1, 5))
+ end
+
+ def test_sliced_different_content
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float32Array.new(values)
+ array2 = ArrowFormat::Float32Array.new([0.0, 0.0] + values + [0.0])
+ assert_not_equal(array1, array2.slice(1, 5))
+ 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
new file mode 100644
index 0000000000..c3feebdc93
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-float64-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestFloat64Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-Float::INFINITY, -0.0, +0.0, +Float::INFINITY]
+ assert_equal(values,
+ ArrowFormat::Float64Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ assert_equal(values,
+ ArrowFormat::Float64Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float64Array.new(values)
+ array2 = ArrowFormat::Float64Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float64Array.new(values)
+ array2 = ArrowFormat::Float64Array.new([0.0] + values + [0.0])
+ assert_equal(array1, array2.slice(1, 5))
+ end
+
+ def test_sliced_different_content
+ values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
+ array1 = ArrowFormat::Float64Array.new(values)
+ array2 = ArrowFormat::Float64Array.new([0.0, 0.0] + values + [0.0])
+ assert_not_equal(array1, array2.slice(1, 5))
+ 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
new file mode 100644
index 0000000000..b25198482b
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-int16-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestInt16Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-(2 ** 15), (2 ** 15) - 1]
+ assert_equal(values,
+ ArrowFormat::Int16Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-(2 ** 15), nil, (2 ** 15) - 1]
+ assert_equal(values,
+ ArrowFormat::Int16Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-(2 ** 15), nil, (2 ** 15) - 1]
+ array1 = ArrowFormat::Int16Array.new(values)
+ array2 = ArrowFormat::Int16Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-(2 ** 15), nil, (2 ** 15) - 1]
+ array1 = ArrowFormat::Int16Array.new(values)
+ array2 = ArrowFormat::Int16Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [-(2 ** 15), nil, (2 ** 15) - 1]
+ array1 = ArrowFormat::Int16Array.new(values)
+ array2 = ArrowFormat::Int16Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..34f68e1294
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-int32-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestInt32Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-(2 ** 31), (2 ** 31) - 1]
+ assert_equal(values,
+ ArrowFormat::Int32Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-(2 ** 31), nil, (2 ** 31) - 1]
+ assert_equal(values,
+ ArrowFormat::Int32Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-(2 ** 31), nil, (2 ** 31) - 1]
+ array1 = ArrowFormat::Int32Array.new(values)
+ array2 = ArrowFormat::Int32Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-(2 ** 31), nil, (2 ** 31) - 1]
+ array1 = ArrowFormat::Int32Array.new(values)
+ array2 = ArrowFormat::Int32Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [-(2 ** 31), nil, (2 ** 31) - 1]
+ array1 = ArrowFormat::Int32Array.new(values)
+ array2 = ArrowFormat::Int32Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..2d92dd6014
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-int64-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestInt64Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-(2 ** 63), (2 ** 63) - 1]
+ assert_equal(values,
+ ArrowFormat::Int64Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-(2 ** 63), nil, (2 ** 63) - 1]
+ assert_equal(values,
+ ArrowFormat::Int64Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-(2 ** 63), nil, (2 ** 63) - 1]
+ array1 = ArrowFormat::Int64Array.new(values)
+ array2 = ArrowFormat::Int64Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-(2 ** 63), nil, (2 ** 63) - 1]
+ array1 = ArrowFormat::Int64Array.new(values)
+ array2 = ArrowFormat::Int64Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [-(2 ** 63), nil, (2 ** 63) - 1]
+ array1 = ArrowFormat::Int64Array.new(values)
+ array2 = ArrowFormat::Int64Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..a882a4e23d
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-int8-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestInt8Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [-(2 ** 7), (2 ** 7) - 1]
+ assert_equal(values,
+ ArrowFormat::Int8Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [-(2 ** 7), nil, (2 ** 7) - 1]
+ assert_equal(values,
+ ArrowFormat::Int8Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [-(2 ** 7), nil, (2 ** 7) - 1]
+ array1 = ArrowFormat::Int8Array.new(values)
+ array2 = ArrowFormat::Int8Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [-(2 ** 7), nil, (2 ** 7) - 1]
+ array1 = ArrowFormat::Int8Array.new(values)
+ array2 = ArrowFormat::Int8Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [-(2 ** 7), nil, (2 ** 7) - 1]
+ array1 = ArrowFormat::Int8Array.new(values)
+ array2 = ArrowFormat::Int8Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..961f2cd8d4
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-null-array.rb
@@ -0,0 +1,37 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestNullArray < Test::Unit::TestCase
+ def test_initialize
+ assert_equal([nil] * 9,
+ ArrowFormat::NullArray.new(9).to_a)
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ array1 = ArrowFormat::NullArray.new(3)
+ array2 = ArrowFormat::NullArray.new(3)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ array1 = ArrowFormat::NullArray.new(3)
+ array2 = ArrowFormat::NullArray.new(5)
+ assert_equal(array1, array2.slice(1, 3))
+ end
+ end
+end
diff --git a/ruby/red-arrow-format/test/test-primitive-array.rb
b/ruby/red-arrow-format/test/test-primitive-array.rb
deleted file mode 100644
index 7e09193ebf..0000000000
--- a/ruby/red-arrow-format/test/test-primitive-array.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-# 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
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-class TestPrimitiveArray < Test::Unit::TestCase
- def test_no_null
- assert_equal([true, false],
- ArrowFormat::BooleanArray.new([true, false]).to_a)
- end
-
- def test_null_multiple_bytes
- values = [true] * 8 + [nil, false]
- assert_equal(values,
- ArrowFormat::BooleanArray.new(values).to_a)
- end
-
- def test_boolean
- assert_equal([true, nil, false],
- ArrowFormat::BooleanArray.new([true, nil, false]).to_a)
- end
-
- def test_int8
- values = [-(2 ** 7), nil, (2 ** 7) - 1]
- assert_equal(values,
- ArrowFormat::Int8Array.new(values).to_a)
- end
-
- def test_uint8
- values = [0, nil, (2 ** 8) - 1]
- assert_equal(values,
- ArrowFormat::UInt8Array.new(values).to_a)
- end
-
- def test_int16
- values = [-(2 ** 15), nil, (2 ** 15) - 1]
- assert_equal(values,
- ArrowFormat::Int16Array.new(values).to_a)
- end
-
- def test_uint16
- values = [0, nil, (2 ** 16) - 1]
- assert_equal(values,
- ArrowFormat::UInt16Array.new(values).to_a)
- end
-
- def test_int32
- values = [-(2 ** 31), nil, (2 ** 31) - 1]
- assert_equal(values,
- ArrowFormat::Int32Array.new(values).to_a)
- end
-
- def test_uint32
- values = [0, nil, (2 ** 32) - 1]
- assert_equal(values,
- ArrowFormat::UInt32Array.new(values).to_a)
- end
-
- def test_int64
- values = [-(2 ** 63), nil, (2 ** 63) - 1]
- assert_equal(values,
- ArrowFormat::Int64Array.new(values).to_a)
- end
-
- def test_uint64
- values = [0, nil, (2 ** 64) - 1]
- assert_equal(values,
- ArrowFormat::UInt64Array.new(values).to_a)
- end
-
- def test_float32
- values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
- assert_equal(values,
- ArrowFormat::Float32Array.new(values).to_a)
- end
-
- def test_float64
- values = [-Float::INFINITY, -0.0, nil, +0.0, +Float::INFINITY]
- assert_equal(values,
- ArrowFormat::Float64Array.new(values).to_a)
- end
-end
diff --git a/ruby/red-arrow-format/test/test-uint16-array.rb
b/ruby/red-arrow-format/test/test-uint16-array.rb
new file mode 100644
index 0000000000..c406aa23cc
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-uint16-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestUInt16Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [0, (2 ** 16) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt16Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [0, nil, (2 ** 16) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt16Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [0, nil, (2 ** 16) - 1]
+ array1 = ArrowFormat::UInt16Array.new(values)
+ array2 = ArrowFormat::UInt16Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [0, nil, (2 ** 16) - 1]
+ array1 = ArrowFormat::UInt16Array.new(values)
+ array2 = ArrowFormat::UInt16Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [0, nil, (2 ** 16) - 1]
+ array1 = ArrowFormat::UInt16Array.new(values)
+ array2 = ArrowFormat::UInt16Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..685f127ab8
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-uint32-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestUInt32Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [0, (2 ** 32) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt32Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [0, nil, (2 ** 32) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt32Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [0, nil, (2 ** 32) - 1]
+ array1 = ArrowFormat::UInt32Array.new(values)
+ array2 = ArrowFormat::UInt32Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [0, nil, (2 ** 32) - 1]
+ array1 = ArrowFormat::UInt32Array.new(values)
+ array2 = ArrowFormat::UInt32Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [0, nil, (2 ** 32) - 1]
+ array1 = ArrowFormat::UInt32Array.new(values)
+ array2 = ArrowFormat::UInt32Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..ff8acf2f54
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-uint64-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestUInt64Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [0, (2 ** 64) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt64Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [0, nil, (2 ** 64) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt64Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [0, nil, (2 ** 64) - 1]
+ array1 = ArrowFormat::UInt64Array.new(values)
+ array2 = ArrowFormat::UInt64Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [0, nil, (2 ** 64) - 1]
+ array1 = ArrowFormat::UInt64Array.new(values)
+ array2 = ArrowFormat::UInt64Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [0, nil, (2 ** 64) - 1]
+ array1 = ArrowFormat::UInt64Array.new(values)
+ array2 = ArrowFormat::UInt64Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ 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
new file mode 100644
index 0000000000..87068f4850
--- /dev/null
+++ b/ruby/red-arrow-format/test/test-uint8-array.rb
@@ -0,0 +1,55 @@
+# 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
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestUInt8Array < Test::Unit::TestCase
+ sub_test_case("#initialize") do
+ def test_no_null
+ values = [0, (2 ** 8) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt8Array.new(values).to_a)
+ end
+
+ def test_mixed
+ values = [0, nil, (2 ** 8) - 1]
+ assert_equal(values,
+ ArrowFormat::UInt8Array.new(values).to_a)
+ end
+ end
+
+ sub_test_case("#==") do
+ def test_no_slice
+ values = [0, nil, (2 ** 8) - 1]
+ array1 = ArrowFormat::UInt8Array.new(values)
+ array2 = ArrowFormat::UInt8Array.new(values)
+ assert_equal(array1, array2)
+ end
+
+ def test_sliced
+ values = [0, nil, (2 ** 8) - 1]
+ array1 = ArrowFormat::UInt8Array.new(values)
+ array2 = ArrowFormat::UInt8Array.new([0] + values + [0])
+ assert_equal(array1, array2.slice(1, 3))
+ end
+
+ def test_sliced_different_content
+ values = [0, nil, (2 ** 8) - 1]
+ array1 = ArrowFormat::UInt8Array.new(values)
+ array2 = ArrowFormat::UInt8Array.new([0, 0] + values + [0])
+ assert_not_equal(array1, array2.slice(1, 3))
+ end
+ end
+end