Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-15159

[C++] Cast from integer to decimal to check the required precision

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • C++

    Description

      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:

      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
      

      Float to decimal casting checks each value instead of upfront. See here.

      Attachments

        Activity

          People

            quanghgx Quang Hoang
            dragosmg Dragoș Moldovan-Grünfeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: