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

feat(c/driver/postgresql): Implement ingestion of list types for PostgreSQL #2153

Merged
merged 15 commits into from
Sep 12, 2024

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Sep 10, 2024

This PR adds list ingest support in the PostgreSQL driver. The raw COPY and type support had already been added; however, there were still some hard-coded switch-on-type that implemented some necessary features (e.g., the CREATE TABLE syntax for each type). I moved these to the type/copy section and removed the previous implementation (which should also help for a future PR implementing the ability to bind nested types as parameters).

I also added the infrastructure to test this in all drivers via the validation suite, which required modifying some of the built-in concepts to accommodate a nested type.

Closes #2066.

library(adbcdrivermanager)

con <- adbc_database_init(
  adbcpostgresql::adbcpostgresql(),
  uri = "postgresql://localhost:5432/postgres?user=postgres&password=password"
) |> 
  adbc_connection_init()

df <- tibble::tibble(
  A = vctrs::list_of(1:3, 4:5, 6:10),
  B = c(10.0, 20.0, 30.0)
)

con |> 
  execute_adbc("DROP TABLE IF EXISTS table_with_list")

df |> 
  write_adbc(con, "table_with_list")

con |> 
  read_adbc("select * from table_with_list") |> 
  tibble::as_tibble() |> 
  dplyr::pull(1)
#> <list_of<integer>[3]>
#> [[1]]
#> [1] 1 2 3
#> 
#> [[2]]
#> [1] 4 5
#> 
#> [[3]]
#> [1]  6  7  8  9 10

Created on 2024-09-11 with reprex v2.1.1

@paleolimbot paleolimbot marked this pull request as ready for review September 11, 2024 22:00
@github-actions github-actions bot added this to the ADBC Libraries 15 milestone Sep 11, 2024
@@ -183,6 +183,26 @@ class PostgresType {
const std::string& field_name() const { return field_name_; }
int64_t n_children() const { return static_cast<int64_t>(children_.size()); }
const PostgresType& child(int64_t i) const { return children_[i]; }
const std::string create_table_name() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named TypeName or something? Not table name?

@paleolimbot paleolimbot merged commit a4a0cc1 into apache:main Sep 12, 2024
63 checks passed
@paleolimbot paleolimbot deleted the c-driver-postgres-list-ingest branch September 12, 2024 16:31
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

Successfully merging this pull request may close these issues.

Streaming LIST data over ADBC
2 participants