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
6 changes: 6 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ def name
def build_array(size, validity_buffer, values_buffer)
DurationArray.new(self, size, validity_buffer, values_buffer)
end

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

class VariableSizeBinaryType < Type
Expand Down
62 changes: 62 additions & 0 deletions ruby/red-arrow-format/test/test-writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def convert_type(red_arrow_type)
ArrowFormat::DayTimeIntervalType.singleton
when Arrow::MonthDayNanoIntervalDataType
ArrowFormat::MonthDayNanoIntervalType.singleton
when Arrow::DurationDataType
ArrowFormat::DurationType.new(convert_time_unit(red_arrow_type.unit))
when Arrow::BinaryDataType
ArrowFormat::BinaryType.singleton
when Arrow::LargeBinaryDataType
Expand Down Expand Up @@ -610,6 +612,66 @@ def test_write
end
end

sub_test_case("Duration(:second)") do
def build_array
Arrow::DurationArray.new(:second, [0, nil, 100])
end

def test_write
assert_equal([0, nil, 100],
@values)
end

def test_type
assert_equal(Arrow::TimeUnit::SECOND, @type.unit)
end
end

sub_test_case("Duration(:millisecond)") do
def build_array
Arrow::DurationArray.new(:milli, [0, nil, 100])
end

def test_write
assert_equal([0, nil, 100],
@values)
end

def test_type
assert_equal(Arrow::TimeUnit::MILLI, @type.unit)
end
end

sub_test_case("Duration(:microsecond)") do
def build_array
Arrow::DurationArray.new(:micro, [0, nil, 100])
end

def test_write
assert_equal([0, nil, 100],
@values)
end

def test_type
assert_equal(Arrow::TimeUnit::MICRO, @type.unit)
end
end

sub_test_case("Duration(:nanosecond)") do
def build_array
Arrow::DurationArray.new(:nano, [0, nil, 100])
end

def test_write
assert_equal([0, nil, 100],
@values)
end

def test_type
assert_equal(Arrow::TimeUnit::NANO, @type.unit)
end
end

sub_test_case("Binary") do
def build_array
Arrow::BinaryArray.new(["Hello".b, nil, "World".b])
Expand Down
16 changes: 11 additions & 5 deletions ruby/red-arrow/ext/arrow/converters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ namespace red_arrow {
return rb_time_num_new(sec, Qnil);
}

// TODO
// inline VALUE convert(const arrow::IntervalArray& array,
// const int64_t i) {
// };

inline VALUE convert(const arrow::MonthIntervalArray& array,
const int64_t i) {
return INT2NUM(array.Value(i));
Expand Down Expand Up @@ -280,6 +275,11 @@ namespace red_arrow {
return value;
}

inline VALUE convert(const arrow::DurationArray& array,
const int64_t i) {
return LL2NUM(array.Value(i));
}

VALUE convert(const arrow::ListArray& array,
const int64_t i);

Expand Down Expand Up @@ -382,6 +382,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down Expand Up @@ -481,6 +482,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down Expand Up @@ -588,6 +590,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down Expand Up @@ -691,6 +694,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down Expand Up @@ -795,6 +799,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down Expand Up @@ -907,6 +912,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down
2 changes: 2 additions & 0 deletions ruby/red-arrow/ext/arrow/raw-records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(Struct)
VISIT(Map)
Expand Down Expand Up @@ -238,6 +239,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(Struct)
VISIT(Map)
Expand Down
1 change: 1 addition & 0 deletions ruby/red-arrow/ext/arrow/values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace red_arrow {
VISIT(MonthInterval)
VISIT(DayTimeInterval)
VISIT(MonthDayNanoInterval)
VISIT(Duration)
VISIT(List)
VISIT(LargeList)
VISIT(Struct)
Expand Down
40 changes: 40 additions & 0 deletions ruby/red-arrow/test/raw-records/test-basic-arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,46 @@ def test_month_day_nano_interval
target = build({column: :month_day_nano_interval}, records)
assert_equal(records, actual_records(target))
end

def test_duration_second
records = [
[0],
[nil],
[100],
]
target = build({column: {type: :duration, unit: :second}}, records)
assert_equal(records, actual_records(target))
end

def test_duration_milli
records = [
[0],
[nil],
[100],
]
target = build({column: {type: :duration, unit: :milli}}, records)
assert_equal(records, actual_records(target))
end

def test_duration_micro
records = [
[0],
[nil],
[100],
]
target = build({column: {type: :duration, unit: :micro}}, records)
assert_equal(records, actual_records(target))
end

def test_duration_nano
records = [
[0],
[nil],
[100],
]
target = build({column: {type: :duration, unit: :nano}}, records)
assert_equal(records, actual_records(target))
end
end

class EachRawRecordRecordBatchBasicArraysTest < Test::Unit::TestCase
Expand Down
40 changes: 40 additions & 0 deletions ruby/red-arrow/test/values/test-basic-arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,46 @@ def test_month_day_nano_interval
target = build(Arrow::MonthDayNanoIntervalArray.new(values))
assert_equal(values, target.values)
end

def test_duration_second
values = [
0,
nil,
100,
]
target = build(Arrow::DurationArray.new(:second, values))
assert_equal(values, target.values)
end

def test_duration_milli
values = [
0,
nil,
100,
]
target = build(Arrow::DurationArray.new(:milli, values))
assert_equal(values, target.values)
end

def test_duration_micro
values = [
0,
nil,
100,
]
target = build(Arrow::DurationArray.new(:micro, values))
assert_equal(values, target.values)
end

def test_duration_nano
values = [
0,
nil,
100,
]
target = build(Arrow::DurationArray.new(:nano, values))
assert_equal(values, target.values)
end
end

class ValuesArrayBasicArraysTest < Test::Unit::TestCase
Expand Down
Loading