Taepper commented on code in PR #46926:
URL: https://github.com/apache/arrow/pull/46926#discussion_r3404501295


##########
cpp/src/arrow/compute/kernels/vector_select_k.cc:
##########
@@ -205,19 +339,38 @@ class ChunkedArraySelector : public TypeVisitor {
     if (k_ > chunked_array_.length()) {
       k_ = chunked_array_.length();
     }
+
+    ARROW_ASSIGN_OR_RAISE(auto take_indices,
+                          MakeMutableUInt64Array(k_, ctx_->memory_pool()));
+    auto* output_begin = take_indices->GetMutableValues<uint64_t>(1);
+
+    int64_t null_count = chunked_array_.null_count();
+    int64_t nan_count = ComputeNanCount<InType>();
+    int64_t non_null_like_count = chunked_array_.length() - null_count - 
nan_count;
+
+    auto output = CalculateOutputRangesByNullLikeness(non_null_like_count, 
nan_count,
+                                                      null_count, 
null_placement_,
+                                                      {output_begin, 
output_begin + k_});
+
+    // Now we can independently fill the output with non_null, nan and null 
items.
+    // For non_null, we do a heap_sort, the others can just be copied until
+    // nan_taken == output.nan_range.size() and
+    // null_taken == output.null_range.size() respectively
+    size_t nan_taken = 0;
+    size_t null_taken = 0;

Review Comment:
   I see your point for consistency, but they are only used in one single code 
section:
   
   ```
         for (; iter != p.null_range.end() && null_taken < 
output.null_range.size();
              ++iter) {
           output.null_range[null_taken] = offset + *iter;
           null_taken++;
         }
   ```
   
   and this would introduce a required `static_cast`, which makes this choice a 
little questionable



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