You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/05 15:33:48 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #10585: ARROW-12016 [C++] Implement array_sort_indices and sort_indices for BOOL type

pitrou commented on a change in pull request #10585:
URL: https://github.com/apache/arrow/pull/10585#discussion_r663999228



##########
File path: cpp/src/arrow/compute/kernels/vector_sort.cc
##########
@@ -477,6 +491,87 @@ class ArrayCountSorter {
   }
 };
 
+using ::arrow::internal::Bitmap;
+
+template <>
+class ArrayCountSorter<BooleanType> {
+ public:
+  ArrayCountSorter() = default;
+
+  // Returns where null starts.
+  uint64_t* Sort(uint64_t* indices_begin, uint64_t* indices_end,
+                 const BooleanArray& values, int64_t offset,
+                 const ArraySortOptions& options) {
+    // 32bit counter performs much better than 64bit one

Review comment:
       This sounds rather weird. Are you sure about this?

##########
File path: cpp/src/arrow/compute/kernels/vector_sort.cc
##########
@@ -477,6 +491,87 @@ class ArrayCountSorter {
   }
 };
 
+using ::arrow::internal::Bitmap;
+
+template <>
+class ArrayCountSorter<BooleanType> {
+ public:
+  ArrayCountSorter() = default;
+
+  // Returns where null starts.
+  uint64_t* Sort(uint64_t* indices_begin, uint64_t* indices_end,
+                 const BooleanArray& values, int64_t offset,
+                 const ArraySortOptions& options) {
+    // 32bit counter performs much better than 64bit one
+    if (values.length() < (1LL << 32)) {
+      return SortInternal<uint32_t>(indices_begin, indices_end, values, offset, options);
+    } else {
+      return SortInternal<uint64_t>(indices_begin, indices_end, values, offset, options);
+    }
+  }
+
+ private:
+  template <typename CounterType>
+  void CountBits(const BooleanArray& values, int64_t offset, CounterType* set_count,
+                 CounterType* null_count) {

Review comment:
       Really, you needn't write this yourself. Just call `null_count()` and `true_count()`.

##########
File path: cpp/src/arrow/compute/kernels/vector_sort_test.cc
##########
@@ -980,6 +1056,68 @@ TEST_F(TestTableSortIndices, NaNAndNull) {
   AssertSortIndices(table, options, "[7, 1, 2, 6, 5, 4, 0, 3]");
 }
 
+TEST_F(TestTableSortIndices, Boolean) {

Review comment:
       Same here.

##########
File path: cpp/src/arrow/compute/kernels/vector_sort_test.cc
##########
@@ -842,6 +877,47 @@ TEST_F(TestRecordBatchSortIndices, NaNAndNull) {
   AssertSortIndices(batch, options, "[7, 1, 2, 6, 5, 4, 0, 3]");
 }
 
+TEST_F(TestRecordBatchSortIndices, Boolean) {

Review comment:
       I don't think it's worth testing the non-null case separately. This will make less test code to maintain.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org