Skip to content

Commit 59e47ca

Browse files
authored
GH-48380: [Ruby] Add support for reading float64 array (#48381)
### Rationale for this change It's the second floating point array. ### What changes are included in this PR? * Add `ArrowFromat::Float64Type` * Add `ArrowFormat::Float64Array` ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #48380 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent f66887e commit 59e47ca

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,25 @@ def to_a
9191
end
9292
end
9393

94-
class FloatArray < Array
94+
class FloatingPointArray < Array
9595
def initialize(type, size, validity_buffer, values_buffer)
9696
super(type, size, validity_buffer)
9797
@values_buffer = values_buffer
9898
end
9999
end
100100

101-
class Float32Array < FloatArray
101+
class Float32Array < FloatingPointArray
102102
def to_a
103103
apply_validity(@values_buffer.values(:f32, 0, @size))
104104
end
105105
end
106106

107+
class Float64Array < FloatingPointArray
108+
def to_a
109+
apply_validity(@values_buffer.values(:f64, 0, @size))
110+
end
111+
end
112+
107113
class VariableSizeBinaryLayoutArray < Array
108114
def initialize(type, size, validity_buffer, offsets_buffer, values_buffer)
109115
super(type, size, validity_buffer)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def read_field(fb_field)
154154
case fb_type.precision
155155
when Org::Apache::Arrow::Flatbuf::Precision::SINGLE
156156
type = Float32Type.singleton
157+
when Org::Apache::Arrow::Flatbuf::Precision::DOUBLE
158+
type = Float64Type.singleton
157159
end
158160
when Org::Apache::Arrow::Flatbuf::List
159161
type = ListType.new(read_field(fb_field.children[0]))
@@ -189,8 +191,7 @@ def read_column(field, nodes, buffers, body)
189191

190192
case field.type
191193
when BooleanType,
192-
IntType,
193-
FloatType
194+
NumberType
194195
values_buffer = buffers.shift
195196
values = body.slice(values_buffer.offset, values_buffer.length)
196197
field.type.build_array(length, validity, values)

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def build_array(size, validity_buffer, values_buffer)
5454
end
5555
end
5656

57-
class IntType < Type
57+
class NumberType < Type
58+
end
59+
60+
class IntType < NumberType
5861
attr_reader :bit_width
5962
attr_reader :signed
6063
def initialize(name, bit_width, signed)
@@ -96,30 +99,46 @@ def build_array(size, validity_buffer, values_buffer)
9699
end
97100
end
98101

99-
class FloatType < Type
102+
class FloatingPointType < NumberType
100103
attr_reader :precision
101104
def initialize(name, precision)
102105
super(name)
103106
@precision = precision
104107
end
105108
end
106109

107-
class Float32Type < FloatType
110+
class Float32Type < FloatingPointType
108111
class << self
109112
def singleton
110113
@singleton ||= new
111114
end
112115
end
113116

114117
def initialize
115-
super("Float32", 32)
118+
super("Float32", :single)
116119
end
117120

118121
def build_array(size, validity_buffer, values_buffer)
119122
Float32Array.new(self, size, validity_buffer, values_buffer)
120123
end
121124
end
122125

126+
class Float64Type < FloatingPointType
127+
class << self
128+
def singleton
129+
@singleton ||= new
130+
end
131+
end
132+
133+
def initialize
134+
super("Float64", :double)
135+
end
136+
137+
def build_array(size, validity_buffer, values_buffer)
138+
Float64Array.new(self, size, validity_buffer, values_buffer)
139+
end
140+
end
141+
123142
class VariableSizeBinaryType < Type
124143
end
125144

0 commit comments

Comments
 (0)