Skip to content

Add product aggregate kernel to arrow-rs #10150

@devanbenz

Description

@devanbenz

Is your feature request related to a problem or challenge?

Arrow C++ has a product aggregate, arrow-rs has sum/sum_checked but no product equivalent. Add product and product_checked to arrow-arith/src/aggregate.rs, mirroring sum.

C++ (exists today)

arrow::Int64Builder b;
b.AppendValues({1, 2, 3, 4, 5});
auto arr = b.Finish().ValueOrDie();
auto out = arrow::compute::CallFunction("product", {arr});
// out.scalar() == 120

Describe the solution you'd like

/// Returns the product of values in the primitive array.
/// Returns `None` if the array is empty or all-null.
pub fn product<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native> {
    aggregate::<T::Native, T, ProdAccumulator<T::Native>>(array)
}

/// Overflow-checking variant of [`product`].
pub fn product_checked<T: ArrowNumericType>(
    array: &PrimitiveArray<T>,
) -> Result<Option<T::Native>, ArrowError> { /* mirror sum_checked/ }

Describe alternatives you've considered

Not implementing product compute kernel.

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementAny new improvement worthy of a entry in the changelog
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions