Alex-PLACET commented on code in PR #49679: URL: https://github.com/apache/arrow/pull/49679#discussion_r3126702938
########## cpp/src/arrow/compute/kernels/vector_search_sorted_test.cc: ########## @@ -0,0 +1,409 @@ +// 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 <memory> +#include <string> +#include <vector> + +#include <gtest/gtest.h> + +#include "arrow/compute/api.h" +#include "arrow/compute/kernels/test_util_internal.h" +#include "arrow/testing/gtest_util.h" + +namespace arrow { + +using internal::checked_cast; + +namespace compute { +namespace { + +Result<std::shared_ptr<Array>> REEFromJSON(const std::shared_ptr<DataType>& ree_type, + const std::string& json) { + auto ree_type_ptr = checked_cast<const RunEndEncodedType*>(ree_type.get()); + auto array = ArrayFromJSON(ree_type_ptr->value_type(), json); + ARROW_ASSIGN_OR_RAISE( + auto datum, RunEndEncode(array, RunEndEncodeOptions{ree_type_ptr->run_end_type()})); + return datum.make_array(); +} + +void CheckSimpleSearchSorted(const std::shared_ptr<DataType>& type, + const std::string& values_json, + const std::string& needles_json, + const std::string& expected_left_json, + const std::string& expected_right_json) { + auto values = ArrayFromJSON(type, values_json); + auto needles = ArrayFromJSON(type, needles_json); + + ASSERT_OK_AND_ASSIGN(auto left, + SearchSorted(Datum(values), Datum(needles), + SearchSortedOptions(SearchSortedOptions::Left))); + ASSERT_OK_AND_ASSIGN(auto right, + SearchSorted(Datum(values), Datum(needles), + SearchSortedOptions(SearchSortedOptions::Right))); + + AssertArraysEqual(*ArrayFromJSON(uint64(), expected_left_json), *left.make_array()); + AssertArraysEqual(*ArrayFromJSON(uint64(), expected_right_json), *right.make_array()); +} + +void CheckSimpleScalarSearchSorted(const std::shared_ptr<DataType>& type, + const std::string& values_json, + const std::string& needle_json, uint64_t expected_left, + uint64_t expected_right) { + auto values = ArrayFromJSON(type, values_json); + auto needle = ScalarFromJSON(type, needle_json); + + ASSERT_OK_AND_ASSIGN(auto left, + SearchSorted(Datum(values), Datum(needle), + SearchSortedOptions(SearchSortedOptions::Left))); + ASSERT_OK_AND_ASSIGN(auto right, + SearchSorted(Datum(values), Datum(needle), + SearchSortedOptions(SearchSortedOptions::Right))); + + ASSERT_TRUE(left.is_scalar()); + ASSERT_TRUE(right.is_scalar()); + ASSERT_EQ(checked_cast<const UInt64Scalar&>(*left.scalar()).value, expected_left); + ASSERT_EQ(checked_cast<const UInt64Scalar&>(*right.scalar()).value, expected_right); +} + +struct SearchSortedSmokeCase { + std::string name; + std::shared_ptr<DataType> type; + std::string values_json; + std::string needles_json; + std::string expected_left_json; + std::string expected_right_json; + std::string scalar_needle_json; + uint64_t expected_scalar_left; + uint64_t expected_scalar_right; Review Comment: Ok fixed -- 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]
