felipecrv commented on code in PR #35750:
URL: https://github.com/apache/arrow/pull/35750#discussion_r1218600095


##########
cpp/src/arrow/compute/kernels/vector_selection_filter_internal.cc:
##########
@@ -161,39 +173,88 @@ class PrimitiveFilterImpl {
       out_is_valid_ = out_arr->buffers[0]->mutable_data();
     }
     out_data_ = reinterpret_cast<T*>(out_arr->buffers[1]->mutable_data());
-    out_offset_ = out_arr->offset;
     out_length_ = out_arr->length;
+    DCHECK_EQ(out_arr->offset, 0);
     out_position_ = 0;
   }
 
-  void ExecNonNull() {
-    // Fast filter when values and filter are not null
-    ::arrow::internal::VisitSetBitRunsVoid(
-        filter_data_, filter_offset_, values_length_,
-        [&](int64_t position, int64_t length) { WriteValueSegment(position, 
length); });
+  void ExecREEFilter() {
+    if (filter_.child_data[1].null_count == 0 && values_null_count_ == 0) {
+      DCHECK(!out_is_valid_);
+      // Fastest: no nulls in either filter or values
+      return VisitPlainxREEFilterOutputSegments(
+          filter_, /*filter_may_have_nulls=*/false, null_selection_,
+          [&](int64_t position, int64_t segment_length, bool filter_valid) {
+            // Fastest path: all values in range are included and not null
+            WriteValueSegment(position, segment_length);
+            DCHECK(filter_valid);
+          });
+    }
+    if (values_is_valid_ && out_is_valid_) {
+      // Fast path: values can be null, so the validity bitmap should be copied

Review Comment:
   Changing to
   
   ```diff
              });
        }
        if (values_is_valid_ && out_is_valid_) {
   -      // Fast path: values can be null, so the validity bitmap should be 
copied
   +      // Slower path: values can be null, so the validity bitmap should be 
copied
          return VisitPlainxREEFilterOutputSegments(
              filter_, /*filter_may_have_nulls=*/true, null_selection_,
              [&](int64_t position, int64_t segment_length, bool filter_valid) {
   @@ -206,6 +206,8 @@ class PrimitiveFilterImpl {
                }
              });
        }
   +    // Faster path: only write to out_is_valid_ if filter contains nulls and
   +    // null_selection is EMIT_NULL
        if (out_is_valid_) {
          // Set all to valid, so only if nulls are produced by EMIT_NULL, we 
need
          // to set out_is_valid[i] to false.
     ```



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