From f12c35d1cf62e8d329304f7ef274c34b6941a8e8 Mon Sep 17 00:00:00 2001 From: Hyukjin Kwon Date: Fri, 23 Jan 2026 08:42:09 +0900 Subject: [PATCH 1/2] Remove an obsolete todo --- .../compute/kernels/vector_array_sort.cc | 1 - .../arrow/compute/kernels/vector_sort_test.cc | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/kernels/vector_array_sort.cc b/cpp/src/arrow/compute/kernels/vector_array_sort.cc index 950de47733b..664703d8f7c 100644 --- a/cpp/src/arrow/compute/kernels/vector_array_sort.cc +++ b/cpp/src/arrow/compute/kernels/vector_array_sort.cc @@ -237,7 +237,6 @@ class ArrayCompareSorter { RankOptions rank_options(SortOrder::Ascending, NullPlacement::AtEnd, RankOptions::Dense); - // XXX Should this support Type::NA? auto data = array->data(); std::shared_ptr null_bitmap; if (array->null_count() > 0) { diff --git a/cpp/src/arrow/compute/kernels/vector_sort_test.cc b/cpp/src/arrow/compute/kernels/vector_sort_test.cc index 90f8eb7a56b..7563f9039fa 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort_test.cc @@ -437,6 +437,27 @@ TEST(ArraySortIndicesFunction, AllNullDictionaryArray) { } } +TEST(ArraySortIndicesFunction, NullTypeDictionaryArray) { + // Test that dictionaries with Type::NA (null type) values can be sorted. + // All values in a null-type dictionary are logically null, so sorting + // should just arrange indices based on null placement, preserving order. + for (const auto& index_type : all_dictionary_index_types()) { + ARROW_SCOPED_TRACE("index_type = ", index_type->ToString()); + auto dict_type = dictionary(index_type, null()); + auto dict_arr = DictArrayFromJSON(dict_type, "[null, null, null, null]", "[]"); + + for (auto null_placement : AllNullPlacements()) { + ArraySortOptions options{SortOrder::Ascending, null_placement}; + // All nulls, so output should be identity permutation + auto expected = ArrayFromJSON(uint64(), "[0, 1, 2, 3]"); + ASSERT_OK_AND_ASSIGN(auto actual, + CallFunction("array_sort_indices", {dict_arr}, &options)); + ValidateOutput(actual); + AssertDatumsEqual(expected, actual, /*verbose=*/true); + } + } +} + Result> DecodeDictionary(const Array& array) { const auto& dict_array = checked_cast(array); ARROW_ASSIGN_OR_RAISE(auto decoded_datum, From 192e799bfb15bed2b4f8b4164ee56fbf7bb01ad5 Mon Sep 17 00:00:00 2001 From: Hyukjin Kwon Date: Wed, 4 Feb 2026 08:23:53 +0900 Subject: [PATCH 2/2] review comment --- cpp/src/arrow/compute/kernels/vector_sort_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/kernels/vector_sort_test.cc b/cpp/src/arrow/compute/kernels/vector_sort_test.cc index 7563f9039fa..e18fcf37716 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort_test.cc @@ -444,7 +444,7 @@ TEST(ArraySortIndicesFunction, NullTypeDictionaryArray) { for (const auto& index_type : all_dictionary_index_types()) { ARROW_SCOPED_TRACE("index_type = ", index_type->ToString()); auto dict_type = dictionary(index_type, null()); - auto dict_arr = DictArrayFromJSON(dict_type, "[null, null, null, null]", "[]"); + auto dict_arr = DictArrayFromJSON(dict_type, "[null, 0, 0, null]", "[null]"); for (auto null_placement : AllNullPlacements()) { ArraySortOptions options{SortOrder::Ascending, null_placement};