Skip to content

Commit 66c2cf0

Browse files
authored
GH-44742: [Ruby] Fix a bug that empty struct list value can't be built (#44763)
### Rationale for this change This codes add a list value but no struct value isn't added: ```ruby require "arrow" schema = Arrow::Schema.new( [ Arrow::Field.new("structs", Arrow::ListDataType.new( Arrow::StructDataType.new([ Arrow::Field.new("foo", :int64), Arrow::Field.new("bar", :int64) ]) )) ] ) Arrow::RecordBatchBuilder.build(schema, [{structs: []}]) ``` ### What changes are included in this PR? Don't add a list value. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #44742 Authored-by: Sutou Kouhei <kou@clear-code.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent bc36282 commit 66c2cf0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ruby/red-arrow/lib/arrow/list-array-builder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def append_value(*args)
5454
when nil
5555
append_null
5656
when ::Array
57+
return if value.empty?
5758
append_value_raw
5859
@value_builder ||= value_builder
5960
@value_builder.append(*value)

ruby/red-arrow/test/test-list-array-builder.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def setup
3333
array = @builder.finish
3434
assert_equal([true, false, true], array[0].to_a)
3535
end
36+
37+
test("Struct[]") do
38+
item_type = Arrow::StructDataType.new([{name: "visible", type: :boolean}])
39+
data_type = Arrow::ListDataType.new(name: "struct", data_type: item_type)
40+
builder = Arrow::ListArrayBuilder.new(data_type)
41+
builder.append_value([])
42+
array = builder.finish
43+
assert_equal([], array[0].to_a)
44+
end
3645
end
3746

3847
sub_test_case("#append_values") do

0 commit comments

Comments
 (0)