Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-16266

[R] Add StructArray$create()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: In Progress
    • Critical
    • Resolution: Unresolved
    • None
    • 11.0.0
    • R

    Description

      In ARROW-13371 we implemented the make_struct compute function bound to data.frame() / tibble() in dplyr evaluation; however, we didn't actually implement StructArray$create(). In ARROW-15168, it turns out that we need to do this to support StructArray creation from data.frames whose columns aren't all convertable using the internal C++ conversion. The hack used in that PR is below (but we should clearly implement the C++ function instead of using the hack):

      library(arrow, warn.conflicts = FALSE)
      
      struct_array <- function(...) {
        batch <- record_batch(...)
        array_ptr <- arrow:::allocate_arrow_array()
        schema_ptr <- arrow:::allocate_arrow_schema()
        batch$export_to_c(array_ptr, schema_ptr)
        Array$import_from_c(array_ptr, schema_ptr)
      }
      
      struct_array(a = 1, b = "two")
      #> StructArray
      #> <struct<a: double, b: string>>
      #> -- is_valid: all not null
      #> -- child 0 type: double
      #>   [
      #>     1
      #>   ]
      #> -- child 1 type: string
      #>   [
      #>     "two"
      #>   ]
      

      Attachments

        Issue Links

          Activity

            People

              thisisnic Nicola Crane
              paleolimbot Dewey Dunnington
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h