Skip to content

Commit

Permalink
GH-44742: [Ruby] Fix a bug that empty struct list value can't be built (
Browse files Browse the repository at this point in the history
#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 <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
kou authored Nov 19, 2024
1 parent bc36282 commit 66c2cf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions ruby/red-arrow/lib/arrow/list-array-builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def append_value(*args)
when nil
append_null
when ::Array
return if value.empty?
append_value_raw
@value_builder ||= value_builder
@value_builder.append(*value)
Expand Down
9 changes: 9 additions & 0 deletions ruby/red-arrow/test/test-list-array-builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def setup
array = @builder.finish
assert_equal([true, false, true], array[0].to_a)
end

test("Struct[]") do
item_type = Arrow::StructDataType.new([{name: "visible", type: :boolean}])
data_type = Arrow::ListDataType.new(name: "struct", data_type: item_type)
builder = Arrow::ListArrayBuilder.new(data_type)
builder.append_value([])
array = builder.finish
assert_equal([], array[0].to_a)
end
end

sub_test_case("#append_values") do
Expand Down

0 comments on commit 66c2cf0

Please sign in to comment.