Skip to content

Commit 3d75b88

Browse files
committed
GH-48945: [Ruby] Add support for writing large binary array
1 parent 044ca4d commit 3d75b88

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ def build_array(size, validity_buffer, offsets_buffer, values_buffer)
505505
offsets_buffer,
506506
values_buffer)
507507
end
508+
509+
def to_flatbuffers
510+
FB::LargeBinary::Data.new
511+
end
508512
end
509513

510514
class UTF8Type < VariableSizeBinaryType

ruby/red-arrow-format/test/test-writer.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def convert_type(red_arrow_type)
4040
ArrowFormat::UInt64Type.singleton
4141
when Arrow::BinaryDataType
4242
ArrowFormat::BinaryType.singleton
43+
when Arrow::LargeBinaryDataType
44+
ArrowFormat::LargeBinaryType.singleton
4345
when Arrow::StringDataType
4446
ArrowFormat::UTF8Type.singleton
4547
else
@@ -203,6 +205,17 @@ def test_write
203205
end
204206
end
205207

208+
sub_test_case("LargeBinary") do
209+
def build_array
210+
Arrow::LargeBinaryArray.new(["Hello".b, nil, "World".b])
211+
end
212+
213+
def test_write
214+
assert_equal(["Hello".b, nil, "World".b],
215+
@values)
216+
end
217+
end
218+
206219
sub_test_case("String") do
207220
def build_array
208221
Arrow::StringArray.new(["Hello", nil, "World"])

ruby/red-arrow/ext/arrow/converters.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,15 @@ namespace red_arrow {
153153
const int64_t i) {
154154
int32_t length;
155155
const auto value = array.GetValue(i, &length);
156-
// TODO: encoding support
156+
return rb_enc_str_new(reinterpret_cast<const char*>(value),
157+
length,
158+
rb_ascii8bit_encoding());
159+
}
160+
161+
inline VALUE convert(const arrow::LargeBinaryArray& array,
162+
const int64_t i) {
163+
int64_t length;
164+
const auto value = array.GetValue(i, &length);
157165
return rb_enc_str_new(reinterpret_cast<const char*>(value),
158166
length,
159167
rb_ascii8bit_encoding());

ruby/red-arrow/ext/arrow/raw-records.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace red_arrow {
8888
VISIT(Float)
8989
VISIT(Double)
9090
VISIT(Binary)
91+
VISIT(LargeBinary)
9192
VISIT(String)
9293
VISIT(FixedSizeBinary)
9394
VISIT(Date32)
@@ -224,6 +225,7 @@ namespace red_arrow {
224225
VISIT(Float)
225226
VISIT(Double)
226227
VISIT(Binary)
228+
VISIT(LargeBinary)
227229
VISIT(String)
228230
VISIT(FixedSizeBinary)
229231
VISIT(Date32)

ruby/red-arrow/ext/arrow/values.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace red_arrow {
6969
VISIT(Float)
7070
VISIT(Double)
7171
VISIT(Binary)
72+
VISIT(LargeBinary)
7273
VISIT(String)
7374
VISIT(FixedSizeBinary)
7475
VISIT(Date32)

ruby/red-arrow/test/raw-records/test-basic-arrays.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ def test_binary
157157
assert_equal(records, actual_records(target))
158158
end
159159

160+
def test_large_binary
161+
records = [
162+
["\x00".b],
163+
[nil],
164+
["\xff".b],
165+
]
166+
target = build({column: :large_binary}, records)
167+
assert_equal(records, actual_records(target))
168+
end
169+
160170
def test_string
161171
records = [
162172
["Ruby"],

ruby/red-arrow/test/values/test-basic-arrays.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ def test_binary
147147
assert_equal(values, target.values)
148148
end
149149

150-
def test_tring
150+
def test_large_binary
151+
values = [
152+
"\x00".b,
153+
nil,
154+
"\xff".b,
155+
]
156+
target = build(Arrow::LargeBinaryArray.new(values))
157+
assert_equal(values, target.values)
158+
end
159+
160+
def test_string
151161
values = [
152162
"Ruby",
153163
nil,

0 commit comments

Comments
 (0)