edponce commented on a change in pull request #10113:
URL: https://github.com/apache/arrow/pull/10113#discussion_r617798895
##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -369,12 +420,37 @@ std::shared_ptr<ScalarFunction>
MakeArithmeticFunctionNotNull(std::string name,
const
FunctionDoc* doc) {
auto func = std::make_shared<ArithmeticFunction>(name, Arity::Binary(), doc);
for (const auto& ty : NumericTypes()) {
- auto exec = NumericEqualTypesBinary<ScalarBinaryNotNullEqualTypes, Op>(ty);
+ auto exec = ArithmeticExecFromOp<ScalarBinaryNotNullEqualTypes, Op>(ty);
DCHECK_OK(func->AddKernel({ty, ty}, ty, exec));
}
return func;
}
+template <typename Op>
+std::shared_ptr<ScalarFunction> MakeUnaryArithmeticFunction(std::string name,
+ const FunctionDoc*
doc) {
+ auto func = std::make_shared<ArithmeticFunction>(name, Arity::Unary(), doc);
+ for (const auto& ty : NumericTypes()) {
+ auto exec = ArithmeticExecFromOp<ScalarUnary, Op>(ty);
+ DCHECK_OK(func->AddKernel({ty}, ty, exec));
+ }
+ return func;
+}
+
+// Like MakeUnaryArithmeticFunction, but for signed arithmetic ops that need
to run
+// only on non-null output.
+template <typename Op>
+std::shared_ptr<ScalarFunction>
MakeUnaryCheckedSignedArithmeticFunctionNotNull(
+ std::string name, const FunctionDoc* doc) {
+ auto func = std::make_shared<ArithmeticFunction>(name, Arity::Unary(), doc);
+ for (const auto& ty :
arrow::internal::FlattenVectors<std::shared_ptr<arrow::DataType>>(
+ {SignedIntTypes(), FloatingPointTypes()})) {
Review comment:
To make this generator more general, I suggest to remove "Checked" from
its name and to not include the "negate_checked" comment:
```
std::shared_ptr<ScalarFunction>
MakeUnarySignedArithmeticFunctionNotNull(...) {
auto func = ...
for (const auto& ty : NumericTypes()) {
if (!is_unsigned_integer(ty->id())) {
auto exec = ...
...
}
}
return func;
}
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]