pitrou commented on code in PR #13334:
URL: https://github.com/apache/arrow/pull/13334#discussion_r911033985
##########
cpp/src/arrow/compute/kernels/vector_array_sort.cc:
##########
@@ -172,6 +173,85 @@ class ArrayCompareSorter {
}
};
+template <>
+class ArrayCompareSorter<DictionaryType> {
+ struct DictionaryInternal {
+ NullPartitionResult p;
+ const std::shared_ptr<Array>& values;
+ const std::shared_ptr<Array>& indices;
+ const UInt64Array& indices_values;
+ const ArraySortOptions& options;
+ int64_t offset;
+
+ Status Visit(const DataType& index_type) {
+ return Status::TypeError("Dictionary sorting not supported for index
type ",
+ index_type.ToString());
+ }
+
+ template <typename IndexType>
+ enable_if_t<is_integer_type<IndexType>::value, Status> Visit(
+ const IndexType& index_type) {
+ return SortInternal<IndexType>();
+ }
+
+ template <typename IndexType>
+ Status SortInternal() {
+ using ArrayType = typename TypeTraits<IndexType>::ArrayType;
+ using GetView = GetViewType<IndexType>;
+ const auto& indices_array = checked_cast<const ArrayType&>(*indices);
+
+ std::vector<uint64_t> sort_order(indices_values.length());
+ uint64_t cur = 0;
+ auto cur_idx =
GetViewType<UInt64Type>::LogicalValue(indices_values.GetView(cur));
+ auto cur_val = values->GetScalar(cur_idx);
+ for (int i = 0; i < indices_values.length(); i++) {
Review Comment:
Note that we now have a Rank kernel which should make this easier, for
example in Python:
```python
>>> pc.rank(["b", None, "b", "a", None, "c"], tiebreaker="dense")
<pyarrow.lib.UInt64Array object at 0x7ff8a7378dc0>
[
2,
4,
2,
1,
4,
3
]
```
--
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]