This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 685873e2c3 GH-48990: [Ruby] Add support for writing date arrays
(#48991)
685873e2c3 is described below
commit 685873e2c3b1886ccf34144194ab9d0d458e9f8d
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Jan 27 20:02:16 2026 +0900
GH-48990: [Ruby] Add support for writing date arrays (#48991)
### Rationale for this change
There are date32 and date64 variants for date arrays.
### What changes are included in this PR?
* Add `ArrowFormat::DateType#to_flatbuffers`
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
* GitHub Issue: #48990
Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow-format/lib/arrow-format/type.rb | 21 +++++++++++-
ruby/red-arrow-format/test/test-reader.rb | 6 ++--
ruby/red-arrow-format/test/test-writer.rb | 46 ++++++++++++++++++++++++++
3 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/ruby/red-arrow-format/lib/arrow-format/type.rb
b/ruby/red-arrow-format/lib/arrow-format/type.rb
index c648e5b631..b3b5bf7aba 100644
--- a/ruby/red-arrow-format/lib/arrow-format/type.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/type.rb
@@ -330,10 +330,21 @@ module ArrowFormat
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
@@ -343,6 +354,10 @@ module ArrowFormat
end
end
+ def initialize
+ super(:day)
+ end
+
def name
"Date32"
end
@@ -359,6 +374,10 @@ module ArrowFormat
end
end
+ def initialize
+ super(:millisecond)
+ end
+
def name
"Date64"
end
diff --git a/ruby/red-arrow-format/test/test-reader.rb
b/ruby/red-arrow-format/test/test-reader.rb
index e004896737..d59ae9cb16 100644
--- a/ruby/red-arrow-format/test/test-reader.rb
+++ b/ruby/red-arrow-format/test/test-reader.rb
@@ -191,7 +191,7 @@ module ReaderTests
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
@@ -199,7 +199,7 @@ module ReaderTests
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
@@ -209,7 +209,7 @@ module ReaderTests
"value" => [
@date_2017_08_28_00_00_00,
nil,
- @date_2025_12_09_00_00_00,
+ @date_2025_12_10_00_00_00,
],
},
],
diff --git a/ruby/red-arrow-format/test/test-writer.rb
b/ruby/red-arrow-format/test/test-writer.rb
index 24a49b3777..31c2bef299 100644
--- a/ruby/red-arrow-format/test/test-writer.rb
+++ b/ruby/red-arrow-format/test/test-writer.rb
@@ -42,6 +42,10 @@ module WriterTests
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
@@ -220,6 +224,48 @@ module WriterTests
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])