[C++] Add a VisitIntegerType helper
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++
@tadeja
And we can similarly want a VisitRunEndType that dispatches over all 3 supported run-end types: INT16, INT32, INT64.
Also @goel-skd
I can take it along with my current work. Will look at it in a couple of days
take
@VedantRalekar - I am actively working on this.
@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
Yes. Will submit a patch soon.
Yes. Will submit a patch soon.
Great, happy to take a look once submitted :)