[
https://issues.apache.org/jira/browse/ARROW-17601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17600769#comment-17600769
]
Neal Richardson commented on ARROW-17601:
-----------------------------------------
The trouble with the status quo is that we fail even if there is no overflow or
required digits > 38:
{code}
> one <- Array$create(1)$cast(decimal128(33, 0))
> one
Array
<decimal128(33, 0)>
[
1
]
> two <- Array$create(2)$cast(decimal128(33, 0))
> one + two
Array
<decimal128(34, 0)>
[
3
]
> one * two
Error: Invalid: Decimal precision out of range [1, 38]: 67
{code}
> [C++] Error when creating Expression on Decimal128 types: precision out of
> range
> --------------------------------------------------------------------------------
>
> Key: ARROW-17601
> URL: https://issues.apache.org/jira/browse/ARROW-17601
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++
> Reporter: Neal Richardson
> Assignee: Yibo Cai
> Priority: Major
>
> Reproducer in R:
> {code}
> library(arrow)
> library(dplyr)
> tab <- Table$create(col1 = 1:4, col2 = 5:8)
> tab <- tab$cast(schema(col1 = decimal128(33, 4), col2 = decimal128(15, 2)))
> tab %>% mutate(col1 * col2)
> # Error: Invalid: Decimal precision out of range [1, 38]: 49
> # /Users/me/arrow/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc:1078
> DecimalType::Make(left_type.id(), precision, scale)
> # /Users/me/arrow/cpp/src/arrow/compute/exec/expression.cc:413
> call.kernel->signature->out_type().Resolve(&kernel_context, types)
> {code}
> We don't have this problem integers and floats (see comment below). For
> consistency with the other arithmetic functions, what I would expect would be
> that we would expand the precision as much as we could within Decimal128–in
> this case, Decimal128(38, 6)–and the compute function would either error _if_
> there is an overflow (in the _checked version) or just overflow in the
> non-checked version. But it wouldn't error on determining the output type.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)