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/12/22 13:17:39 UTC

[GitHub] [arrow] nirandaperera commented on a change in pull request #11886: ARROW-13035: [C++] indices_nonzero compute function

nirandaperera commented on a change in pull request #11886:
URL: https://github.com/apache/arrow/pull/11886#discussion_r773874500



##########
File path: cpp/src/arrow/compute/kernels/scalar_validity.cc
##########
@@ -189,6 +194,73 @@ Status ConstBoolExec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
   return Status::OK();
 }
 
+struct NonZeroVisitor {
+  UInt64Builder* builder;
+  const ArrayData& array;
+
+  NonZeroVisitor(UInt64Builder* builder, const ArrayData& array)
+      : builder(builder), array(array) {}
+
+  Status Visit(const DataType& type) { return Status::NotImplemented(type.ToString()); }
+
+  template <typename Type>
+  enable_if_t<is_primitive_ctype<Type>::value, Status> Visit(const Type&) {
+    using T = typename GetViewType<Type>::T;
+    uint32_t index = 0;
+
+    return VisitArrayDataInline<Type>(
+        this->array,
+        [&](T v) {
+          if (v) {
+            this->builder->UnsafeAppend(index);
+          }
+          ++index;
+          return Status::OK();
+        },
+        [&]() {
+          ++index;
+          return Status::OK();
+        });
+  }

Review comment:
       wouldn't it be best to use the `void` visitor here? AFAIU the hot loop checks if status is okay. But may be the compiler removes that part :thinking: Nevertheless, I think the following would be neater. 
   ```suggestion
       VisitArrayDataInline<Type>(
           this->array,
           [&](T v) {
             if (v) {
               this->builder->UnsafeAppend(index);
             }
             ++index;
           },
           [&]() {
             ++index;
           });
       return Status::OK();
     }
   ```




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