Skip to content

Commit 4574e70

Browse files
committed
apacheGH-51029: fix MapArray validation with unknown null count
1 parent a6f451b commit 4574e70

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎cpp/src/arrow/array/array_list_test.cc‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,23 @@ TEST_F(TestMapArray, ValueBuilder) {
15321532
ASSERT_ARRAYS_EQUAL(*actual_list, map_as_list);
15331533
}
15341534

1535+
// // GH-51029: Validate MapArray keys with an all-valid bitmap and unknown null count.
1536+
TEST_F(TestMapArray, ValidateKeysWithAllValidBitmap) {
1537+
auto keys = ArrayFromJSON(utf8(), R"(["a", "b"])");
1538+
auto items = ArrayFromJSON(int32(), "[1, 2]");
1539+
auto offsets = ArrayFromJSON(int32(), "[0, 1, 2]");
1540+
1541+
// Inject an all-valid validity bitmap with kUnknownNullCount.
1542+
auto keys_data = keys->data()->Copy();
1543+
keys_data->buffers[0] = ArrayFromJSON(boolean(), "[true, true]")->data()->buffers[1];
1544+
keys_data->null_count = kUnknownNullCount;
1545+
1546+
ASSERT_OK_AND_ASSIGN(auto result,
1547+
MapArray::FromArrays(offsets, MakeArray(keys_data), items));
1548+
ASSERT_OK(result->ValidateFull());
1549+
ASSERT_EQ(result->length(), 2);
1550+
}
1551+
15351552
// ----------------------------------------------------------------------
15361553
// FixedSizeList tests
15371554

‎cpp/src/arrow/array/array_nested.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,13 +896,13 @@ Status MapArray::ValidateChildData(
896896
if (pair_data->type->id() != Type::STRUCT) {
897897
return Status::Invalid("Map array child array should have struct type");
898898
}
899-
if (pair_data->MayHaveNulls()) {
899+
if (pair_data->GetNullCount() != 0) {
900900
return Status::Invalid("Map array child array should have no nulls");
901901
}
902902
if (pair_data->child_data.size() != 2) {
903903
return Status::Invalid("Map array child array should have two fields");
904904
}
905-
if (pair_data->child_data[0]->MayHaveNulls()) {
905+
if (pair_data->child_data[0]->GetNullCount() != 0) {
906906
return Status::Invalid("Map array keys array should have no nulls");
907907
}
908908
return Status::OK();

0 commit comments

Comments
 (0)