kou commented on a change in pull request #8612:
URL: https://github.com/apache/arrow/pull/8612#discussion_r526612977



##########
File path: cpp/src/arrow/compute/kernels/vector_sort.cc
##########
@@ -346,14 +374,396 @@ void AddSortingKernels(VectorKernel base, 
VectorFunction* func) {
   }
 }
 
+class TableSorter : public TypeVisitor {
+ private:
+  struct ResolvedSortKey {
+    ResolvedSortKey(const ChunkedArray& chunked_array, const SortOrder order)
+        : order(order) {
+      type = chunked_array.type().get();
+      null_count = chunked_array.null_count();
+      num_chunks = chunked_array.num_chunks();
+      for (const auto& chunk : chunked_array.chunks()) {
+        chunks.push_back(chunk.get());
+      }
+    }
+
+    template <typename ArrayType>
+    ArrayType* ResolveChunk(int64_t index, int64_t& chunk_index) const {
+      if (num_chunks == 1) {
+        chunk_index = index;
+        return static_cast<ArrayType*>(chunks[0]);
+      } else {
+        int64_t offset = 0;
+        for (size_t i = 0; i < num_chunks; ++i) {
+          if (index < offset + chunks[i]->length()) {
+            chunk_index = index - offset;
+            return static_cast<ArrayType*>(chunks[i]);
+          }
+          offset += chunks[i]->length();
+        }
+        return nullptr;
+      }
+    }
+
+    SortOrder order;
+    DataType* type;
+    int64_t null_count;
+    size_t num_chunks;
+    std::vector<Array*> chunks;
+  };
+
+  class Comparer : public TypeVisitor {
+   public:
+    Comparer(const Table& table, const std::vector<SortKey>& sort_keys)
+        : TypeVisitor(), status_(Status::OK()) {
+      for (const auto& sort_key : sort_keys) {
+        const auto& chunked_array = table.GetColumnByName(sort_key.name);
+        if (!chunked_array) {
+          status_ = Status::Invalid("Nonexistent sort key column: ", 
sort_key.name);
+          return;
+        }
+        sort_keys_.emplace_back(*chunked_array, sort_key.order);
+      }
+    }
+
+    Status status() { return status_; }
+
+    const std::vector<ResolvedSortKey>& sort_keys() { return sort_keys_; }
+
+    bool Compare(uint64_t left, uint64_t right, size_t start_sort_key_index) {

Review comment:
       Added.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to