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
10 changes: 10 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def apply_validity(array)
end
end

class NullArray < Array
def initialize(type, size)
super(type, size, nil)
end

def to_a
[nil] * @size
end
end

class IntArray < Array
def initialize(type, size, validity_buffer, values_buffer)
super(type, size, validity_buffer)
Expand Down
8 changes: 8 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/file-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

require_relative "org/apache/arrow/flatbuf/footer"
require_relative "org/apache/arrow/flatbuf/message"
require_relative "org/apache/arrow/flatbuf/binary"
require_relative "org/apache/arrow/flatbuf/int"
require_relative "org/apache/arrow/flatbuf/null"
require_relative "org/apache/arrow/flatbuf/utf8"
require_relative "org/apache/arrow/flatbuf/schema"

module ArrowFormat
Expand Down Expand Up @@ -128,6 +132,8 @@ def read_schema(fb_schema)
fields = fb_schema.fields.collect do |fb_field|
fb_type = fb_field.type
case fb_type
when Org::Apache::Arrow::Flatbuf::Null
type = NullType.singleton
when Org::Apache::Arrow::Flatbuf::Int
case fb_type.bit_width
when 8
Expand All @@ -146,6 +152,8 @@ def read_schema(fb_schema)
end

def read_column(field, n_rows, buffers, body)
return field.type.build_array(n_rows) if field.type.is_a?(NullType)

validity_buffer = buffers.shift
if validity_buffer.length.zero?
validity = nil
Expand Down
16 changes: 16 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ def initialize(name)
end
end

class NullType < Type
class << self
def singleton
@singleton ||= new
end
end

def initialize
super("Null")
end

def build_array(size)
NullArray.new(self, size)
end
end

class IntType < Type
attr_reader :bit_width
attr_reader :signed
Expand Down
11 changes: 11 additions & 0 deletions ruby/red-arrow-format/test/test-file-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def read
end
end

sub_test_case("Null") do
def build_array
Arrow::NullArray.new(3)
end

def test_read
assert_equal([{"value" => [nil, nil, nil]}],
read)
end
end

sub_test_case("Int8") do
def build_array
Arrow::Int8Array.new([-128, nil, 127])
Expand Down