Skip to content

Commit

Permalink
add util test
Browse files Browse the repository at this point in the history
  • Loading branch information
js8544 committed Dec 18, 2023
1 parent 73b2442 commit 19b01f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,19 @@ TEST_F(TestArray, TestMakeArrayOfNullUnion) {
ASSERT_EQ(typed_union.raw_value_offsets()[i], 0);
}
}

// zero-length nested types should have union children with length zero
auto list_union = list(dense_union({field("a", utf8()), field("b", int32())}, {0, 1}));
ASSERT_OK_AND_ASSIGN(auto list_union_nulls, MakeArrayOfNull(list_union, 0));
ASSERT_OK(list_union_nulls->ValidateFull());
ASSERT_EQ(list_union_nulls->null_count(), 0);
{
const auto& typed_list = checked_cast<const ListArray&>(*list_union_nulls);
const auto& typed_union = checked_cast<const DenseUnionArray&>(*typed_list.values());
// Child field has length 0
ASSERT_EQ(typed_union.field(0)->length(), 0);
ASSERT_EQ(typed_union.field(0)->null_count(), 0);
}
}

TEST_F(TestArray, TestValidateNullCount) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/array/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class NullArrayFactory {
int64_t child_length = length_;
if (type.mode() == UnionMode::DENSE) {
// For dense unions, we set the offsets to all zero and create children
// with length 1
// with length 1 if length_ is non-zero
out_->buffers.resize(3);
out_->buffers[2] = buffer_;

Expand Down

0 comments on commit 19b01f9

Please sign in to comment.