Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/aggregate_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct CountImpl : public ScalarAggregator {
this->non_nulls += batch.length;
} else if (batch[0].is_array()) {
const ArraySpan& input = batch[0].array;
const int64_t nulls = input.GetNullCount();
const int64_t nulls = input.ComputeLogicalNullCount();
this->nulls += nulls;
this->non_nulls += input.length - nulls;
} else {
Expand Down
10 changes: 10 additions & 0 deletions cpp/src/arrow/compute/kernels/aggregate_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,16 @@ TYPED_TEST(TestCountKernel, SimpleCount) {
EXPECT_THAT(Count(*MakeScalar(ty, 1), all), ResultWith(Datum(int64_t(1))));
}

TEST(TestCountKernel, RunEndEncodedNulls) {
auto input = ArrayFromJSON(int32(), "[1, 1, null, null, null, 2, 2, 2, null, 3]");
ASSERT_OK_AND_ASSIGN(auto encoded, RunEndEncode(input));

auto array = encoded.make_array();
ValidateCount(*array, {6, 4});
// Logical slice: [null, null, 2, 2, 2, null].
ValidateCount(*array->Slice(3, 6), {3, 3});
}

template <typename ArrowType>
class TestRandomNumericCountKernel : public ::testing::Test {};

Expand Down
12 changes: 12 additions & 0 deletions python/pyarrow/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,18 @@ def test_count():
pc.count(arr, 'something else')


def test_count_run_end_encoded_nulls():
arr = pc.run_end_encode(
pa.array([1, 1, None, None, None, 2, 2, 2, None, 3]))

assert pc.count(arr, mode="only_valid").as_py() == 6
assert pc.count(arr, mode="only_null").as_py() == 4
assert pc.count(arr, mode="all").as_py() == 10
# Slice crosses run boundaries: logical [None, None, 2, 2, 2, None].
assert pc.count(arr.slice(3, 6), mode="only_valid").as_py() == 3
assert pc.count(arr.slice(3, 6), mode="only_null").as_py() == 3


def test_index():
arr = pa.array([0, 1, None, 3, 4], type=pa.int64())
assert pc.index(arr, pa.scalar(0)).as_py() == 0
Expand Down
Loading