Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions cpp/src/arrow/compute/kernels/vector_sort_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
nfrmtk marked this conversation as resolved.
Outdated
};

Expand Down
24 changes: 24 additions & 0 deletions cpp/src/arrow/compute/kernels/vector_sort_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SortKey> 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()),
Expand Down