romainfrancois commented on pull request #11225:
URL: https://github.com/apache/arrow/pull/11225#issuecomment-926613285


   One thing I had not paid attention to is that list types benefit from altrep 
too (when the type can be managed by an altrep vector): 
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   #> See arrow_info() for available features
   ```
   
   an Array of type list(int32())
   
   ``` r
   a <- Array$create(list(1:10, 11:20))
   ```
   
   under the hood, an Array of int32() is stored:
   
   ``` r
   a$values()
   #> Array
   #> <int32>
   #> [
   #>   1,
   #>   2,
   #>   3,
   #>   4,
   #>   5,
   #>   6,
   #>   7,
   #>   8,
   #>   9,
   #>   10,
   #>   11,
   #>   12,
   #>   13,
   #>   14,
   #>   15,
   #>   16,
   #>   17,
   #>   18,
   #>   19,
   #>   20
   #> ]
   ```
   
   so converting a to an R vector still benefits from altrep
   
   ``` r
   .Internal(inspect( a$as_vector() ))
   #> @7fc8453ebd88 19 VECSXP g0c2 [OBJ,REF(1),ATT] (len=2, tl=0)
   #>   @7fc848c440f0 13 INTSXP g0c0 [REF(65535)] arrow::Array<int32, 0 nulls> 
len=10, Array=<0x7fc84481d538>
   #>     @7fc848c44160 22 EXTPTRSXP g0c0 [REF(4)] 
   #>   @7fc848c43de0 13 INTSXP g0c0 [REF(65535)] arrow::Array<int32, 0 nulls> 
len=10, Array=<0x7fc84480be58>
   #>     @7fc848c43e50 22 EXTPTRSXP g0c0 [REF(4)] 
   #> ATTRIB:
   #>   @7fc848c446d8 02 LISTSXP g0c0 [REF(1)] 
   #>     TAG: @7fc84000d1d0 01 SYMSXP g1c0 [MARK,REF(45102),LCK,gp=0x6000] 
"class" (has value)
   #>     @7fc845c07738 16 STRSXP g0c3 [MARK,REF(3)] (len=4, tl=0)
   #>       @7fc842f5b988 09 CHARSXP g0c2 [MARK,REF(16),gp=0x60] [ASCII] 
[cached] "arrow_list"
   #>       @7fc842a57c88 09 CHARSXP g1c2 [MARK,REF(149),gp=0x60] [ASCII] 
[cached] "vctrs_list_of"
   #>       @7fc842a57c48 09 CHARSXP g1c2 [MARK,REF(562),gp=0x60] [ASCII] 
[cached] "vctrs_vctr"
   #>       @7fc840026650 09 CHARSXP g1c1 [MARK,REF(1365),gp=0x61] [ASCII] 
[cached] "list"
   #>     TAG: @7fc843a1dc10 01 SYMSXP g1c0 [MARK,REF(2)] "ptype"
   #>     @7fc848c44438 13 INTSXP g0c0 [REF(1)] (len=0, tl=0)
   ```
   
   <sup>Created on 2021-09-24 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.0)</sup>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to