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): Handle NUMERIC type by converting to string #883

Merged
merged 15 commits into from
Jul 11, 2023

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Jul 7, 2023

Closes #767.

This PR implements NUMERIC Postgres columns by converting them to strings. This is not ideal but there is also no Arrow type that can be easily computed before an entire column of Postgres numerics has been resolved. A future extension could attempt decimal conversion in the driver but for now a string value is better than is what currently gets returned (a blob of the COPY data).

Example support via the R bindings:

# pak::pak("apache/arrow-adbc/r/adbcpostgresql#883")
# docker compose up postgres_test
library(adbcdrivermanager)

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

db |> 
  read_adbc(
    "SELECT CAST(col AS NUMERIC) AS col FROM 
      (VALUES (-123.456), (123.456), (0.4567890), (1200000), ('nan'), ('-inf'), ('inf'), (NULL)) 
      AS drvd(col)"
  ) |> 
  as.data.frame()
#>         col
#> 1  -123.456
#> 2   123.456
#> 3 0.4567890
#> 4   1200000
#> 5       nan
#> 6      -inf
#> 7       inf
#> 8      <NA>

Created on 2023-07-08 with reprex v2.0.2

@paleolimbot paleolimbot marked this pull request as ready for review July 10, 2023 19:44
return EINVAL;
}

if (special_value.size() > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: !special_value.empty()

}

// Calculate string space requirement
int64_t max_chars_required = std::max<int64_t>(1, weight + 1 * kDecDigits);
Copy link
Member

Choose a reason for hiding this comment

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

is the 1 * necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! (Was a typo 😬 )

@paleolimbot paleolimbot merged commit 409f839 into apache:main Jul 11, 2023
65 checks passed
@paleolimbot paleolimbot deleted the postgres-numeric branch July 12, 2023 15:11
@lidavidm lidavidm added this to the ADBC Libraries 0.6.0 milestone Jul 20, 2023
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.

c/driver/postgresql: support NUMERIC type
2 participants