pitrou commented on code in PR #45562: URL: https://github.com/apache/arrow/pull/45562#discussion_r1970185714
########## cpp/src/arrow/compute/kernels/pivot_internal.cc: ########## @@ -0,0 +1,127 @@ +// 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 "arrow/compute/kernels/pivot_internal.h" + +#include <cstdint> + +#include "arrow/compute/exec.h" +#include "arrow/compute/kernels/codegen_internal.h" +#include "arrow/scalar.h" +#include "arrow/type_traits.h" +#include "arrow/util/checked_cast.h" +#include "arrow/visit_type_inline.h" + +namespace arrow::compute::internal { + +using ::arrow::util::span; + +struct BasePivotKeyMapper : public PivotWiderKeyMapper { + Status Init(const PivotWiderOptions* options) override { + if (options->key_names.size() > static_cast<size_t>(kMaxPivotKey) + 1) { + return Status::NotImplemented("Pivoting to more than ", + static_cast<size_t>(kMaxPivotKey) + 1, + " columns: got ", options->key_names.size()); + } + key_name_map_.reserve(options->key_names.size()); + PivotWiderKeyIndex index = 0; + for (const auto& key_name : options->key_names) { + bool inserted = + key_name_map_.try_emplace(std::string_view(key_name), index++).second; + if (!inserted) { + return Status::KeyError("Duplicate key name '", key_name, + "' in PivotWiderOptions"); + } + } + unexpected_key_behavior_ = options->unexpected_key_behavior; + return Status::OK(); + } + + protected: + Result<PivotWiderKeyIndex> KeyNotFound(std::string_view key_name) { + if (unexpected_key_behavior_ == PivotWiderOptions::kIgnore) { + return kNullPivotKey; + } + return Status::KeyError("Unexpected pivot key: ", key_name); + } + + Result<PivotWiderKeyIndex> LookupKey(std::string_view key_name) { + const auto it = this->key_name_map_.find(key_name); + if (ARROW_PREDICT_FALSE(it == this->key_name_map_.end())) { + return KeyNotFound(key_name); + } else { + return it->second; + } + } + + Status NullKeyName() { return Status::KeyError("pivot key name cannot be null"); } + + static constexpr int kBatchLength = 512; Review Comment: Probably a leftover, I'll remove it :) -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
