Skip to content

Commit 6c9f542

Browse files
authored
GH-48423: [Ruby] Add support for reading date64 array (#48424)
### Rationale for this change It's a millisecond variant of date array. ### What changes are included in this PR? * Add `ArrowFormat::Date64Type` * Add `ArrowFormat::Date64Array` ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #48423 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent dfb5bea commit 6c9f542

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

ruby/red-arrow-format/lib/arrow-format/array.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ def to_a
123123
end
124124
end
125125

126+
class Date64Array < DateArray
127+
def to_a
128+
apply_validity(@values_buffer.values(:s64, 0, @size))
129+
end
130+
end
131+
126132
class VariableSizeBinaryLayoutArray < Array
127133
def initialize(type, size, validity_buffer, offsets_buffer, values_buffer)
128134
super(type, size, validity_buffer)

ruby/red-arrow-format/lib/arrow-format/file-reader.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def read_field(fb_field)
166166
case fb_type.unit
167167
when Org::Apache::Arrow::Flatbuf::DateUnit::DAY
168168
type = Date32Type.singleton
169+
when Org::Apache::Arrow::Flatbuf::DateUnit::MILLISECOND
170+
type = Date64Type.singleton
169171
end
170172
when Org::Apache::Arrow::Flatbuf::List
171173
type = ListType.new(read_field(fb_field.children[0]))

ruby/red-arrow-format/lib/arrow-format/type.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ def build_array(size, validity_buffer, values_buffer)
158158
end
159159
end
160160

161+
class Date64Type < DateType
162+
class << self
163+
def singleton
164+
@singleton ||= new
165+
end
166+
end
167+
168+
def initialize
169+
super("Date64")
170+
end
171+
172+
def build_array(size, validity_buffer, values_buffer)
173+
Date64Array.new(self, size, validity_buffer, values_buffer)
174+
end
175+
end
176+
161177
class VariableSizeBinaryType < Type
162178
end
163179

ruby/red-arrow-format/test/test-file-reader.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,35 @@ def test_read
123123
end
124124
end
125125

126+
sub_test_case("Date64") do
127+
def setup(&block)
128+
@date_2017_08_28_00_00_00 = 1503878400000
129+
@date_2025_12_09_00_00_00 = 1765324800000
130+
super(&block)
131+
end
132+
133+
def build_array
134+
Arrow::Date64Array.new([
135+
@date_2017_08_28_00_00_00,
136+
nil,
137+
@date_2025_12_09_00_00_00,
138+
])
139+
end
140+
141+
def test_read
142+
assert_equal([
143+
{
144+
"value" => [
145+
@date_2017_08_28_00_00_00,
146+
nil,
147+
@date_2025_12_09_00_00_00,
148+
],
149+
},
150+
],
151+
read)
152+
end
153+
end
154+
126155
sub_test_case("Binary") do
127156
def build_array
128157
Arrow::BinaryArray.new(["Hello".b, nil, "World".b])

0 commit comments

Comments
 (0)