Commits


Dewey Dunnington authored and GitHub committed 19e459f2ba9
GH-27494: [R] Implement RPrimitiveConverter for Decimal type (#15211) Implements conversion from R to Decimal128/256 in such a way that it works with `Array$create()`. Before this PR: ``` r library(arrow, warn.conflicts = FALSE) #> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information. Array$create(1)$cast(decimal(10, 2)) #> Array #> <decimal128(10, 2)> #> [ #> 1.00 #> ] Array$create(1, type = decimal128(10, 2)) #> Error in `value[[3L]]()`: #> ! NotImplemented: Extend #> ℹ You might want to try casting manually with `Array$create(...)$cast(...)`. #> Backtrace: #> ▆ #> 1. └─Array$create(1, type = decimal128(10, 2)) #> 2. └─base::tryCatch(...) at r/R/array.R:198:2 #> 3. └─base (local) tryCatchList(expr, classes, parentenv, handlers) #> 4. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 5. └─value[[3L]](cond) #> 6. └─rlang::abort(...) at r/R/array.R:202:6 Array$create(1, type = decimal256(10, 2)) #> Error in `value[[3L]]()`: #> ! NotImplemented: Extend #> ℹ You might want to try casting manually with `Array$create(...)$cast(...)`. #> Backtrace: #> ▆ #> 1. └─Array$create(1, type = decimal256(10, 2)) #> 2. └─base::tryCatch(...) at r/R/array.R:198:2 #> 3. └─base (local) tryCatchList(expr, classes, parentenv, handlers) #> 4. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) #> 5. └─value[[3L]](cond) #> 6. └─rlang::abort(...) at r/R/array.R:202:6 ``` <sup>Created on 2023-01-05 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup> After this PR: ``` r library(arrow, warn.conflicts = FALSE) #> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information. Array$create(1)$cast(decimal(10, 2)) #> Array #> <decimal128(10, 2)> #> [ #> 1.00 #> ] Array$create(1, type = decimal128(10, 2)) #> Array #> <decimal128(10, 2)> #> [ #> 1.00 #> ] Array$create(1, type = decimal256(10, 2)) #> Array #> <decimal256(10, 2)> #> [ #> 1.00 #> ] ``` <sup>Created on 2023-01-05 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup> TODO: test! Lead-authored-by: Dewey Dunnington <dewey@fishandwhistle.net> Co-authored-by: Dewey Dunnington <dewey@voltrondata.com> Co-authored-by: Nic Crane <thisisnic@gmail.com> Co-authored-by: Weston Pace <weston.pace@gmail.com> Signed-off-by: Dewey Dunnington <dewey@fishandwhistle.net>