From fdc15ca7b451fc60123a95e41bcf4d022e645fd7 Mon Sep 17 00:00:00 2001 From: Ivan Lykov Date: Fri, 26 Jun 2026 17:33:55 +0300 Subject: [PATCH 1/2] fix --- .../compute/kernels/vector_sort_internal.h | 5 ++-- .../arrow/compute/kernels/vector_sort_test.cc | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/vector_sort_internal.h b/cpp/src/arrow/compute/kernels/vector_sort_internal.h index 06d911b2c0c8..15c06577e23a 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_internal.h +++ b/cpp/src/arrow/compute/kernels/vector_sort_internal.h @@ -780,14 +780,15 @@ struct ResolvedTableSortKey { // so we can't simply access the column from the table directly. ArrayVector chunks; chunks.reserve(batches.size()); + auto physical_type = GetPhysicalType(f.type->GetSharedPtr()); int64_t null_count = 0; for (const auto& batch : batches) { ARROW_ASSIGN_OR_RAISE(auto child, f.path.GetFlattened(*batch)); null_count += child->null_count(); - chunks.push_back(std::move(child)); + chunks.push_back(GetPhysicalArray(*child, physical_type)); } - return ResolvedTableSortKey(f.type->GetSharedPtr(), std::move(chunks), f.order, + return ResolvedTableSortKey(std::move(physical_type), std::move(chunks), f.order, f.null_placement, null_count); }; diff --git a/cpp/src/arrow/compute/kernels/vector_sort_test.cc b/cpp/src/arrow/compute/kernels/vector_sort_test.cc index 40bd09362031..e0594e536658 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_test.cc +++ b/cpp/src/arrow/compute/kernels/vector_sort_test.cc @@ -1739,6 +1739,30 @@ TEST_F(TestTableSortIndices, Decimal) { AssertSortIndices(table, options, "[3, 4, 0, 2, 1]"); } +TEST_F(TestTableSortIndices, Timestamp) { + auto schema = ::arrow::schema({ + {field("a", timestamp(TimeUnit::MICRO))}, + {field("b", timestamp(TimeUnit::MICRO))}, + }); + std::vector sort_keys{SortKey("a", SortOrder::Ascending), + SortKey("b", SortOrder::Descending)}; + + auto table = TableFromJSON(schema, {R"([{"a": 1, "b": 2}, + {"a": 3, "b": 4}, + {"a": 8, "b": 6} + ])", + R"([{"a": 6, "b": null}, + {"a": 6, "b": 7} + ])"}); + SortOptions options(sort_keys); + AssertSortIndices(table, options, "[0, 1, 4, 3, 2]"); + options.sort_keys[0].null_placement = NullPlacement::AtStart; + AssertSortIndices(table, options, "[0, 1, 4, 3, 2]"); + options.sort_keys[1].null_placement = NullPlacement::AtStart; + AssertSortIndices(table, options, "[0, 1, 3, 4, 2]"); + +} + TEST_F(TestTableSortIndices, NullType) { auto schema = arrow::schema({ field("a", null()), From 8dfccc090e7992500fd9ed861487c466c52e76b7 Mon Sep 17 00:00:00 2001 From: nfrmtk Date: Fri, 26 Jun 2026 18:34:47 +0300 Subject: [PATCH 2/2] fix Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- cpp/src/arrow/compute/kernels/vector_sort_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/kernels/vector_sort_internal.h b/cpp/src/arrow/compute/kernels/vector_sort_internal.h index 15c06577e23a..9d2ad650f1e1 100644 --- a/cpp/src/arrow/compute/kernels/vector_sort_internal.h +++ b/cpp/src/arrow/compute/kernels/vector_sort_internal.h @@ -788,7 +788,7 @@ struct ResolvedTableSortKey { chunks.push_back(GetPhysicalArray(*child, physical_type)); } - return ResolvedTableSortKey(std::move(physical_type), std::move(chunks), f.order, + return ResolvedTableSortKey(physical_type, std::move(chunks), f.order, f.null_placement, null_count); };