Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nanoarrow_array_stream or nanoarrow_array? #3

Closed
eitsupi opened this issue Nov 12, 2023 · 4 comments
Closed

nanoarrow_array_stream or nanoarrow_array? #3

eitsupi opened this issue Nov 12, 2023 · 4 comments

Comments

@eitsupi
Copy link

eitsupi commented Nov 12, 2023

The DBI package documentation and the DBItest shows that methods like dbGetQueryArrow return nanoarrow_array_stream, but the README of this repository seems to return nanoarrow_array.
Is this intentional?

adbi/README.md

Lines 98 to 99 in f56d677

dbGetQueryArrow(con, "SELECT * from swiss WHERE Agriculture < 40")
#> <nanoarrow_array struct[16]>

@nbenn
Copy link
Member

nbenn commented Dec 14, 2023

@eitsupi sorry for the slow response. We're still a bit unclear on the DBI API here. As soon as that is fixed (i.e. CRAN released), adbi should fall in line.

cc @krlmlr

@eitsupi
Copy link
Author

eitsupi commented Dec 28, 2023

Any update on this?

I tried to implement Arrow-related methods to polarssql, but the return value type is not listed in the documentation and I cannot see the implementation method.

@krlmlr
Copy link
Member

krlmlr commented Dec 31, 2023

The README now returns a nanoarrow array stream. The documentation at https://dbi.r-dbi.org/dev/reference/dbGetQueryArrow.html isn't very specific, intentionally. DBI's implementation for the fallback is accessible like this:

DBI:::dbGetQueryArrow_DBIConnection_character
#> function(conn, statement, ...) {
#>   rs <- dbSendQueryArrow(conn, statement, ...)
#>   on.exit(dbClearResult(rs))
#> 
#>   dbFetchArrow(rs, ...)
#> }
#> <environment: namespace:DBI>
DBI:::dbFetchArrow_DBIResultArrow
#> function(res, ...) {
#>   chunk <- dbFetchArrowChunk_DBIResultArrow(res)
#>   # Corner case: add empty chunk only for zero rows, for schema
#>   if (chunk$length == 0) {
#>     return(nanoarrow::basic_array_stream(
#>       list(),
#>       schema = nanoarrow::infer_nanoarrow_schema(chunk),
#>       validate = FALSE
#>     ))
#>   }
#> 
#>   out <- list(chunk)
#>   repeat {
#>     chunk <- dbFetchArrowChunk_DBIResultArrow(res)
#>     if (chunk$length == 0) {
#>       return(nanoarrow::basic_array_stream(
#>         out,
#>         schema = nanoarrow::infer_nanoarrow_schema(out[[1]]),
#>         validate = FALSE
#>       ))
#>     }
#>     out <- c(out, list(chunk))
#>   }
#> }
#> <environment: namespace:DBI>

Created on 2023-12-31 with reprex v2.0.2

@eitsupi
Copy link
Author

eitsupi commented May 3, 2024

I think this has been fixed, thanks!

@eitsupi eitsupi closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants