Skip to content

Commit

Permalink
apacheGH-41016: [C++] Fix null count check in BooleanArray.true_count()
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Apr 8, 2024
1 parent 84f6ede commit 79d9b3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/src/arrow/array/array_primitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int64_t BooleanArray::false_count() const {
}

int64_t BooleanArray::true_count() const {
if (data_->null_count.load() != 0) {
if (data_->GetNullCount() != 0) {
DCHECK(data_->buffers[0]);
return internal::CountAndSetBits(data_->buffers[0]->data(), data_->offset,
data_->buffers[1]->data(), data_->offset,
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,14 @@ TEST(TestBooleanArray, TrueCountFalseCount) {
CheckArray(checked_cast<const BooleanArray&>(*arr));
CheckArray(checked_cast<const BooleanArray&>(*arr->Slice(5)));
CheckArray(checked_cast<const BooleanArray&>(*arr->Slice(0, 0)));

// GH-41016 true_count() with array without validity buffer with null_count of -1
auto data = ArrayFromJSON(boolean(), "[true, false, true]")->data();
data->null_count = -1;
std::shared_ptr<BooleanArray> arr2(new BooleanArray(data));
ASSERT_EQ(arr2->data()->null_count.load(), -1);
ASSERT_EQ(arr2->null_bitmap(), nullptr);
ASSERT_EQ(arr2->true_count(), 2);
}

TEST(TestPrimitiveAdHoc, TestType) {
Expand Down

0 comments on commit 79d9b3c

Please sign in to comment.