Skip to content

Commit

Permalink
gather_intenal.h: Clarify the semantics of ValiditySpan/IsSrcValid
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Aug 15, 2024
1 parent 7fa4dd9 commit 344f77b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cpp/src/arrow/compute/kernels/gather_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class GatherBaseCRTP {
template <typename IndexCType>
bool IsSrcValid(const ArraySpan& src_validity, const IndexCType* idx,
int64_t position) const {
// Translate position into index on the source
const int64_t index = idx[position];
ARROW_COMPILER_ASSUME(src_validity.buffers[0].data != nullptr);
return src_validity.IsValid(idx[position]);
return src_validity.IsValid(index);
}

ARROW_FORCE_INLINE int64_t ExecuteNoNulls(int64_t idx_length) {
Expand All @@ -89,6 +91,9 @@ class GatherBaseCRTP {
// doesn't have to be called for resulting null positions. A position is
// considered null if either the index or the source value is null at that
// position.
//
// ValiditySpan is any class that `GatherImpl::IsSrcValid(src_validity, idx, position)`
// can be called with.
template <bool kOutputIsZeroInitialized, typename IndexCType,
class ValiditySpan = ArraySpan>
ARROW_FORCE_INLINE int64_t ExecuteWithNulls(const ValiditySpan& src_validity,
Expand Down Expand Up @@ -333,7 +338,10 @@ struct ChunkedValiditySpan {

bool MayHaveNulls() const { return may_have_nulls; }

bool IsValid(int64_t position) const {
bool IsSrcValid(const IndexCType* idx, int64_t position) const {
// idx is unused because all the indices have been pre-resolved into
// `chunk_index_vec` and `index_in_chunk_vec` by ChunkResolver::ResolveMany.
ARROW_UNUSED(idx);
auto chunk_index = chunk_index_vec[position];
auto index_in_chunk = index_in_chunk_vec[position];
return chunks_validity.chunk(static_cast<int>(chunk_index))->IsValid(index_in_chunk);
Expand Down Expand Up @@ -407,7 +415,7 @@ class GatherFromChunks

bool IsSrcValid(const ChunkedValiditySpan<IndexCType>& src_validity,
const IndexCType* idx, int64_t position) const {
return src_validity.IsValid(position);
return src_validity.IsSrcValid(idx, position);
}

public:
Expand Down

0 comments on commit 344f77b

Please sign in to comment.