You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Dragoș Moldovan-Grünfeld (Jira)" <ji...@apache.org> on 2021/12/20 13:28:00 UTC

[jira] [Created] (ARROW-15159) [C++] Improve cast from integer to decimal

Dragoș Moldovan-Grünfeld created ARROW-15159:
------------------------------------------------

             Summary: [C++] Improve cast from integer to decimal
                 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


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
#> ]
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)