amol- commented on a change in pull request #11886:
URL: https://github.com/apache/arrow/pull/11886#discussion_r773919342



##########
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();
+        });
+  }
+};
+
+Status IndicesNonZeroExec(KernelContext* ctx, const ExecBatch& batch, Datum* 
out) {
+  std::shared_ptr<ArrayData> array = batch[0].array();
+  UInt64Builder builder;
+
+  RETURN_NOT_OK(builder.Reserve(array->length));
+  NonZeroVisitor visitor(&builder, *array.get());
+  RETURN_NOT_OK(VisitTypeInline(*(array->type), &visitor));
+
+  std::shared_ptr<ArrayData> out_data;
+  RETURN_NOT_OK(builder.FinishInternal(&out_data));
+  out->value = std::move(out_data);
+  return Status::OK();
+}
+
+std::shared_ptr<ScalarFunction> MakeIndicesNonZeroFunction(std::string name,

Review comment:
       Oh thanks for the clarification, I thought that a function could be 
considered scalar as far as it only cared about one element of the array at a 
time, I'll change this to be a `VectorFunction`




-- 
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-unsubscr...@arrow.apache.org

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


Reply via email to