You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Kouhei Sutou (Jira)" <ji...@apache.org> on 2022/10/19 03:12:00 UTC
[jira] [Updated] (ARROW-17606) [C++] Cast float to decimal truncates
[ https://issues.apache.org/jira/browse/ARROW-17606?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kouhei Sutou updated ARROW-17606:
---------------------------------
Fix Version/s: 11.0.0
(was: 10.0.0)
> [C++] Cast float to decimal truncates
> -------------------------------------
>
> Key: ARROW-17606
> URL: https://issues.apache.org/jira/browse/ARROW-17606
> Project: Apache Arrow
> Issue Type: Bug
> Components: C++
> Reporter: Neal Richardson
> Priority: Major
> Fix For: 11.0.0
>
>
> Even with all of the cast options to allow truncation and overflow set to False, cast from double to decimal truncates.
> Short reproducer in R:
> {code}
> library(arrow, warn.conflicts = FALSE)
> a <- Scalar$create(sqrt(2))
> a
> #> Scalar
> #> 1.4142135623730951
> a$cast(decimal(5, 1))
> #> Scalar
> #> 1.4
> {code}
> Longer version that shows the cast options:
> {code}
> library(arrow, warn.conflicts = FALSE)
> library(dplyr, warn.conflicts = FALSE)
> tab <- arrow_table(a = sqrt(2))
> tab
> #> Table
> #> 1 rows x 1 columns
> #> $a <double>
> tab$a
> #> ChunkedArray
> #> <double>
> #> [
> #> [
> #> 1.4142135623730951
> #> ]
> #> ]
> # See that all of the cast options are false:
> tab %>%
> mutate(b = cast(a, decimal(5, 1)))
> #> Table (query)
> #> a: double
> #> b: decimal128(5, 1) (cast(a, {to_type=decimal128(5, 1), allow_int_overflow=false, allow_time_truncate=false, allow_time_overflow=false, allow_decimal_truncate=false, allow_float_truncate=false, allow_invalid_utf8=false}))
> #>
> #> See $.data for the source Arrow object
> new_tab <- tab %>%
> mutate(b = cast(a, decimal(5, 1))) %>%
> compute()
> new_tab
> #> Table
> #> 1 rows x 2 columns
> #> $a <double>
> #> $b <decimal128(5, 1)>
> new_tab$b
> #> ChunkedArray
> #> <decimal128(5, 1)>
> #> [
> #> [
> #> 1.4
> #> ]
> #> ]
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)