[ https://issues.apache.org/jira/browse/ARROW-15159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
David Li updated ARROW-15159: ----------------------------- Labels: good-first-issue kernel (was: ) > [C++] Cast from integer to decimal to check the required precision > ------------------------------------------------------------------ > > Key: ARROW-15159 > URL: https://issues.apache.org/jira/browse/ARROW-15159 > Project: Apache Arrow > Issue Type: Improvement > Components: C++ > Reporter: Dragoș Moldovan-Grünfeld > Priority: Major > Labels: good-first-issue, kernel > > Casting from integer to decimal currently requires a precision of at least 12 > (I think that might be the maximum precision required to represent any > {{{}int32{}}}), irrespective of the actual values requiring casting. > An example of how this surfaces in R: > {code:r} > library(arrow) > a <- as.double(1:10) > b <- 1:10 > typeof(a) > #> [1] "double" > typeof(b) > #> [1] "integer" > Array$create(a)$cast(decimal(4, 2)) > #> Array > #> <decimal128(4, 2)> > #> [ > #> 1.00, > #> 2.00, > #> 3.00, > #> 4.00, > #> 5.00, > #> 6.00, > #> 7.00, > #> 8.00, > #> 9.00, > #> 10.00 > #> ] > # a precision of 4 should be more than enough for this example > Array$create(b)$cast(decimal(4, 2)) > #> Error: Invalid: Precision is not great enough for the result. It should be > at least 12 > {code} > Float to decimal casting checks each value instead of upfront. [See > here|https://github.com/apache/arrow/blob/f473cb908f4b25e3d5e4343af5c4b567751c0995/cpp/src/arrow/compute/kernels/scalar_cast_numeric.cc#L546-L578]. -- This message was sent by Atlassian Jira (v8.20.1#820001)