viirya commented on code in PR #3690:
URL: https://github.com/apache/arrow-rs/pull/3690#discussion_r1103859143
##########
arrow-arith/src/arithmetic.rs:
##########
@@ -1241,6 +1243,74 @@ pub fn multiply_dyn_checked(
}
}
+/// Perform `left * right` operation on two decimal arrays. If either left or
right value is
+/// null then the result is also null.
+///
+/// This performs decimal multiplication which allows precision loss if an
exact representation
+/// is not possible for the result. In the case, the result will be rounded.
+pub fn multiply_decimal(
+ left: &PrimitiveArray<Decimal128Type>,
+ right: &PrimitiveArray<Decimal128Type>,
+) -> Result<ArrayRef, ArrowError> {
+ let precision = left.precision();
+ let mut product_scale = left.scale() + right.scale();
+
+ math_checked_op(left, right, |a, b| {
Review Comment:
The result of multiplication between smaller type (i.e. `i128`) could be
overflowed but it could still be represented as i128 after we truncate it
below. If we don't perform multiplication as the larger type, I'm not sure if
we can get the (overflowed) result and truncate on it?
--
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]