Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cpp/src/arrow/compute/kernels/vector_search_sorted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ const FunctionDoc search_sorted_doc(
VISIT(DoubleType) \
VISIT(BinaryType) \
VISIT(LargeBinaryType) \
VISIT(BinaryViewType)
VISIT(BinaryViewType) \
VISIT(FixedSizeBinaryType) \
VISIT(Decimal32Type) \
VISIT(Decimal64Type) \
VISIT(Decimal128Type) \
VISIT(Decimal256Type)

template <typename ArrowType>
using SearchValue = typename GetViewType<ArrowType>::T;
Expand Down Expand Up @@ -568,8 +573,13 @@ Status VisitArrayNeedleRuns(const std::shared_ptr<ArrayData>& needles_data,
Visitor&& visitor) {
using ArrayType = typename TypeTraits<ArrowType>::ArrayType;

auto physical_type = TypeTraits<ArrowType>::type_singleton();
auto physical_data = ToPhysicalData(needles_data, physical_type);
std::shared_ptr<ArrayData> physical_data;
if constexpr (TypeTraits<ArrowType>::is_parameter_free) {
physical_data = ToPhysicalData(needles_data, TypeTraits<ArrowType>::type_singleton());
} else {
// Parametric types (decimals, fixed_size_binary) are their own physical type
physical_data = needles_data;
}
ArrayType array(physical_data);
for (int64_t index = 0; index < array.length(); ++index) {
RETURN_NOT_OK(visitor(ReadVisitedNeedle<ArrowType>(array, index)));
Expand Down Expand Up @@ -706,8 +716,7 @@ Result<Datum> ComputeInsertionIndices(const Datum& sorted_values, const Datum& n
SearchSortedOptions::Side side,
NullPlacement null_placement,
uint64_t insertion_offset, ExecContext* ctx) {
auto physical_type = TypeTraits<ArrowType>::type_singleton();
DCHECK_NE(physical_type->id(), Type::RUN_END_ENCODED);
static_assert(ArrowType::type_id != Type::RUN_END_ENCODED);

if (sorted_values.type()->id() == Type::RUN_END_ENCODED) {
return ComputeInsertionIndicesWithAccessor<ArrowType,
Expand Down
19 changes: 19 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_search_sorted_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ std::vector<SearchSortedSmokeCase> SupportedTypeSmokeCases() {
R"(["a", "c", "bb", "z"])", "[0, 3, 1, 5]", "[0, 3, 3, 5]"},
{"StringView", utf8_view(), R"(["aa", "bb", "bb", "dd", "ff"])",
R"(["a", "c", "bb", "z"])", "[0, 3, 1, 5]", "[0, 3, 3, 5]"},
{"FixedSizeBinary", fixed_size_binary(2), R"(["aa", "bb", "bb", "dd", "ff"])",
R"(["ab", "cc", "bb", "zz"])", "[1, 3, 1, 5]", "[1, 3, 3, 5]"},
{"Decimal32", decimal32(5, 2), R"(["-12.50", "-1.00", "-1.00", "0.00", "3.25"])",
R"(["-20.00", "-1.00", "1.00", "5.00"])", "[0, 1, 4, 5]", "[0, 3, 4, 5]"},
{"Decimal64", decimal64(10, 2), R"(["-12.50", "-1.00", "-1.00", "0.00", "3.25"])",
R"(["-20.00", "-1.00", "1.00", "5.00"])", "[0, 1, 4, 5]", "[0, 3, 4, 5]"},
{"Decimal128", decimal128(20, 2), R"(["-12.50", "-1.00", "-1.00", "0.00", "3.25"])",
R"(["-20.00", "-1.00", "1.00", "5.00"])", "[0, 1, 4, 5]", "[0, 3, 4, 5]"},
{"Decimal256", decimal256(40, 2), R"(["-12.50", "-1.00", "-1.00", "0.00", "3.25"])",
R"(["-20.00", "-1.00", "1.00", "5.00"])", "[0, 1, 4, 5]", "[0, 3, 4, 5]"},
};
}

Expand Down Expand Up @@ -540,6 +550,15 @@ TEST(SearchSorted, RunEndEncodedDate32Values) {
CheckSearchSorted(Datum(values), Datum(needles), "[2]", "[2]");
}

TEST(SearchSorted, RunEndEncodedDecimalValues) {
auto values_type = run_end_encoded(int16(), decimal128(10, 2));
ASSERT_OK_AND_ASSIGN(auto values,
REEFromJSON(values_type, R"([null, "-1.00", "-1.00", "2.50"])"));
auto needles = ArrayFromJSON(decimal128(10, 2), R"(["-1.00", "0.00", null])");

CheckSearchSorted(Datum(values), Datum(needles), "[1, 3, null]", "[3, 3, null]");
}

TEST(SearchSorted, RunEndEncodedNulls) {
auto values_type = run_end_encoded(int16(), int32());
ASSERT_OK_AND_ASSIGN(auto ree_values,
Expand Down
Loading