Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ruby/red-arrow-format/lib/arrow-format/error.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-binary-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-boolean-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions ruby/red-arrow-format/test/test-date32-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions ruby/red-arrow-format/test/test-date64-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
19 changes: 19 additions & 0 deletions ruby/red-arrow-format/test/test-day-time-interval-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-duration-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-float32-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-float64-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-int16-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-int32-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions ruby/red-arrow-format/test/test-int64-array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Loading