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
13 changes: 13 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def to_a
end
end

class DateArray < Array
def initialize(type, size, validity_buffer, values_buffer)
super(type, size, validity_buffer)
@values_buffer = values_buffer
end
end

class Date32Array < DateArray
def to_a
apply_validity(@values_buffer.values(:s32, 0, @size))
end
end

class VariableSizeBinaryLayoutArray < Array
def initialize(type, size, validity_buffer, offsets_buffer, values_buffer)
super(type, size, validity_buffer)
Expand Down
10 changes: 9 additions & 1 deletion 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,8 @@

require_relative "org/apache/arrow/flatbuf/binary"
require_relative "org/apache/arrow/flatbuf/bool"
require_relative "org/apache/arrow/flatbuf/date"
require_relative "org/apache/arrow/flatbuf/date_unit"
require_relative "org/apache/arrow/flatbuf/floating_point"
require_relative "org/apache/arrow/flatbuf/footer"
require_relative "org/apache/arrow/flatbuf/int"
Expand Down Expand Up @@ -159,6 +161,11 @@ def read_field(fb_field)
when Org::Apache::Arrow::Flatbuf::Precision::DOUBLE
type = Float64Type.singleton
end
when Org::Apache::Arrow::Flatbuf::Date
case fb_type.unit
when Org::Apache::Arrow::Flatbuf::DateUnit::DAY
type = Date32Type.singleton
end
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case: DateUnit::MILLISECOND will implement aonther PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It's for date64 array.

when Org::Apache::Arrow::Flatbuf::List
type = ListType.new(read_field(fb_field.children[0]))
when Org::Apache::Arrow::Flatbuf::Struct
Expand Down Expand Up @@ -198,7 +205,8 @@ def read_column(field, nodes, buffers, body)

case field.type
when BooleanType,
NumberType
NumberType,
DateType
values_buffer = buffers.shift
values = body.slice(values_buffer.offset, values_buffer.length)
field.type.build_array(length, validity, values)
Expand Down
19 changes: 19 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ def build_array(size, validity_buffer, values_buffer)
end
end

class DateType < Type
end

class Date32Type < DateType
class << self
def singleton
@singleton ||= new
end
end

def initialize
super("Date32")
end

def build_array(size, validity_buffer, values_buffer)
Date32Array.new(self, size, validity_buffer, values_buffer)
end
end

class VariableSizeBinaryType < Type
end

Expand Down
28 changes: 28 additions & 0 deletions ruby/red-arrow-format/test/test-file-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ def test_read
end
end

sub_test_case("Float64") do
def build_array
Arrow::DoubleArray.new([-0.5, nil, 0.5])
end

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

sub_test_case("Date32") do
def setup(&block)
@date_2017_08_28 = 17406
@date_2025_12_09 = 20431
super(&block)
end

def build_array
Arrow::Date32Array.new([@date_2017_08_28, nil, @date_2025_12_09])
end

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

sub_test_case("Binary") do
def build_array
Arrow::BinaryArray.new(["Hello".b, nil, "World".b])
Expand Down
Loading