fenfeng9 commented on issue #50113: URL: https://github.com/apache/arrow/issues/50113#issuecomment-4639226572
I think this bug is in the union logical null count path. `count` calls `ComputeLogicalNullCount()` for array inputs here: https://github.com/apache/arrow/blob/e980b7ef70f66c2d5b674bd637a070333e10a3fc/cpp/src/arrow/compute/kernels/aggregate_basic.cc#L101-L108 For union arrays, `ArraySpan::ComputeLogicalNullCount()` dispatches to the union logical null count helpers here: https://github.com/apache/arrow/blob/e980b7ef70f66c2d5b674bd637a070333e10a3fc/cpp/src/arrow/array/data.cc#L624-L630 The sparse and dense union implementations are here: https://github.com/apache/arrow/blob/e980b7ef70f66c2d5b674bd637a070333e10a3fc/cpp/src/arrow/util/union_util.cc#L28-L38 https://github.com/apache/arrow/blob/e980b7ef70f66c2d5b674bd637a070333e10a3fc/cpp/src/arrow/util/union_util.cc#L43-L53 `LogicalSparseUnionNullCount` uses `types = span.GetValues<int8_t>(1)`, which already accounts for `span.offset`, but it still indexes `types[span.offset + i]`. It also checks child nullness with `IsNull(i)` instead of `IsNull(span.offset + i)`. Likewise, `LogicalDenseUnionNullCount` uses `GetValues(...)` pointers that already account for `span.offset`, but it still indexes `types[span.offset + i]` and `offsets[span.offset + i]`. As a result, sliced unions can report incorrect logical null counts, which affects `count`. I verified the issue and a local fix, and I plan to open a PR shortly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
