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 2a4ed78482 GH-48440: [Ruby] Add support for reading time32 array 
(#48441)
2a4ed78482 is described below

commit 2a4ed78482085a184d00d77044f0a74f0a04627d
Author: Sutou Kouhei <[email protected]>
AuthorDate: Sat Dec 13 16:43:42 2025 +0900

    GH-48440: [Ruby] Add support for reading time32 array (#48441)
    
    ### Rationale for this change
    
    It's a 32 bits variant for time array.
    
    ### What changes are included in this PR?
    
    * Add `ArrowFormat::Time32Type`
    * Add `ArrowFormat::Time32Array`
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * GitHub Issue: #48440
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 ruby/red-arrow-format/lib/arrow-format/array.rb    | 14 ++++++++-
 .../lib/arrow-format/file-reader.rb                | 14 ++++++++-
 ruby/red-arrow-format/lib/arrow-format/type.rb     | 19 +++++++++++-
 ruby/red-arrow-format/test/test-file-reader.rb     | 35 ++++++++++++++++++++++
 4 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/ruby/red-arrow-format/lib/arrow-format/array.rb 
b/ruby/red-arrow-format/lib/arrow-format/array.rb
index 97cae705eb..403366ed20 100644
--- a/ruby/red-arrow-format/lib/arrow-format/array.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/array.rb
@@ -122,13 +122,16 @@ module ArrowFormat
     end
   end
 
-  class DateArray < Array
+  class TemporalArray < Array
     def initialize(type, size, validity_buffer, values_buffer)
       super(type, size, validity_buffer)
       @values_buffer = values_buffer
     end
   end
 
+  class DateArray < TemporalArray
+  end
+
   class Date32Array < DateArray
     def to_a
       apply_validity(@values_buffer.values(:s32, 0, @size))
@@ -141,6 +144,15 @@ module ArrowFormat
     end
   end
 
+  class TimeArray < TemporalArray
+  end
+
+  class Time32Array < TimeArray
+    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)
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 e2a7955524..24249a0bab 100644
--- a/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/file-reader.rb
@@ -38,6 +38,8 @@ require_relative "org/apache/arrow/flatbuf/null"
 require_relative "org/apache/arrow/flatbuf/precision"
 require_relative "org/apache/arrow/flatbuf/schema"
 require_relative "org/apache/arrow/flatbuf/struct_"
+require_relative "org/apache/arrow/flatbuf/time"
+require_relative "org/apache/arrow/flatbuf/time_unit"
 require_relative "org/apache/arrow/flatbuf/union"
 require_relative "org/apache/arrow/flatbuf/union_mode"
 require_relative "org/apache/arrow/flatbuf/utf8"
@@ -177,6 +179,16 @@ module ArrowFormat
         when Org::Apache::Arrow::Flatbuf::DateUnit::MILLISECOND
           type = Date64Type.singleton
         end
+      when Org::Apache::Arrow::Flatbuf::Time
+        case fb_type.bit_width
+        when 32
+          case fb_type.unit
+          when Org::Apache::Arrow::Flatbuf::TimeUnit::SECOND
+            type = Time32Type.new(:second)
+          when Org::Apache::Arrow::Flatbuf::TimeUnit::MILLISECOND
+            type = Time32Type.new(:millisecond)
+          end
+        end
       when Org::Apache::Arrow::Flatbuf::List
         type = ListType.new(read_field(fb_field.children[0]))
       when Org::Apache::Arrow::Flatbuf::LargeList
@@ -228,7 +240,7 @@ module ArrowFormat
       case field.type
       when BooleanType,
            NumberType,
-           DateType
+           TemporalType
         values_buffer = buffers.shift
         values = body.slice(values_buffer.offset, values_buffer.length)
         field.type.build_array(length, validity, values)
diff --git a/ruby/red-arrow-format/lib/arrow-format/type.rb 
b/ruby/red-arrow-format/lib/arrow-format/type.rb
index dc1b9f64bf..16f8ab4553 100644
--- a/ruby/red-arrow-format/lib/arrow-format/type.rb
+++ b/ruby/red-arrow-format/lib/arrow-format/type.rb
@@ -171,7 +171,10 @@ module ArrowFormat
     end
   end
 
-  class DateType < Type
+  class TemporalType < Type
+  end
+
+  class DateType < TemporalType
   end
 
   class Date32Type < DateType
@@ -206,6 +209,20 @@ module ArrowFormat
     end
   end
 
+  class TimeType < TemporalType
+  end
+
+  class Time32Type < TimeType
+    def initialize(unit)
+      super("Time32")
+      @unit = unit
+    end
+
+    def build_array(size, validity_buffer, values_buffer)
+      Time32Array.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 eb44fe35c1..c74e431f7a 100644
--- a/ruby/red-arrow-format/test/test-file-reader.rb
+++ b/ruby/red-arrow-format/test/test-file-reader.rb
@@ -174,6 +174,41 @@ class TestFileReader < Test::Unit::TestCase
     end
   end
 
+  sub_test_case("Time32(:second)") do
+    def setup(&block)
+      @time_00_00_10 = 10
+      @time_00_01_10 = 60 + 10
+      super(&block)
+    end
+
+    def build_array
+      Arrow::Time32Array.new(:second, [@time_00_00_10, nil, @time_00_01_10])
+    end
+
+    def test_read
+      assert_equal([{"value" => [@time_00_00_10, nil, @time_00_01_10]}],
+                   read)
+    end
+  end
+
+  sub_test_case("Time32(:millisecond)") do
+    def setup(&block)
+      @time_00_00_10_000 = 10 * 1000
+      @time_00_01_10_000 = (60 + 10) * 1000
+      super(&block)
+    end
+
+    def build_array
+      Arrow::Time32Array.new(:milli,
+                             [@time_00_00_10_000, nil, @time_00_01_10_000])
+    end
+
+    def test_read
+      assert_equal([{"value" => [@time_00_00_10_000, nil, 
@time_00_01_10_000]}],
+                   read)
+    end
+  end
+
   sub_test_case("Binary") do
     def build_array
       Arrow::BinaryArray.new(["Hello".b, nil, "World".b])

Reply via email to