edponce commented on a change in pull request #11886:
URL: https://github.com/apache/arrow/pull/11886#discussion_r764311223
##########
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());
Review comment:
[Use `Status::NotImplemented` as in the default
TypeVisitors.](https://github.com/edponce/arrow/blob/master/cpp/src/arrow/visitor.cc#L81)
##########
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);
Review comment:
[Use
`builder->Append(index)`](https://github.com/edponce/arrow/blob/master/cpp/src/arrow/array/builder_primitive.h#L88)
##########
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) {
Review comment:
Since `T` can be `bool` (besides integers and floating-point), maybe
using `if (v) { ... }` is a more general expression.
##########
File path: cpp/src/arrow/compute/kernels/scalar_validity.cc
##########
@@ -17,6 +17,8 @@
#include <cmath>
+#include "arrow/array/builder_primitive.h"
+
Review comment:
Missing C++ header files:
* `#include <cstdint>` - xxx_t C types
* `#include <types>` - std::is_same
* `#include <memory>` - std::shared_ptr
##########
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,
Review comment:
I think what you need here is
[`enable_if_primitive_ctype`](https://github.com/edponce/arrow/blob/master/cpp/src/arrow/type_traits.h#L740).
Primitive C type includes: boolean, integers, and floating-point numbers.
--
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]