You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "paleolimbot (via GitHub)" <gi...@apache.org> on 2023/09/05 16:43:30 UTC

[GitHub] [arrow-adbc] paleolimbot commented on pull request #985: feat(r): Add async infrastructure for specific methods

paleolimbot commented on PR #985:
URL: https://github.com/apache/arrow-adbc/pull/985#issuecomment-1706960502

   Far from usable, but it works! Probably needs some version of "read everything from `stream` with a callback for each batch...I'm not sure that fits nicely into `promises` since there are an indeterminate number of batches.
   
   ``` r
   library(adbcdrivermanager)
   
   db <- adbc_database_init(adbcsqlite::adbcsqlite())
   con <- adbc_connection_init(db)
   
   flights <- nycflights13::flights
   flights$time_hour <- NULL
   flights |>
     write_adbc(con, "flights")
   
   
   # Sync
   stmt <- adbc_statement_init(con)
   adbc_statement_set_sql_query(stmt, "SELECT * from flights")
   stream <- nanoarrow::nanoarrow_allocate_array_stream()
   adbc_statement_execute_query(stmt, stream)
   #> [1] -1
   stream
   #> <nanoarrow_array_stream struct<year: int64, month: int64, day: int64, dep_time: int64, sched_dep_time: int64, dep_delay: double, arr_time: int64, sched_arr_time: int64, arr_delay: double, carrier: string, flight: int64, tailnum: string, origin: string, dest: string, air_time: double, distance: double, hour: double, minute: double>>
   #>  $ get_schema:function ()  
   #>  $ get_next  :function (schema = x$get_schema(), validate = TRUE)  
   #>  $ release   :function ()
   
   value <- NULL
   
   
   # Async
   (promise <- con |> 
     adbc_statement_init() |> 
     adbc_statement_set_sql_query("SELECT * from flights") |> 
     adbcdrivermanager:::adbc_statement_execute_query_promise() |> 
     promises::then(function(stream) {
       adbcdrivermanager:::adbc_array_stream_get_next_promise(stream)
     }) |> 
     promises::then(function(array) {
       tibble::as_tibble(array)
     }) |> 
     promises::then(function(tbl) {
       value <<- tbl
     }))
   #> <Promise [pending]>
   
   value
   #> NULL
   
   while(!later::loop_empty()) {
     later::run_now()
   }
   
   promise
   #> <Promise [fulfilled: tbl_df]>
   value
   #> # A tibble: 1,024 × 18
   #>     year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
   #>    <dbl> <dbl> <dbl>    <dbl>          <dbl>     <dbl>    <dbl>          <dbl>
   #>  1  2013     1     1      517            515         2      830            819
   #>  2  2013     1     1      533            529         4      850            830
   #>  3  2013     1     1      542            540         2      923            850
   #>  4  2013     1     1      544            545        -1     1004           1022
   #>  5  2013     1     1      554            600        -6      812            837
   #>  6  2013     1     1      554            558        -4      740            728
   #>  7  2013     1     1      555            600        -5      913            854
   #>  8  2013     1     1      557            600        -3      709            723
   #>  9  2013     1     1      557            600        -3      838            846
   #> 10  2013     1     1      558            600        -2      753            745
   #> # ℹ 1,014 more rows
   #> # ℹ 10 more variables: arr_delay <dbl>, carrier <chr>, flight <dbl>,
   #> #   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
   #> #   hour <dbl>, minute <dbl>
   ```
   
   <sup>Created on 2023-09-05 with [reprex v2.0.2](https://reprex.tidyverse.org)</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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org