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
21 changes: 20 additions & 1 deletion ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,21 @@ def build_array(size, validity_buffer, values_buffer)
end
end

class TemporalType < Type
class TemporalType < PrimitiveType
end

class DateType < TemporalType
attr_reader :unit
def initialize(unit)
super()
@unit = unit
end

def to_flatbuffers
fb_type = FB::Date::Data.new
fb_type.unit = FB::DateUnit.try_convert(@unit.to_s.upcase)
fb_type
end
end

class Date32Type < DateType
Expand All @@ -343,6 +354,10 @@ def singleton
end
end

def initialize
super(:day)
end

def name
"Date32"
end
Expand All @@ -359,6 +374,10 @@ def singleton
end
end

def initialize
super(:millisecond)
end

def name
"Date64"
end
Expand Down
6 changes: 3 additions & 3 deletions ruby/red-arrow-format/test/test-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ def test_read
sub_test_case("Date64") do
def setup(&block)
@date_2017_08_28_00_00_00 = 1503878400000
@date_2025_12_09_00_00_00 = 1765324800000
@date_2025_12_10_00_00_00 = 1765324800000
super(&block)
end

def build_array
Arrow::Date64Array.new([
@date_2017_08_28_00_00_00,
nil,
@date_2025_12_09_00_00_00,
@date_2025_12_10_00_00_00,
])
end

Expand All @@ -209,7 +209,7 @@ def test_read
"value" => [
@date_2017_08_28_00_00_00,
nil,
@date_2025_12_09_00_00_00,
@date_2025_12_10_00_00_00,
],
},
],
Expand Down
46 changes: 46 additions & 0 deletions ruby/red-arrow-format/test/test-writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def convert_type(red_arrow_type)
ArrowFormat::Float32Type.singleton
when Arrow::DoubleDataType
ArrowFormat::Float64Type.singleton
when Arrow::Date32DataType
ArrowFormat::Date32Type.singleton
when Arrow::Date64DataType
ArrowFormat::Date64Type.singleton
when Arrow::BinaryDataType
ArrowFormat::BinaryType.singleton
when Arrow::LargeBinaryDataType
Expand Down Expand Up @@ -220,6 +224,48 @@ def test_write
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_write
assert_equal([Date.new(2017, 8, 28), nil, Date.new(2025, 12, 9)],
@values)
end
end

sub_test_case("Date64") do
def setup(&block)
@date_2017_08_28_00_00_00 = 1503878400000
@date_2025_12_10_00_00_00 = 1765324800000
super(&block)
end

def build_array
Arrow::Date64Array.new([
@date_2017_08_28_00_00_00,
nil,
@date_2025_12_10_00_00_00,
])
end

def test_write
assert_equal([
DateTime.new(2017, 8, 28, 0, 0, 0),
nil,
DateTime.new(2025, 12, 10, 0, 0, 0),
],
@values)
end
end

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