arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[C++] Add a VisitIntegerType helper

Open pitrou opened this issue 4 months ago • 9 comments

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: https://github.com/apache/arrow/blob/154962c364bc210c10ef16680f54a115b624b400/cpp/src/arrow/util/dict_util.cc#L61-L79

Component(s)

C++

pitrou avatar Jul 22 '26 07:07 pitrou

@tadeja

pitrou avatar Jul 22 '26 07:07 pitrou

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

pitrou avatar Jul 22 '26 10:07 pitrou

Also @goel-skd

pitrou avatar Jul 22 '26 16:07 pitrou

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

goel-skd avatar Jul 22 '26 17:07 goel-skd

take

goel-skd avatar Jul 23 '26 04:07 goel-skd

@VedantRalekar - I am actively working on this.

goel-skd avatar Aug 03 '26 00:08 goel-skd

@goel-skd Are you still working on this?

Judging by https://github.com/apache/arrow/pull/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

pitrou avatar Oct 27 '26 10:10 pitrou

Yes. Will submit a patch soon.

goel-skd avatar Oct 27 '26 11:10 goel-skd

Yes. Will submit a patch soon.

Great, happy to take a look once submitted :)

taepper avatar Oct 28 '26 09:10 taepper