From bb1998fdea5833e06f10d946fd2ae0f06a95e0ed Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 10 Jan 2025 13:21:18 -0500 Subject: [PATCH 1/2] GH-45167: [C++] Implement Compute Equals for List Types --- .../arrow/compute/kernels/codegen_internal.h | 55 ++++++++++++++++ .../arrow/compute/kernels/scalar_compare.cc | 8 +++ .../compute/kernels/scalar_compare_test.cc | 66 +++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/cpp/src/arrow/compute/kernels/codegen_internal.h b/cpp/src/arrow/compute/kernels/codegen_internal.h index 2a492f581f53b..f420b31e78d34 100644 --- a/cpp/src/arrow/compute/kernels/codegen_internal.h +++ b/cpp/src/arrow/compute/kernels/codegen_internal.h @@ -141,6 +141,13 @@ struct GetViewType::value || static T LogicalValue(PhysicalType value) { return value; } }; +template +struct GetViewType> { + using T = typename TypeTraits::ScalarType; + + static T LogicalValue(T value) { return value; } +}; + template <> struct GetViewType { using T = Decimal32; @@ -322,6 +329,32 @@ struct ArrayIterator> { } }; +template +struct ArrayIterator> { + using T = typename TypeTraits::ScalarType; + using ArrayT = typename TypeTraits::ArrayType; + + const ArraySpan& arr; + const char* data; + const int32_t width; + int64_t position; + + explicit ArrayIterator(const ArraySpan& arr) + : arr(arr), + data(reinterpret_cast(arr.buffers[1].data)), + width(arr.type->byte_width()), + position(arr.offset) {} + + T operator()() { + // TODO: how cann we avoid the ToArray call + const auto array_ptr = arr.ToArray(); + const auto array = checked_cast(array_ptr.get()); + auto result = T{array->value_slice(position)}; + position++; + return result; + } +}; + template <> struct ArrayIterator { const ArraySpan& arr; @@ -390,6 +423,12 @@ struct UnboxScalar> { } }; +template +struct UnboxScalar> { + using T = typename TypeTraits::ScalarType; + static const T& Unbox(const Scalar& val) { return checked_cast(val); } +}; + template <> struct UnboxScalar { using T = Decimal32; @@ -1383,6 +1422,22 @@ ArrayKernelExec GenerateDecimal(detail::GetTypeId get_id) { } } +// Generate a kernel given a templated functor for list types +// +// See "Numeric" above for description of the generator functor +template