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 323c251661 GH-48535: [Ruby] Add support for reading time64 array
(#48536)
323c251661 is described below
commit 323c2516619336fce73d2c83c6fb034059e78305
Author: Sutou Kouhei <[email protected]>
AuthorDate: Tue Dec 16 09:30:15 2025 +0900
GH-48535: [Ruby] Add support for reading time64 array (#48536)
### Rationale for this change
It's a 64 bits variant of time array.
### What changes are included in this PR?
* Add `ArrowFormat::Time64Type`
* Add `ArrowFormat::Time64Array`
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Yes.
* GitHub Issue: #48535
Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
ruby/red-arrow-format/lib/arrow-format/array.rb | 6 +++
.../lib/arrow-format/file-reader.rb | 7 +++
ruby/red-arrow-format/lib/arrow-format/type.rb | 11 ++++
ruby/red-arrow-format/test/test-file-reader.rb | 60 ++++++++++++++++++++++
4 files changed, 84 insertions(+)
diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb
b/ruby/red-arrow-format/lib/arrow-format/array.rb
index 5a90f4ca45..4788df341a 100644
--- a/ruby/red-arrow-format/lib/arrow-format/array.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/array.rb
@@ -177,6 +177,12 @@ module ArrowFormat
end
end
+ class Time64Array < TimeArray
+ def to_a
+ apply_validity(@values_buffer.values(:s64, 0, @size))
+ end
+ end
+
class VariableSizeBinaryLayoutArray < Array
def initialize(type, size, validity_buffer, offsets_buffer, values_buffer)
super(type, size, validity_buffer)
diff --git a/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
b/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
index 0dcdbfac62..fb1c9fb8a8 100644
--- a/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
@@ -200,6 +200,13 @@ module ArrowFormat
when Org::Apache::Arrow::Flatbuf::TimeUnit::MILLISECOND
type = Time32Type.new(:millisecond)
end
+ when 64
+ case fb_type.unit
+ when Org::Apache::Arrow::Flatbuf::TimeUnit::MICROSECOND
+ type = Time64Type.new(:microsecond)
+ when Org::Apache::Arrow::Flatbuf::TimeUnit::NANOSECOND
+ type = Time64Type.new(:nanosecond)
+ end
end
when Org::Apache::Arrow::Flatbuf::List
type = ListType.new(read_field(fb_field.children[0]))
diff --git a/ruby/red-arrow-format/lib/arrow-format/type.rb
b/ruby/red-arrow-format/lib/arrow-format/type.rb
index a8d58d9fdd..87d85f3419 100644
--- a/ruby/red-arrow-format/lib/arrow-format/type.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/type.rb
@@ -287,6 +287,17 @@ module ArrowFormat
end
end
+ class Time64Type < TimeType
+ def initialize(unit)
+ super("Time64")
+ @unit = unit
+ end
+
+ def build_array(size, validity_buffer, values_buffer)
+ Time64Array.new(self, size, validity_buffer, values_buffer)
+ end
+ end
+
class VariableSizeBinaryType < Type
end
diff --git a/ruby/red-arrow-format/test/test-file-reader.rb
b/ruby/red-arrow-format/test/test-file-reader.rb
index 24f59c535b..fb715ea2c4 100644
--- a/ruby/red-arrow-format/test/test-file-reader.rb
+++ b/ruby/red-arrow-format/test/test-file-reader.rb
@@ -265,6 +265,66 @@ class TestFileReader < Test::Unit::TestCase
end
end
+ sub_test_case("Time64(:microsecond)") do
+ def setup(&block)
+ @time_00_00_10_000_000 = 10 * 1_000_000
+ @time_00_01_10_000_000 = (60 + 10) * 1_000_000
+ super(&block)
+ end
+
+ def build_array
+ Arrow::Time64Array.new(:micro,
+ [
+ @time_00_00_10_000_000,
+ nil,
+ @time_00_01_10_000_000,
+ ])
+ end
+
+ def test_read
+ assert_equal([
+ {
+ "value" => [
+ @time_00_00_10_000_000,
+ nil,
+ @time_00_01_10_000_000,
+ ],
+ },
+ ],
+ read)
+ end
+ end
+
+ sub_test_case("Time64(:nanosecond)") do
+ def setup(&block)
+ @time_00_00_10_000_000_000 = 10 * 1_000_000_000
+ @time_00_01_10_000_000_000 = (60 + 10) * 1_000_000_000
+ super(&block)
+ end
+
+ def build_array
+ Arrow::Time64Array.new(:nano,
+ [
+ @time_00_00_10_000_000_000,
+ nil,
+ @time_00_01_10_000_000_000,
+ ])
+ end
+
+ def test_read
+ assert_equal([
+ {
+ "value" => [
+ @time_00_00_10_000_000_000,
+ nil,
+ @time_00_01_10_000_000_000,
+ ],
+ },
+ ],
+ read)
+ end
+ end
+
sub_test_case("Binary") do
def build_array
Arrow::BinaryArray.new(["Hello".b, nil, "World".b])