lidavidm commented on a change in pull request #10486:
URL: https://github.com/apache/arrow/pull/10486#discussion_r759257517
##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic.cc
##########
@@ -929,6 +929,7 @@ void RegisterScalarAggregateBasic(FunctionRegistry*
registry) {
AddArrayScalarAggKernels(SumInit, SignedIntTypes(), int64(), func.get());
AddArrayScalarAggKernels(SumInit, UnsignedIntTypes(), uint64(), func.get());
AddArrayScalarAggKernels(SumInit, FloatingPointTypes(), float64(),
func.get());
+ AddArrayScalarAggKernels(SumInit, {null()}, null(), func.get());
Review comment:
If we're returning int64 below, this should be declared to return int64.
##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic.cc
##########
@@ -929,6 +929,7 @@ void RegisterScalarAggregateBasic(FunctionRegistry*
registry) {
AddArrayScalarAggKernels(SumInit, SignedIntTypes(), int64(), func.get());
AddArrayScalarAggKernels(SumInit, UnsignedIntTypes(), uint64(), func.get());
AddArrayScalarAggKernels(SumInit, FloatingPointTypes(), float64(),
func.get());
+ AddArrayScalarAggKernels(SumInit, {null()}, null(), func.get());
Review comment:
```suggestion
AddArrayScalarAggKernels(SumInit, {null()}, int64(), func.get());
```
##########
File path: cpp/src/arrow/compute/exec.cc
##########
@@ -961,6 +961,14 @@ class ScalarAggExecutor : public
KernelExecutorImpl<ScalarAggregateKernel> {
return outputs[0];
}
+ Status CheckResultType(const Datum& out, const char* function_name) override
{
+ if (strcmp(function_name, "sum") == 0 &&
output_descr_.type->Equals(null())) {
+ // Skip CheckResultType for sum of null type, as it may return various
types
+ return Status::OK();
+ }
+ return KernelExecutorImpl::CheckResultType(out, function_name);
+ }
Review comment:
Let's not do this. Below we should return a null scalar of the right
type, not a null scalar of the null type.
##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic_internal.h
##########
@@ -121,6 +121,37 @@ struct SumImpl : public ScalarAggregator {
ScalarAggregateOptions options;
};
+struct NullSumImpl : public ScalarAggregator {
+ explicit NullSumImpl(const ScalarAggregateOptions& options_) :
options(options_) {}
+
+ Status Consume(KernelContext*, const ExecBatch& batch) override {
+ if (batch[0].is_scalar() || batch[0].array()->GetNullCount() > 0) {
+ // If the batch is a scalar or an array with elements, set is_empty to
false
+ is_empty = false;
+ }
+ return Status::OK();
+ }
+
+ Status MergeFrom(KernelContext*, KernelState&& src) override {
+ const auto& other = checked_cast<const NullSumImpl&>(src);
+ this->is_empty &= other.is_empty;
+ return Status::OK();
+ }
+
+ Status Finalize(KernelContext*, Datum* out) override {
+ if ((options.skip_nulls || this->is_empty) && options.min_count == 0) {
+ // Return 0 if the remaining data is empty
+ out->value = std::make_shared<Int64Scalar>(0);
+ } else {
+ out->value = MakeNullScalar(null());
Review comment:
```suggestion
out->value = MakeNullScalar(int64());
```
--
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]