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

   The working example I have is only with queries that don't require reading 
in async (the reading in async is implemented but I haven't played with it 
much).
   
   ``` r
   library(adbcdrivermanager)
   
   # docker compose up postgres-test
   test_uri <- 
"postgresql://localhost:5432/postgres?user=postgres&password=password"
   
   # Needs to be big or else it doesn't take long enough to test that 
cancellation works
   flights <- vctrs::vec_rep(nycflights13::flights, 10)
   flights <- nanoarrow::as_nanoarrow_array_stream(flights)
   
   con <- adbc_database_init(adbcpostgresql::adbcpostgresql(), uri = test_uri) 
|> 
     adbc_connection_init()
   
   stmt <- adbc_statement_init(con, adbc.ingest.target_table = "flights")
   adbc_statement_bind_stream(stmt, flights)
   task <- adbcdrivermanager:::adbc_statement_execute_query_async(stmt)
   
   # You should be able to request cancel using Control-C here
   adbcdrivermanager:::adbc_async_task_wait(task)
   #> $statement
   #> <adbcpostgresql_statement at 0x11d785370> 
   #> List of 1
   #>  $ connection:<adbcpostgresql_connection at 0x11d7e0c10> 
   #> List of 1
   #>   ..$ database:<adbcpostgresql_database at 0x11d7a47c0> 
   #> List of 1
   #>   .. ..$ driver:<adbcpostgresql_driver_postgresql> List of 2
   #>   .. .. ..$ driver_init_func:Class 'adbc_driver_init_func' <externalptr> 
   #>   .. .. ..$ .child_count    : int 0
   #> 
   #> $stream
   #> NULL
   #> 
   #> $rows_affected
   #> [1] 3367760
   
   # In case you want to try this again
   # con |> execute_adbc("DROP TABLE flights;")
   ```
   
   <sup>Created on 2024-06-16 with [reprex 
v2.1.0](https://reprex.tidyverse.org)</sup>
   
   Another example I was playing with was using the "sleep" version to ensure 
that it wasn't too costly to make these async calls:
   
   ``` r
   bench::mark(
     a1 = adbcdrivermanager:::adbc_async_sleep(1) |> 
adbcdrivermanager:::adbc_async_task_wait(),
     a10 = adbcdrivermanager:::adbc_async_sleep(10) |> 
adbcdrivermanager:::adbc_async_task_wait(),
     a100 = adbcdrivermanager:::adbc_async_sleep(100) |> 
adbcdrivermanager:::adbc_async_task_wait(),
     a500 = adbcdrivermanager:::adbc_async_sleep(500) |> 
adbcdrivermanager:::adbc_async_task_wait(),
     check = FALSE
   )
   #> # A tibble: 4 × 6
   #>   expression      min   median `itr/sec` mem_alloc `gc/sec`
   #>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
   #> 1 a1           1.14ms    1.4ms    704.       338KB        0
   #> 2 a10         10.52ms   12.5ms     81.0       560B        0
   #> 3 a100       100.84ms  103.6ms      9.71      560B        0
   #> 4 a500       497.31ms  497.3ms      2.01      560B        0
   ```
   
   <sup>Created on 2024-06-16 with [reprex 
v2.1.0](https://reprex.tidyverse.org)</sup>
   
   You should be able to try these with promises by turning the `task` into a 
promise using `as.promise()`. Feel free to post your adventures here so that I 
have better examples to test with!


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