aocsa commented on a change in pull request #11019: URL: https://github.com/apache/arrow/pull/11019#discussion_r700688954
########## File path: cpp/src/arrow/compute/kernels/select_k_test.cc ########## @@ -0,0 +1,714 @@ +// 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 <functional> +#include <iostream> +#include <limits> +#include <memory> +#include <string> +#include <vector> + +#include "arrow/array/array_decimal.h" +#include "arrow/array/concatenate.h" +#include "arrow/compute/api_vector.h" +#include "arrow/compute/kernels/test_util.h" +#include "arrow/table.h" +#include "arrow/testing/gtest_common.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" +#include "arrow/testing/util.h" +#include "arrow/type_traits.h" + +namespace arrow { + +using internal::checked_cast; +using internal::checked_pointer_cast; + +namespace compute { + +namespace { + +// Convert arrow::Type to arrow::DataType. If arrow::Type isn't +// parameter free, this returns an arrow::DataType with the default +// parameter. +template <typename ArrowType> +enable_if_t<TypeTraits<ArrowType>::is_parameter_free, std::shared_ptr<DataType>> +TypeToDataType() { + return TypeTraits<ArrowType>::type_singleton(); +} + +template <typename ArrowType> +enable_if_t<std::is_same<ArrowType, TimestampType>::value, std::shared_ptr<DataType>> +TypeToDataType() { + return timestamp(TimeUnit::MILLI); +} + +template <typename ArrowType> +enable_if_t<std::is_same<ArrowType, Time32Type>::value, std::shared_ptr<DataType>> +TypeToDataType() { + return time32(TimeUnit::MILLI); +} + +template <typename ArrowType> +enable_if_t<std::is_same<ArrowType, Time64Type>::value, std::shared_ptr<DataType>> +TypeToDataType() { + return time64(TimeUnit::NANO); +} + +// ---------------------------------------------------------------------- +// Tests for SelectK + +template <typename ArrayType> +auto GetLogicalValue(const ArrayType& array, uint64_t index) + -> decltype(array.GetView(index)) { + return array.GetView(index); +} + +Decimal128 GetLogicalValue(const Decimal128Array& array, uint64_t index) { + return Decimal128(array.Value(index)); +} + +Decimal256 GetLogicalValue(const Decimal256Array& array, uint64_t index) { + return Decimal256(array.Value(index)); +} + +} // namespace + +template <typename ArrayType, SortOrder order> +class SelectKComparator { + public: + template <typename Type> + bool operator()(const Type& lval, const Type& rval) { + if (is_floating_type<typename ArrayType::TypeClass>::value) { + // NaNs ordered after non-NaNs + if (rval != rval) return true; Review comment: Not for this case, this functor is used only to test output not to process data. So it is expected that NaN are not part of the output as null-like values were filtered before in TopK/BottomK. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org