Skip to content

Commit 07c1c44

Browse files
authored
GH-48945: [Ruby] Add support for writing large binary array (#48946)
### Rationale for this change It's a large variant of binary array. ### What changes are included in this PR? * Add `ArrowFormat::LargeBinaryType#to_flatbuffers` * Add support for `Arrow::LargeBinaryArray#values` * Add support for `Arrow::LargeBinaryArray` in `Arrow::{RecordBatch,Table}#raw_records` * Add support for `Arrow::LargeBinaryArray` in `Arrow::{RecordBatch,Table}#each_record` ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #48945 Authored-by: Sutou Kouhei <kou@clear-code.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 9f5a5c7 commit 07c1c44

7 files changed

Lines changed: 50 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ def build_array(size, validity_buffer, offsets_buffer, values_buffer)
511511
offsets_buffer,
512512
values_buffer)
513513
end
514+
515+
def to_flatbuffers
516+
FB::LargeBinary::Data.new
517+
end
514518
end
515519

516520
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
@@ -44,6 +44,8 @@ def convert_type(red_arrow_type)
4444
ArrowFormat::Float64Type.singleton
4545
when Arrow::BinaryDataType
4646
ArrowFormat::BinaryType.singleton
47+
when Arrow::LargeBinaryDataType
48+
ArrowFormat::LargeBinaryType.singleton
4749
when Arrow::StringDataType
4850
ArrowFormat::UTF8Type.singleton
4951
else
@@ -229,6 +231,17 @@ def test_write
229231
end
230232
end
231233

234+
sub_test_case("LargeBinary") do
235+
def build_array
236+
Arrow::LargeBinaryArray.new(["Hello".b, nil, "World".b])
237+
end
238+
239+
def test_write
240+
assert_equal(["Hello".b, nil, "World".b],
241+
@values)
242+
end
243+
end
244+
232245
sub_test_case("String") do
233246
def build_array
234247
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)