paleolimbot commented on pull request #11730:
URL: https://github.com/apache/arrow/pull/11730#issuecomment-984643010


   ...and I can't get this to fail invoking the C API from the R end of things:
   
   <details>
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   library(dplyr, warn.conflicts = FALSE)
   
   example_data <- tibble::tibble(
     int = c(1:3, NA_integer_, 5:10),
     dbl = c(1:8, NA, 10) + .1,
     dbl2 = rep(5, 10),
     lgl = sample(c(TRUE, FALSE, NA), 10, replace = TRUE),
     false = logical(10),
     chr = letters[c(1:5, NA, 7:10)],
     fct = factor(letters[c(1:4, NA, NA, 7:10)])
   )
   
   tf <- tempfile()
   new_ds <- rbind(
     cbind(example_data, part = 1),
     cbind(example_data, part = 2),
     cbind(example_data, part = 3),
     cbind(example_data, part = 4)
   ) %>%
     mutate(row_order = 1:n()) %>% 
     select(-false, -lgl, -fct)
   
   write_dataset(new_ds, tf, partitioning = "part")
   
   ds <- open_dataset(tf)
   
   # let's pop this puppy open in C and see if what's coming from the pipe in 
Arrow
   # is correct
   # 
https://github.com/duckdb/duckdb/blob/master/tools/rpkg/R/register.R#L71-L82
   
   stream <- carrow:::blank_invalid_array_stream()
   stream_ptr <- carrow:::xptr_addr_double(stream)
   s <- Scanner$create(
     ds, 
     NULL,
     filter = arrow:::build_expr(
       "&",
       arrow:::build_expr(">", Expression$field_ref("int"), 5),
       arrow:::build_expr(">", Expression$field_ref("part"), 1)
     ),
     use_async = FALSE,
     use_threads = TRUE
   )$
     ToRecordBatchReader()$
     export_to_c(stream_ptr)
   
   # check schema
   recreated_schema <- carrow::from_carrow_array(
     list(schema = carrow::carrow_array_stream_get_schema(stream)),
     arrow::Schema
   )
   # ding!
   recreated_schema == ds$schema
   #> [1] TRUE
   
   items <- list()
   while (TRUE) {
     item <- carrow::carrow_array_stream_get_next(stream)
     if (is.null(item)) {
       break
     }
     items[[length(items) + 1L]] <- carrow::from_carrow_array(item)
   }
   
   result <- tibble::as_tibble(bind_rows(items))
   
   waldo::compare(
     result %>% 
       select(part, everything()) %>%
       mutate(part = as.double(part)) %>% 
       arrange(row_order),
     tibble::as_tibble(new_ds) %>%
       filter(int > 5 & part > 1) %>% 
       select(part, everything())
   )
   #> ✓ No differences
   ```
   
   <sup>Created on 2021-12-02 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</sup>
   
   </details>
   


-- 
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