Skip to content

Commit 4095d92

Browse files
authored
GH-46825: [R] Use smallest_decimal() from C++ instead of working out which decimal type to instantiate in R (#47906)
### Rationale for this change R code duplicated code from C++ ### What changes are included in this PR? Remove duplication ### Are these changes tested? There were existing tests ### Are there any user-facing changes? Nah * GitHub Issue: #46825 Authored-by: Nic Crane <[email protected]> Signed-off-by: Nic Crane <[email protected]>
1 parent 527ddb0 commit 4095d92

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

r/R/arrowExports.R

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/R/type.R

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,7 @@ timestamp <- function(unit = c("s", "ms", "us", "ns"), timezone = "") {
604604
#' @export
605605
decimal <- function(precision, scale) {
606606
args <- check_decimal_args(precision, scale)
607-
608-
if (args$precision > 38) {
609-
decimal256(args$precision, args$scale)
610-
} else if (args$precision > 18) {
611-
decimal128(args$precision, args$scale)
612-
} else if (args$precision > 9) {
613-
decimal64(args$precision, args$scale)
614-
} else {
615-
decimal32(args$precision, args$scale)
616-
}
607+
SmallestDecimal__initialize(args$precision, args$scale)
617608
}
618609

619610
#' @rdname data-type

r/src/arrowExports.cpp

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/src/datatype.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ std::shared_ptr<arrow::DataType> Decimal256Type__initialize(int32_t precision,
213213
return ValueOrStop(arrow::Decimal256Type::Make(precision, scale));
214214
}
215215

216+
// [[arrow::export]]
217+
std::shared_ptr<arrow::DataType> SmallestDecimal__initialize(int32_t precision,
218+
int32_t scale) {
219+
return arrow::smallest_decimal(precision, scale);
220+
}
221+
216222
// [[arrow::export]]
217223
std::shared_ptr<arrow::DataType> DayTimeInterval__initialize() {
218224
return arrow::day_time_interval();

0 commit comments

Comments
 (0)