[
https://issues.apache.org/jira/browse/ARROW-17885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17611028#comment-17611028
]
Dewey Dunnington commented on ARROW-17885:
------------------------------------------
It looks like we need {{infer_type()}} and {{as_arrow_array()}} generics for
the blob class (or maybe we could do this more generically for the vctrs
list_of class):
{code:R}
library(arrow, warn.conflicts = FALSE)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()` for
more information.
infer_type.blob <- function(x, ...) {
if (sum(lengths(x)) > .Machine$integer.max) {
large_binary()
} else {
binary()
}
}
as_arrow_array.blob <- function(x, ..., type = NULL) {
as_arrow_array(unclass(x), type = type)
}
data <- data.frame(
a = 1:3,
b = 2.5,
c = "three",
stringsAsFactors = FALSE
)
data$d <- blob::blob(as.raw(1:10))
(tbl <- arrow::as_arrow_table(data))
#> Table
#> 3 rows x 4 columns
#> $a <int32>
#> $b <double>
#> $c <string>
#> $d <binary>
#>
#> See $metadata for additional Schema metadata
tibble::as_tibble(tbl)
#> # A tibble: 3 × 4
#> a b c d
#> <int> <dbl> <chr> <blob>
#> 1 1 2.5 three <raw 10 B>
#> 2 2 2.5 three <raw 10 B>
#> 3 3 2.5 three <raw 10 B>
{code}
> [R] Return BLOB data as list of raw instead of a list of integers
> -----------------------------------------------------------------
>
> Key: ARROW-17885
> URL: https://issues.apache.org/jira/browse/ARROW-17885
> Project: Apache Arrow
> Issue Type: Bug
> Components: R
> Affects Versions: 10.0.0, 9.0.1
> Environment: macOS arm64, R 4.1.3
> Reporter: Kirill Müller
> Priority: Minor
>
> BLOBs should be mapped to lists of raw in R, not lists of integer. Tested
> with ec714db3995549309b987fc8112db98bb93102d0.
> library(arrow)
> #> Some features are not enabled in this build of Arrow. Run `arrow_info()`
> for more information.
> #>
> #> Attaching package: 'arrow'
> #> The following object is masked from 'package:utils':
> #>
> #> timestamp
> data <- data.frame(
> a = 1:3,
> b = 2.5,
> c = "three",
> stringsAsFactors = FALSE
> )
> data$d <- blob::blob(as.raw(1:10))
> tbl <- arrow::as_arrow_table(data)
> rbr <- arrow::as_record_batch_reader(tbl)
> waldo::compare(as.data.frame(rbr$read_next_batch()), data)
> #> `old$d[[1]]` is an integer vector (1, 2, 3, 4, 5, ...)
> #> `new$d[[1]]` is a raw vector (01, 02, 03, 04, 05, ...)
> #>
> #> `old$d[[2]]` is an integer vector (1, 2, 3, 4, 5, ...)
> #> `new$d[[2]]` is a raw vector (01, 02, 03, 04, 05, ...)
> #>
> #> `old$d[[3]]` is an integer vector (1, 2, 3, 4, 5, ...)
> #> `new$d[[3]]` is a raw vector (01, 02, 03, 04, 05, ...)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)