GitHub user paleolimbot added a comment to the discussion: R w adbi package
reading from FlightSQL server - could duckdb type UBIGINT and BIGINT be treated
as bit64 in R?
Thanks for opening!
nanoarrow has an option to explicitly choose the destination ptype when
converting to R, including using a function to handle arbitrary input!
``` r
library(nanoarrow)
df <- data.frame(x = bit64::as.integer64(2^60) + 1L)
stream <- as_nanoarrow_array_stream(df)
stream$get_schema()
#> <nanoarrow_schema struct>
#> $ format : chr "+s"
#> $ name : chr ""
#> $ metadata : list()
#> $ flags : int 0
#> $ children :List of 1
#> ..$ x:<nanoarrow_schema int64>
#> .. ..$ format : chr "l"
#> .. ..$ name : chr "x"
#> .. ..$ metadata : list()
#> .. ..$ flags : int 2
#> .. ..$ children : list()
#> .. ..$ dictionary: NULL
#> $ dictionary: NULL
convert_array_stream(stream)
#> Warning in convert_array_stream(stream): 1 value(s) may have incurred loss of
#> precision in conversion to double()
#> x
#> 1 1.152922e+18
stream <- as_nanoarrow_array_stream(df)
convert_array_stream(stream, to = data.frame(x = bit64::integer64()))
#> x
#> 1 1152921504606846977
stream <- as_nanoarrow_array_stream(df)
convert_array_stream(stream, to = data.frame(x = character()))
#> x
#> 1 1152921504606846977
custom <- function(schema, inferred_ptype) {
for (i in seq_along(schema$children)) {
if (schema$children[[i]]$format == "l") {
inferred_ptype[[i]] <- bit64::integer64()
}
}
inferred_ptype
}
stream <- as_nanoarrow_array_stream(df)
convert_array_stream(stream, to = custom)
#> x
#> 1 1152921504606846977
```
I forget how or if this was integrated into adbi (I seem to recall there was an
option at some point!)
GitHub link:
https://github.com/apache/arrow-nanoarrow/discussions/812#discussioncomment-14576571
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]