forked from apache/arrow-adbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(c/driver/postgresql): Use copy writer in BindStream for para…
…meter binding (apache#2157) This PR refactors the `BindStream` to use the COPY writer instead of its own serialization logic. This logic is the same between insertion and binding, although the API used to send it to the database is slightly different. This is a helpful consolidation of logic and means that adding type support on the Arrow or Postgresql side (or fixing bugs in the inference or serialization) is slightly easier. It also means we can bind parameters that are lists and is a workaround for inserting into a table with a schema where Postgres knows how to cast the types (but ADBC might not yet). ``` r library(adbcdrivermanager) library(nanoarrow) con <- adbc_database_init( adbcpostgresql::adbcpostgresql(), uri = "postgresql://localhost:5432/postgres?user=postgres&password=password" ) |> adbc_connection_init() # Create an array with a uint32 column df <- tibble::tibble(uint32_col = 1:5) array <- df |> nanoarrow::as_nanoarrow_array( schema = na_struct(list(uint32_col = na_uint32())) ) # Create a table with an integer column con |> execute_adbc("DROP TABLE IF EXISTS adbc_test") con |> execute_adbc("CREATE TABLE adbc_test (uint32_col int4)") # This will fail (types not identical) array |> write_adbc(con, "adbc_test", mode = "append") #> Error in adbc_statement_execute_query(stmt): INVALID_ARGUMENT: [libpq] Failed to execute COPY statement: PGRES_FATAL_ERROR ERROR: incorrect binary data format #> CONTEXT: COPY adbc_test, line 1, column uint32_col con |> execute_adbc("INSERT INTO adbc_test VALUES ($1)", bind = array) con |> read_adbc("SELECT * FROM adbc_test") |> tibble::as_tibble() #> # A tibble: 5 × 1 #> uint32_col #> <int> #> 1 1 #> 2 2 #> 3 3 #> 4 4 #> 5 5 ``` <sup>Created on 2024-09-12 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
- Loading branch information
1 parent
fa8ea10
commit 46dc748
Showing
9 changed files
with
221 additions
and
365 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters