Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependency-reduced-pom.xml
MANIFEST
compile_commands.json
build.ninja
build/
Comment thread
AnuragRaut08 marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build/


# Generated Visual Studio files
*.vcxproj
Expand Down
37 changes: 37 additions & 0 deletions cpp/src/arrow/array/array_list_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,43 @@ TEST_F(TestMapArray, ValueBuilder) {
ASSERT_ARRAYS_EQUAL(*actual_list, map_as_list);
}

// GH-51029: Validate MapArray keys with an all-valid bitmap and unknown null count.
TEST_F(TestMapArray, ValidateKeysWithAllValidBitmap) {
auto keys = ArrayFromJSON(utf8(), R"(["a", "b"])");
auto items = ArrayFromJSON(int32(), "[1, 2]");
auto offsets = ArrayFromJSON(int32(), "[0, 1, 2]");

// Inject an all-valid validity bitmap with kUnknownNullCount.
auto keys_data = keys->data()->Copy();
keys_data->buffers[0] = ArrayFromJSON(boolean(), "[true, true]")->data()->buffers[1];
keys_data->null_count = kUnknownNullCount;

ASSERT_OK_AND_ASSIGN(auto result,
MapArray::FromArrays(offsets, MakeArray(keys_data), items));
ASSERT_OK(result->ValidateFull());
ASSERT_EQ(result->length(), 2);
}

TEST_F(TestMapArray, FromArraysWithAllValidOffsetsBitmap) {
auto offsets = ArrayFromJSON(int32(), "[0, 1, 2]");
auto keys = ArrayFromJSON(utf8(), R"(["a", "b"])");
auto items = ArrayFromJSON(int32(), "[1, 2]");

// Inject an all-valid validity bitmap with kUnknownNullCount.
auto offsets_data = offsets->data()->Copy();
offsets_data->buffers[0] =
ArrayFromJSON(boolean(), "[true, true, true]")->data()->buffers[1];
offsets_data->null_count = kUnknownNullCount;
offsets = MakeArray(offsets_data);

auto null_bitmap = ArrayFromJSON(boolean(), "[true, true]")->data()->buffers[1];

ASSERT_OK_AND_ASSIGN(auto result,
MapArray::FromArrays(offsets, keys, items, pool_, null_bitmap));
ASSERT_OK(result->ValidateFull());
ASSERT_EQ(result->length(), 2);
}

// ----------------------------------------------------------------------
// FixedSizeList tests

Expand Down
10 changes: 5 additions & 5 deletions cpp/src/arrow/array/array_nested.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>> ListArrayFromArray
return Status::TypeError("List offsets must be ", OffsetArrowType::type_name());
}

if (null_bitmap != nullptr && offsets.data()->MayHaveNulls()) {
if (null_bitmap != nullptr && offsets.data()->GetNullCount() != 0) {
return Status::Invalid(
"Ambiguous to specify both validity map and offsets with nulls");
}
Expand Down Expand Up @@ -826,7 +826,7 @@ Result<std::shared_ptr<Array>> MapArray::FromArraysInternal(
return Status::Invalid("Map key and item arrays must be equal length");
}

if (null_bitmap != nullptr && offsets->data()->MayHaveNulls()) {
if (null_bitmap != nullptr && offsets->data()->GetNullCount() != 0) {
return Status::Invalid(
"Ambiguous to specify both validity map and offsets with nulls");
}
Expand All @@ -835,7 +835,7 @@ Result<std::shared_ptr<Array>> MapArray::FromArraysInternal(
return Status::NotImplemented("Null bitmap with offsets slice not supported.");
}

if (offsets->data()->MayHaveNulls()) {
if (offsets->data()->GetNullCount() != 0) {
ARROW_ASSIGN_OR_RAISE(auto buffers,
CleanListOffsets<MapType>(NULLPTR, *offsets, pool));
return std::make_shared<MapArray>(type, offsets->length() - 1, std::move(buffers),
Expand Down Expand Up @@ -896,13 +896,13 @@ Status MapArray::ValidateChildData(
if (pair_data->type->id() != Type::STRUCT) {
return Status::Invalid("Map array child array should have struct type");
}
if (pair_data->MayHaveNulls()) {
if (pair_data->GetNullCount() != 0) {
return Status::Invalid("Map array child array should have no nulls");
}
if (pair_data->child_data.size() != 2) {
return Status::Invalid("Map array child array should have two fields");
}
if (pair_data->child_data[0]->MayHaveNulls()) {
if (pair_data->child_data[0]->GetNullCount() != 0) {
return Status::Invalid("Map array keys array should have no nulls");
}
return Status::OK();
Expand Down
Loading