cyb70289 commented on a change in pull request #10931:
URL: https://github.com/apache/arrow/pull/10931#discussion_r690866806
##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic.cc
##########
@@ -187,31 +188,32 @@ struct ProductImpl : public ScalarAggregator {
const auto& other = checked_cast<const ThisType&>(src);
this->count += other.count;
this->product =
- static_cast<ProductType>(to_unsigned(this->product) *
to_unsigned(other.product));
+ MultiplyTraits<AccType>::Multiply(*out_type, this->product,
other.product);
return Status::OK();
}
Status Finalize(KernelContext*, Datum* out) override {
if (this->count < options.min_count) {
- out->value = std::make_shared<OutputType>();
+ out->value = std::make_shared<OutputType>(out_type);
} else {
- out->value = MakeScalar(this->product);
+ out->value = std::make_shared<OutputType>(this->product, out_type);
}
return Status::OK();
}
- size_t count = 0;
- typename AccType::c_type product = 1;
+ std::shared_ptr<DataType> out_type;
Review comment:
Nit: const reference?
##########
File path: cpp/src/arrow/compute/kernels/aggregate_test.cc
##########
@@ -556,6 +641,98 @@ TYPED_TEST(TestNumericProductKernel,
ScalarAggregateOptions) {
ResultWith(null_result));
}
+TEST(TestDecimalProductKernel, SimpleProduct) {
+ for (const auto& ty : {decimal128(3, 2), decimal256(3, 2)}) {
+ Datum null = ScalarFromJSON(ty, R"(null)");
+
+ EXPECT_THAT(Product(ArrayFromJSON(ty, R"([])")), ResultWith(null));
+ EXPECT_THAT(Product(ArrayFromJSON(ty, R"([null])")), ResultWith(null));
+ EXPECT_THAT(
+ Product(ArrayFromJSON(ty, R"(["0.00", "1.00", "2.00", "3.00", "4.00",
"5.00"])")),
+ ResultWith(ScalarFromJSON(ty, R"("0.00")")));
+ Datum chunks =
+ ChunkedArrayFromJSON(ty, {R"(["1.00", "2.00", "3.00", "4.00",
"5.00"])"});
Review comment:
Nit: add some negative values?
--
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]