wesm commented on a change in pull request #7240: URL: https://github.com/apache/arrow/pull/7240#discussion_r428738646
########## File path: cpp/src/arrow/compute/kernels/codegen_internal.h ########## @@ -0,0 +1,648 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <cstdint> +#include <memory> +#include <vector> + +#include "arrow/array.h" +#include "arrow/compute/kernel.h" +#include "arrow/scalar.h" +#include "arrow/type_traits.h" +#include "arrow/util/bit_util.h" +#include "arrow/util/logging.h" +#include "arrow/util/optional.h" +#include "arrow/util/string_view.h" +#include "arrow/visitor_inline.h" + +namespace arrow { + +using internal::BitmapReader; +using internal::FirstTimeBitmapWriter; +using internal::GenerateBitsUnrolled; + +namespace compute { + +#ifdef ARROW_EXTRA_ERROR_CONTEXT + +#define KERNEL_ABORT_IF_ERROR(ctx, expr) \ + do { \ + Status _st = (expr); \ + if (ARROW_PREDICT_FALSE(!_st.ok())) { \ + _st.AddContextLine(__FILE__, __LINE__, #expr); \ + ctx->SetStatus(_st); \ + return; \ + } \ + } while (0) + +#else + +#define KERNEL_ABORT_IF_ERROR(ctx, expr) \ + do { \ + Status _st = (expr); \ + if (ARROW_PREDICT_FALSE(!_st.ok())) { \ + ctx->SetStatus(_st); \ + return; \ + } \ + } while (0) + +#endif // ARROW_EXTRA_ERROR_CONTEXT + +// A kernel that exposes Call methods that handles iteration over ArrayData +// inputs itself +// + +constexpr int kValidity = 0; +constexpr int kBinaryOffsets = 1; +constexpr int kPrimitiveData = 1; +constexpr int kBinaryData = 2; + +// ---------------------------------------------------------------------- +// Iteration / value access utilities + +template <typename T, typename R = void> +using enable_if_has_c_type_not_boolean = enable_if_t<has_c_type<T>::value && + !is_boolean_type<T>::value, R>; + +template <typename T, typename Enable = void> +struct CodegenTraits; + +template <typename T> +struct CodegenTraits<T, enable_if_has_c_type<T>> { + using value_type = typename T::c_type; +}; + +template <typename T> +struct CodegenTraits<T, enable_if_base_binary<T>> { + using value_type = util::string_view; +}; + +template <typename Type, typename Enable = void> +struct ArrayIterator; + +template <typename Type> +struct ArrayIterator<Type, enable_if_has_c_type_not_boolean<Type>> { + using T = typename Type::c_type; + const T* values; + ArrayIterator(const ArrayData& data) : values(data.GetValues<T>(1)) {} + T operator()() { return *values++; } +}; + +template <typename Type> +struct ArrayIterator<Type, enable_if_boolean<Type>> { + BitmapReader reader; + ArrayIterator(const ArrayData& data) + : reader(data.buffers[1]->data(), data.offset, data.length) {} + bool operator()() { + bool out = reader.IsSet(); + reader.Next(); + return out; + } +}; + +template <typename Type> +struct ArrayIterator<Type, enable_if_base_binary<Type>> { + int64_t position = 0; + typename TypeTraits<Type>::ArrayType arr; + ArrayIterator(const ArrayData& data) + : arr(data.Copy()) {} Review comment: Array subclasses require a `shared_ptr<ArrayData>` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org