Skip to content

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

Open

Description

@felipecrv

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:

    template <typename ArrowType>
    bool IsNullFast(int64_t i) const {
      return !IsValidFast<ArrowType>(i);
    }

    template <typename ArrowType>
    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++

Activity

  1. felipecrv commented on Apr 14, 2023

    @felipecrv
    ContributorAuthor

    take

  2. added
    Status: stale-warning
    on Feb 18, 2026
  3. thisisnic commented on Feb 18, 2026

    @thisisnic
    Member

    This issue has been marked as stale because it has had no activity in the past 2 years. Please remove the stale label or comment below, or this issue will be closed in 14 days.

  4. removed
    Status: stale-warning
    on May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions