amol- commented on a change in pull request #11886: URL: https://github.com/apache/arrow/pull/11886#discussion_r773051867
########## File path: cpp/src/arrow/compute/kernels/scalar_validity.cc ########## @@ -189,6 +191,72 @@ Status ConstBoolExec(KernelContext* ctx, const ExecBatch& batch, Datum* out) { return Status::OK(); } +struct NonZeroVisitor { + UInt32Builder *builder; + const ArrayData& array; + + NonZeroVisitor(UInt32Builder *builder, const ArrayData& array) + : builder(builder), array(array) {} + + Status Visit(const DataType& type) { + return Status::TypeError("Unsupported type for nonzero: ", type.ToString()); + } + + template <typename Type> + enable_if_t<has_c_type<Type>::value && + !std::is_same<Type, MonthDayNanoIntervalType>::value && + !std::is_same<Type, DayTimeIntervalType>::value, + Status> + Visit(const Type&) { + using T = typename GetViewType<Type>::T; + uint32_t index = 0; + + return VisitArrayDataInline<Type>( + this->array, + [&](T v) { + if(v != 0) { + RETURN_NOT_OK(this->builder->Reserve(1)); + this->builder->UnsafeAppend(index); + } + ++index; + return Status::OK(); + }, + [&]() { + ++index; + return Status::OK(); + }); + } +}; + +Status NonZeroExec(KernelContext* ctx, const ExecBatch& batch, Datum* out) { + std::shared_ptr<ArrayData> array = batch[0].array(); + UInt32Builder builder; Review comment: Given that we always only return indices of an array, what's the purpose of generalising it? Shouldn't the result always be uint64? I can see there might be a will to make it return Uint8/16/32 for smaller arrays, but that seems a premature optimization. -- 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