Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cpp/src/arrow/array/array_run_end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,7 @@ TEST_P(TestRunEndEncodedArray, Validate) {
BitmapFromVector<bool>({true, false}, &null_bitmap);
has_null_buffer->data()->buffers[0] = null_bitmap;
EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid,
::testing::HasSubstr(
std::string("Invalid: Run end encoded array should not have a null bitmap.")),
Invalid, ::testing::HasSubstr(std::string("should not have a null bitmap")),
has_null_buffer->Validate());

auto too_many_children = MakeArray(good_array->data()->Copy());
Expand All @@ -570,7 +568,7 @@ TEST_P(TestRunEndEncodedArray, Validate) {
values_nullptr->Validate());

auto run_ends_string = MakeArray(good_array->data()->Copy());
run_ends_string->data()->child_data[0] = values->data();
run_ends_string->data()->child_data[0] = MakeEmptyArray(utf8()).ValueOrDie()->data();
EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid,
::testing::HasSubstr(
Expand All @@ -596,10 +594,9 @@ TEST_P(TestRunEndEncodedArray, Validate) {
malformed_array->data()->buffers.emplace_back(NULLPTR);
EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid,
::testing::HasSubstr(
std::string(
"Invalid: Run ends array invalid: Expected 2 buffers in array of type ") +
run_end_type->ToString() + ", got 3"),
::testing::HasSubstr(std::string("Invalid: Run ends array invalid: Invalid: "
"Expected 2 buffers in array of type ") +
run_end_type->ToString() + ", got 3"),
run_ends_malformed->Validate());
}

Expand All @@ -610,8 +607,9 @@ TEST_P(TestRunEndEncodedArray, Validate) {
malformed_array->data()->buffers.emplace_back(NULLPTR);
EXPECT_RAISES_WITH_MESSAGE_THAT(
Invalid,
::testing::HasSubstr("Invalid: Values array invalid: Expected 2 buffers in array "
"of type int32, got 3"),
::testing::HasSubstr(
"Invalid: Values array invalid: Invalid: Expected 2 buffers in array "
"of type int32, got 3"),
values_malformed->Validate());
}

Expand Down
25 changes: 25 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ static std::vector<std::shared_ptr<DataType>> TestArrayUtilitiesAgainstTheseType
list_view(utf8()),
large_list_view(utf8()),
dictionary(int32(), utf8()),
struct_({}),
struct_({field("a", utf8()), field("b", int32())}),
sparse_union(union_fields1, union_type_codes),
sparse_union(union_fields2, union_type_codes),
Expand All @@ -477,6 +478,7 @@ static std::vector<std::shared_ptr<DataType>> TestArrayUtilitiesAgainstTheseType

TEST_F(TestArray, TestMakeArrayOfNull) {
for (int64_t length : {0, 1, 16, 133}) {
ARROW_SCOPED_TRACE("length = ", length);
for (auto type : TestArrayUtilitiesAgainstTheseTypes()) {
ARROW_SCOPED_TRACE("type = ", type->ToString());
ASSERT_OK_AND_ASSIGN(auto array, MakeArrayOfNull(type, length));
Expand Down Expand Up @@ -506,6 +508,29 @@ TEST_F(TestArray, TestMakeArrayOfNull) {
}
}
}

for (int64_t length : {0, 16}) {
ARROW_SCOPED_TRACE("length = ", length, " (required fields)");

auto req = [](auto type) { return field("", std::move(type), /*nullable=*/false); };

// union with no nullable fields cannot represent a null
ASSERT_RAISES(TypeError, MakeArrayOfNull(dense_union({req(int8())}), length));
// run end encoded with non nullable child cannot represent a null
// (not directly constructible, but not invalid per Columnar.rst)
auto ree = run_end_encoded(int16(), utf8());
const_cast<FieldVector&>(ree->fields())[1] = req(utf8());
ASSERT_RAISES(TypeError, MakeArrayOfNull(ree, length));

// struct with no nullable fields has a top level bitmap and can mask them
ASSERT_OK_AND_ASSIGN(auto s, MakeArrayOfNull(struct_({req(int8())}), length));
ASSERT_OK(s->ValidateFull());

// dictionary with non-nullable indices can use a 1-long dict of null
ASSERT_OK_AND_ASSIGN(
s, MakeArrayOfNull(struct_({req(dictionary(int8(), int8()))}), length));
ASSERT_OK(s->ValidateFull());
Comment thread
bkietz marked this conversation as resolved.
}
}

TEST_F(TestArray, TestMakeArrayOfNullUnion) {
Expand Down
Loading
Loading