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

Deal with bigint = "integer64" to mean "always return integer64" #311

Open
nbenn opened this issue Dec 14, 2023 · 0 comments
Open

Deal with bigint = "integer64" to mean "always return integer64" #311

nbenn opened this issue Dec 14, 2023 · 0 comments

Comments

@nbenn
Copy link
Member

nbenn commented Dec 14, 2023

As per spec, the semantics for the bigint = "integer64" connection argument are

return as a data type that can be coerced using as.integer() (with warning on overflow), as.numeric() and as.character()

For the implementation in adbi, this means that setting bigint = "integer64" will always return integer64, irrespective of whether the data fits into the int range or not. This deviates from how RSQLite interprets this option.

This causes issues in DBItest that might require a "tweak" similar to how logical_return works, as I now get a failure for example in table_visible_in_other_connection :

ctx <- DBItest::make_context(
  adbi::adbi("adbcsqlite"),
  list(
    uri = tempfile("DBItest", fileext = ".sqlite"),
    rows_affected_callback = function() function(x) {
      if (x == -1) testthat::skip("unknown number of `rows_affected`") else x
    }
  ),
  tweaks = suppressWarnings(
    DBItest::tweaks(
      dbitest_version = "1.7.3",
      constructor_relax_args = TRUE,
      placeholder_pattern = c("?", "$1", "$name", ":name"),
      date_cast = function(x) paste0("'", x, "'"),
      time_cast = function(x) paste0("'", x, "'"),
      timestamp_cast = function(x) paste0("'", x, "'"),
      logical_return = function(x) bit64::as.integer64(x),
      date_typed = FALSE,
      time_typed = FALSE,
      timestamp_typed = FALSE,
      temporary_tables = FALSE, # apache/arrow-adbc#1141
      strict_identifier = TRUE
    )
  ),
  name = "adbi"
)

trace(DBItest:::expect_equal_df, quote({print(str(actual)); print(str(expected))}))
#> Tracing function "expect_equal_df" in package "DBItest
#> (not-exported)"
#> [1] "expect_equal_df"

try(DBItest::test_some("table_visible_in_other_connection", ctx, FALSE))
#> Tracing expect_equal_df(penguins_out, penguins30) on entry
#> 'data.frame': 3 obs. of  8 variables:
#>  $ species          : chr  "Adelie" "Gentoo" "Chinstrap"
#>  $ island           : chr  "Torgersen" "Biscoe" "Dream"
#>  $ bill_length_mm   : num  39.1 46.1 46.5
#>  $ bill_depth_mm    : num  18.7 13.2 17.9
#>  $ flipper_length_mm:integer64 181 211 192
#>  $ body_mass_g      :integer64 3750 4500 3500
#>  $ sex              : chr  "male" "female" "female"
#>  $ year             :integer64 2007 2007 2007
#> NULL
#> 'data.frame': 3 obs. of  8 variables:
#>  $ species          : chr  "Adelie" "Gentoo" "Chinstrap"
#>  $ island           : chr  "Torgersen" "Biscoe" "Dream"
#>  $ bill_length_mm   : num  39.1 46.1 46.5
#>  $ bill_depth_mm    : num  18.7 13.2 17.9
#>  $ flipper_length_mm: int  181 211 192
#>  $ body_mass_g      : int  3750 4500 3500
#>  $ sex              : chr  "male" "female" "female"
#>  $ year             : int  2007 2007 2007
#> NULL
#> Tracing expect_equal_df(dbReadTable(con2, table_name), penguins30) on entry
#> 'data.frame': 3 obs. of  8 variables:
#>  $ species          : chr  "Adelie" "Gentoo" "Chinstrap"
#>  $ island           : chr  "Torgersen" "Biscoe" "Dream"
#>  $ bill_length_mm   : num  39.1 46.1 46.5
#>  $ bill_depth_mm    : num  18.7 13.2 17.9
#>  $ flipper_length_mm:integer64 181 211 192
#>  $ body_mass_g      :integer64 3750 4500 3500
#>  $ sex              : chr  "male" "female" "female"
#>  $ year             :integer64 2007 2007 2007
#> NULL
#> 'data.frame': 3 obs. of  8 variables:
#>  $ species          : chr  "Adelie" "Gentoo" "Chinstrap"
#>  $ island           : chr  "Torgersen" "Biscoe" "Dream"
#>  $ bill_length_mm   : num  39.1 46.1 46.5
#>  $ bill_depth_mm    : num  18.7 13.2 17.9
#>  $ flipper_length_mm: int  181 211 192
#>  $ body_mass_g      : int  3750 4500 3500
#>  $ sex              : chr  "male" "female" "female"
#>  $ year             : int  2007 2007 2007
#> NULL

Note the different types for columns flipper_length_mm and body_mass_g between actual and expected in the two calls to expect_equal_df().

Some info on package versions (happy to provide more if needed):

─ Packages ─────────────────────────────────────────────────────────────────────────────
 package           * version    date (UTC) lib source
 adbcdrivermanager   0.8.0      2023-11-10 [1] CRAN (R 4.2.3)
 adbcsqlite          0.8.0      2023-11-10 [1] CRAN (R 4.2.3)
 adbi                0.0.2      2023-12-11 [1] CRAN (R 4.2.3)
...
 DBI                 1.1.3.9016 2023-12-12 [1] Github (r-dbi/DBI@4e87378)
 DBItest             1.7.3.9012 2023-12-12 [1] Github (r-dbi/DBItest@fe02e7d)
...
@krlmlr krlmlr changed the title Deal with bigint = "integer64" to mean "always return integer64 Deal with bigint = "integer64" to mean "always return integer64" Dec 16, 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

No branches or pull requests

1 participant