apache / apache/arrow

[C++] Add versions of IsNull/IsValid that take an ArrowType tparam so implementation can be statically dispatched

Open
#35,141 2 comments 0 reactions 1 assignee Claimed by @felipecrv View on GitHub
Component: C++ Type: enhancement
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 18h
Merged PRs (30d)
91

Description

### Describe the enhancement requested

#34408 introduced more branches to the implementations of `IsNull` and `IsValid` testing the type to of the array to dispatch specific implementations for a few special types. Although these branches are easy on the branch predictor, it's good to offer users that know the type ahead of time a way to eliminate those branches completely from their loops.

Proposed implementation using `if constexpr`:

```cpp
template
bool IsNullFast(int64_t i) const {
return !IsValidFast(i);
}

template
bool IsValidFast(int64_t i) const {
if constexpr (ArrowType::type_id == Type::NA) {
return false;
} else if constexpr (ArrowType::type_id == Type::SPARSE_UNION) {
return !internal::IsNullSparseUnion(*this, i);
} else if constexpr (ArrowType::type_id == Type::DENSE_UNION) {
return !internal::IsNullDenseUnion(*this, i);
} else if constexpr (ArrowType::type_id == Type::RUN_END_ENCODED) {
return !internal::IsNullRunEndEncoded(*this, i);
} else {
if (buffers[0] != NULLPTR) {
return bit_util::GetBit(buffers[0]->data(), i + offset);
}
return null_count.load() != length;
}
}
```

### Component(s)

C++

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.