Skip to content
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

[r] Disallow writing character and raw arrays #3503

Open
mojaveazure opened this issue Dec 20, 2024 · 0 comments
Open

[r] Disallow writing character and raw arrays #3503

mojaveazure opened this issue Dec 20, 2024 · 0 comments

Comments

@mojaveazure
Copy link
Member

mojaveazure commented Dec 20, 2024

The R API allows sparse and dense arrays to have a type of arrow::utf8(), which is disallowed by the spec (primitives only). If the user attempts to create an array of characters, the R API should error out

Dense array example:

> uri <- tempfile("r-dense-character")
> strings <- matrix("", nrow = 200L, ncol = 100L)
> (atype <- arrow::infer_type(strings))
[1] Utf8
     string
> arr <- SOMADenseNDArrayCreate(uri, type = atype, shape = dim(strings)) # This should error
> arr$write(strings)
> arr$close()
> arr <- SOMADenseNDArrayOpen(uri)
> arr$read_arrow_table()$soma_data$type
[1] LargeUtf8
     large_string

Sparse array example

> uri <- tempfile("r-sparse-character")
> shape <- c(200L, 100L)
> ij <- sample.int(prod(shape), size = floor(0.6 * prod(shape))) - 1L
> coo <- data.frame(soma_dim_0 = ij%%shape[1L], soma_dim_1 = ij%/%shape[1L], soma_data = "")
> (atype <- arrow::infer_type(coo$soma_data))
[1] Utf8
     string
> arr <- SOMASparseNDArrayCreate(uri, type = atype, shape = shape) # This should error
> arr$.write_coordinates(coo)
> arr$close()
> arr <- SOMASparseNDArrayOpen(uri)
> arr$read()$tables()$concat()$soma_data$type
[1] LargeUtf8
     large_string

Likewise, raw should be disallowed (Arrow maps to Uint8, but this should be Binary, which is also disallowed by the spec)

@mojaveazure mojaveazure changed the title [r] Disallow writing character arrays [r] Disallow writing character and raw arrays Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant