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

feat(r): Implement string view support in R bindings #636

Merged
merged 11 commits into from
Sep 30, 2024

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Sep 27, 2024

This PR adds support for string view and binary view types to the R bindings. As a side effect of this, conversion of character vectors to Arrow types is now simpler (just goes through nanoarrow C's array builder) and supports more types (e.g., the arrow package is no longer required to create large_string, large_binary, or fixed_size_binary).

library(nanoarrow)

long_strings <- rep(strrep(letters, 100), 100)

(array <- as_nanoarrow_array(long_strings, schema = na_string_view()))
#> <nanoarrow_array string_view[2600]>
#>  $ length    : int 2600
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 11
#>   ..$ :<nanoarrow_buffer validity<bool>[0][0 b]> ``
#>   ..$ :<nanoarrow_buffer unknown<string_view>[2600][41600 b]>`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `aaaaaaaaaaaaaaaaaaaaaaaaaaa...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `ppppppppppppppppppppppppppp...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `eeeeeeeeeeeeeeeeeeeeeeeeeee...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `ttttttttttttttttttttttttttt...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `iiiiiiiiiiiiiiiiiiiiiiiiiii...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `xxxxxxxxxxxxxxxxxxxxxxxxxxx...`
#>   ..$ :<nanoarrow_buffer data<string>[32700 b]> `mmmmmmmmmmmmmmmmmmmmmmmmmmm...`
#>   ..$ :<nanoarrow_buffer data<string>[31100 b]> `bbbbbbbbbbbbbbbbbbbbbbbbbbb...`
#>   ..$ :<nanoarrow_buffer data<int64>[8][64 b]> `32700 32700 32700 32700 3270...`
#>  $ dictionary: NULL
#>  $ children  : list()

identical(convert_array(array), long_strings)
#> [1] TRUE

Created on 2024-09-27 with reprex v2.1.1

@paleolimbot paleolimbot marked this pull request as ready for review September 27, 2024 18:53
r/R/type.R Show resolved Hide resolved
Copy link
Member

@amoeba amoeba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left some notes.

r/tests/testthat/test-convert-array.R Show resolved Hide resolved
r/tests/testthat/test-as-array.R Show resolved Hide resolved
r/src/as_array.c Outdated Show resolved Hide resolved
@paleolimbot paleolimbot merged commit 5b98b3d into apache:main Sep 30, 2024
12 checks passed
@paleolimbot paleolimbot deleted the r-string-view branch September 30, 2024 16:58
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

Successfully merging this pull request may close these issues.

2 participants