Skip to content

Commit 4127ca2

Browse files
hiroyuki-satokou
andauthored
GH-48479: [Ruby] Add support for reading Int64 and UInt64 arrays (#48480)
### Rationale for this change They are int64 and uint64 variants of an int array. ### What changes are included in this PR? * Add `ArrowFromat::Int64Type` * Add `ArrowFromat::UInt64Type` * Add `ArrowFromat::Int64Array` * Add `ArrowFromat::UInt64Array` ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #48479 Lead-authored-by: Hiroyuki Sato <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 8afd140 commit 4127ca2

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ def to_a
115115
end
116116
end
117117

118+
class Int64Array < IntArray
119+
def to_a
120+
apply_validity(@values_buffer.values(:s64, 0, @size))
121+
end
122+
end
123+
124+
class UInt64Array < IntArray
125+
def to_a
126+
apply_validity(@values_buffer.values(:u64, 0, @size))
127+
end
128+
end
129+
118130
class FloatingPointArray < Array
119131
def initialize(type, size, validity_buffer, values_buffer)
120132
super(type, size, validity_buffer)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ def read_field(fb_field)
170170
else
171171
type = UInt32Type.singleton
172172
end
173+
when 64
174+
if fb_type.signed?
175+
type = Int64Type.singleton
176+
else
177+
type = UInt64Type.singleton
178+
end
173179
end
174180
when Org::Apache::Arrow::Flatbuf::FloatingPoint
175181
case fb_type.precision

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ def build_array(size, validity_buffer, values_buffer)
163163
end
164164
end
165165

166+
class Int64Type < IntType
167+
class << self
168+
def singleton
169+
@singleton ||= new
170+
end
171+
end
172+
173+
def initialize
174+
super("Int64", 64, true)
175+
end
176+
177+
def build_array(size, validity_buffer, values_buffer)
178+
Int64Array.new(self, size, validity_buffer, values_buffer)
179+
end
180+
end
181+
182+
class UInt64Type < IntType
183+
class << self
184+
def singleton
185+
@singleton ||= new
186+
end
187+
end
188+
189+
def initialize
190+
super("UInt64", 64, false)
191+
end
192+
193+
def build_array(size, validity_buffer, values_buffer)
194+
UInt64Array.new(self, size, validity_buffer, values_buffer)
195+
end
196+
end
197+
166198
class FloatingPointType < NumberType
167199
attr_reader :precision
168200
def initialize(name, precision)

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,40 @@ def test_read
128128
end
129129
end
130130

131+
sub_test_case("Int64") do
132+
def build_array
133+
Arrow::Int64Array.new([
134+
-9223372036854775808,
135+
nil,
136+
9223372036854775807
137+
])
138+
end
139+
140+
def test_read
141+
assert_equal([
142+
{
143+
"value" => [
144+
-9223372036854775808,
145+
nil,
146+
9223372036854775807
147+
]
148+
}
149+
],
150+
read)
151+
end
152+
end
153+
154+
sub_test_case("UInt64") do
155+
def build_array
156+
Arrow::UInt64Array.new([0, nil, 18446744073709551615])
157+
end
158+
159+
def test_read
160+
assert_equal([{"value" => [0, nil, 18446744073709551615]}],
161+
read)
162+
end
163+
end
164+
131165
sub_test_case("Float32") do
132166
def build_array
133167
Arrow::FloatArray.new([-0.5, nil, 0.5])

0 commit comments

Comments
 (0)