Skip to content

[C++] Add a VisitIntegerType helper #50595

Open

Description

@pitrou

Describe the enhancement requested

In visit_type_inline.h we have a VisitType that dispatches all existing data types to a generic callable (presumably a lambda or template function).

It would be useful to have a similar VisitIntegerType helper that assumes its input is an integer type. This would help implementing helpers for dictionary indices, take indices, etc.

For example this snippet could be reimplemented more tersely using said helper:

const auto& dict_array_type = internal::checked_cast<const DictionaryType&>(*span.type);
switch (dict_array_type.index_type()->id()) {
case Type::UINT8:
return LogicalNullCount<UInt8Type>(span);
case Type::INT8:
return LogicalNullCount<Int8Type>(span);
case Type::UINT16:
return LogicalNullCount<UInt16Type>(span);
case Type::INT16:
return LogicalNullCount<Int16Type>(span);
case Type::UINT32:
return LogicalNullCount<UInt32Type>(span);
case Type::INT32:
return LogicalNullCount<Int32Type>(span);
case Type::UINT64:
return LogicalNullCount<UInt64Type>(span);
default:
return LogicalNullCount<Int64Type>(span);
}

Component(s)

C++

Activity

  1. pitrou commented on Jul 22, 2026

    @pitrou
    MemberAuthor
  2. pitrou commented on Jul 22, 2026

    @pitrou
    MemberAuthor

    And we can similarly want a VisitRunEndType that dispatches over all 3 supported run-end types: INT16, INT32, INT64.

  3. pitrou commented on Jul 22, 2026

    @pitrou
    MemberAuthor
  4. goel-skd commented on Jul 22, 2026

    @goel-skd
    Contributor

    I can take it along with my current work. Will look at it in a couple of days

  5. goel-skd commented on Jul 23, 2026

    @goel-skd
    Contributor

    take

  6. goel-skd commented on Aug 3, 2026

    @goel-skd
    Contributor

    @VedantRalekar - I am actively working on this.

  7. pitrou commented on Oct 27, 2026

    @pitrou
    MemberAuthor

    @goel-skd Are you still working on this?

    Judging by #52469, this would still be useful, for example to reduce:

    template <template <typename...> class Checker, typename InType>
    Status CheckFloatToIntImpl(const ArraySpan& input, const ArraySpan& output) {
      switch (output.type->id()) {
        case Type::INT8:
          return CheckFloatToIntValues<Checker, InType, Int8Type>(input, output);
        case Type::INT16:
          return CheckFloatToIntValues<Checker, InType, Int16Type>(input, output);
        case Type::INT32:
          return CheckFloatToIntValues<Checker, InType, Int32Type>(input, output);
        case Type::INT64:
          return CheckFloatToIntValues<Checker, InType, Int64Type>(input, output);
        case Type::UINT8:
          return CheckFloatToIntValues<Checker, InType, UInt8Type>(input, output);
        case Type::UINT16:
          return CheckFloatToIntValues<Checker, InType, UInt16Type>(input, output);
        case Type::UINT32:
          return CheckFloatToIntValues<Checker, InType, UInt32Type>(input, output);
        case Type::UINT64:
          return CheckFloatToIntValues<Checker, InType, UInt64Type>(input, output);
        default:
          break;
      }
      DCHECK(false);
      return Status::OK();
    }

    into something like:

    template <template <typename...> class Checker, typename InType>
    Status CheckFloatToIntImpl(const ArraySpan& input, const ArraySpan& output) {
      return VisitIntegerType(*output.type, [&]<typename OutType>(OutType*) {
        return CheckFloatToIntValues<Checker, InType, OutType>(input, output);
      });
    }

    Also cc @taepper

  8. goel-skd commented on Oct 27, 2026

    @goel-skd
    Contributor

    Yes. Will submit a patch soon.

  9. taepper commented on Oct 28, 2026

    @taepper
    Contributor

    Yes. Will submit a patch soon.

    Great, happy to take a look once submitted :)

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