paleolimbot commented on issue #1127:
URL: https://github.com/apache/arrow-adbc/issues/1127#issuecomment-1739511718

   It's not very pretty, but you can do something like this to get a list:
   
   ``` r
   library(adbcdrivermanager)
   
   db <- adbc_database_init(adbcsqlite::adbcsqlite(), uri = ":memory:")
   con <- adbc_connection_init(db)
   info <- adbc_connection_get_info(con, info_codes = c(0L, 1L))
   info_df <- as.data.frame(info)
   
   info_value <- info_df$info_value
   info_value_na <- lapply(info_value, is.na)
   info_value_list <- vector("list", nrow(info_value))
   for (i in seq_len(nrow(info_value))) {
     for (j in seq_len(ncol(info_value))) {
       if (!info_value_na[[j]][i]) {
         info_value_list[i] <- info_value[[j]][i]
         break
       } else {
         info_value_list[i] <- list(NULL)
       }
     }
   }
   
   info_value_list
   #> [[1]]
   #> [1] "SQLite"
   #> 
   #> [[2]]
   #> [1] "3.39.3"
   ```
   
   If you have the array, nanoarrow lets you inspect the array buffers directly 
to get the "which" buffer of the union. I'm not sure it's any less verbose, but:
   
   ``` r
   library(adbcdrivermanager)
   
   db <- adbc_database_init(adbcsqlite::adbcsqlite(), uri = ":memory:")
   con <- adbc_connection_init(db)
   info <- adbc_connection_get_info(con, info_codes = c(0L, 1L))
   info_array <- info$get_next()
   # Pretty much all drivers should only ever have one array in the stream
   stopifnot(is.null(info$get_next())) 
   info$release()
   
   info_df <- nanoarrow::convert_array(info_array)
   info_df_value_which <- 
nanoarrow::convert_buffer(info_array$children[[2]]$buffers[[1]])
   lapply(seq_len(nrow(info_df)), function(i) {
     info_df$info_value[[info_df_value_which[i] + 1L]][[i]]
   })
   #> [[1]]
   #> [1] "SQLite"
   #> 
   #> [[2]]
   #> [1] "3.39.3"
   ```
   
   <sup>Created on 2023-09-28 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: [email protected]

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

Reply via email to