-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-14844 [R] Implement decimal256()
#11805
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in addition: dragosmg#1
@@ -387,6 +389,22 @@ decimal <- function(precision, scale) { | |||
Decimal128Type__initialize(precision, scale) | |||
} | |||
|
|||
#' @rdname data-type | |||
#' @export | |||
decimal256 <- function(precision, scale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps decimal()
and decimal256
could call the same function for argument checking, e.g.
check_decimal_args <- function(precision, scale) {
precision <- vec_cast(precision, to = integer())
vec_assert(precision, size = 1L)
scale <- vec_cast(scale, to = integer())
vec_assert(scale, size = 1L)
list(precision = precision, scale = scale)
}
#' @rdname data-type
#' @export
decimal <- function(precision, scale) {
args <- check_decimal_args(precision, scale)
Decimal128Type__initialize(args$precision, args$scale)
}
#' @rdname data-type
#' @export
decimal256 <- function(precision, scale) {
args <- check_decimal_args(precision, scale)
Decimal256Type__initialize(args$precision, args$scale)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! I will implement it.
As with library(arrow, warn.conflicts = FALSE)
#> See arrow_info() for available features
Array$create(c(1, 2), type = decimal(4, 3))
#> Error: NotImplemented: Extend Created on 2021-12-03 by the reprex package (v2.0.1.9000) The error comes from this class in template <typename T>
class RPrimitiveConverter<T, enable_if_t<is_decimal_type<T>::value>>
: public PrimitiveConverter<T, RConverter> {
public:
Status Extend(SEXP x, int64_t size, int64_t offset = 0) override {
return Status::NotImplemented("Extend");
}
}; Maybe we could catch the |
Perhaps we could have something like this on the R side: Array$create <- function(x, type = NULL) {
if (!is.null(type)) {
type <- as_type(type)
}
if (inherits(x, "Scalar")) {
out <- x$as_array()
if (!is.null(type)) {
out <- out$cast(type)
}
return(out)
}
tryCatch(
vec_to_Array(x, type),
error = function(cnd) {
if (!is.null(type)) {
# try again and then cast
vec_to_Array(x, NULL)$cast(type)
} else {
signalCondition(cnd)
}
}
)
} So that: library(arrow, warn.conflicts = FALSE)
#> See arrow_info() for available features
Array$create(c(1, 2), type = decimal(4, 3))
#> Array
#> <decimal128(4, 3)>
#> [
#> 1.000,
#> 2.000
#> ] Created on 2021-12-03 by the reprex package (v2.0.1.9000) |
This is outdated. Work on |
@jonkeane & @romainfrancois this is the 2nd attempt at implementing `decimal256()`. First one is #11805 Closes #11898 from dragosmg/ARROW-14844_decimal256_take2 Lead-authored-by: Dragos Moldovan-Grünfeld <dragos.mold@gmail.com> Co-authored-by: Dragoș Moldovan-Grünfeld <dragos.mold@gmail.com> Signed-off-by: Jonathan Keane <jkeane@gmail.com>
@jonkeane & @romainfrancois this is the 2nd attempt at implementing `decimal256()`. First one is apache#11805 Closes apache#11898 from dragosmg/ARROW-14844_decimal256_take2 Lead-authored-by: Dragos Moldovan-Grünfeld <dragos.mold@gmail.com> Co-authored-by: Dragoș Moldovan-Grünfeld <dragos.mold@gmail.com> Signed-off-by: Jonathan Keane <jkeane@gmail.com>
No description provided.