ArianaVillegas commented on code in PR #13334:
URL: https://github.com/apache/arrow/pull/13334#discussion_r919042403


##########
cpp/src/arrow/compute/kernels/vector_array_sort.cc:
##########
@@ -173,6 +175,78 @@ class ArrayCompareSorter {
   }
 };
 
+template <>
+class ArrayCompareSorter<DictionaryType> {
+  struct DictionaryInternal {
+    NullPartitionResult* p;
+    const std::shared_ptr<Array>& values;
+    const std::shared_ptr<Array>& indices;
+    const UInt64Array& values_rank;
+    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::stable_sort(this->p->non_nulls_begin, this->p->non_nulls_end,
+                       [&](uint64_t left, uint64_t right) {
+                         const auto lhs_idx =
+                             GetView::LogicalValue(indices_array.GetView(left 
- offset));
+                         const auto rhs_idx =
+                             GetView::LogicalValue(indices_array.GetView(right 
- offset));
+                         const auto lhs = 
GetViewType<UInt64Type>::LogicalValue(
+                             values_rank.GetView(lhs_idx - offset));
+                         const auto rhs = 
GetViewType<UInt64Type>::LogicalValue(
+                             values_rank.GetView(rhs_idx - offset));
+                         return lhs < rhs;
+                       });
+
+      return Status::OK();
+    }
+
+    Status Make(const std::shared_ptr<DataType>& index_type) {
+      return VisitTypeInline(*index_type, this);

Review Comment:
   Indeed, that sounds like a good idea. I'll go for it



-- 
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]

Reply via email to