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

DBI introduced breaking change #478

Closed
meztez opened this issue Jan 6, 2022 · 1 comment · Fixed by #479
Closed

DBI introduced breaking change #478

meztez opened this issue Jan 6, 2022 · 1 comment · Fixed by #479
Labels
bug an unexpected problem or unintended behavior DBI 🗃️

Comments

@meztez
Copy link
Contributor

meztez commented Jan 6, 2022

DBI introduced a new dbQuoteLiteral that changes the behaviour of sqlData from DBI with BigQueryConnection class.

remotes::install_github("r-dbi/dbi@v1.1.1")
#> Skipping install of 'DBI' from a github remote, the SHA1 (71400d92) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(bigrquery)
library(DBI)
conn <- dbConnect(
  drv = bigquery(),
  project = bq_test_project(),
  dataset = "SHARE"
)
test_df <- data.frame(VAR1 = c(TRUE, FALSE, TRUE))
dbRemoveTable(conn, "TEST_DF")
dbWriteTable(conn, "TEST_DF", sqlData(conn, test_df))
dbReadTable(conn, "TEST_DF")
#> # A tibble: 3 x 1
#>   VAR1 
#>   <lgl>
#> 1 FALSE
#> 2 TRUE 
#> 3 TRUE
Created on 2022-01-06 by the reprex package (v2.0.1)
remotes::install_github("r-dbi/dbi@v1.1.2")
#> Downloading GitHub repo r-dbi/dbi@v1.1.2
#>          checking for file 'C:\Users\gen01914\AppData\Local\Temp\RtmpQXG3OY\remotes2dd044fc3839\r-dbi-DBI-f9d1f6a/DESCRIPTION' ...     checking for file 'C:\Users\gen01914\AppData\Local\Temp\RtmpQXG3OY\remotes2dd044fc3839\r-dbi-DBI-f9d1f6a/DESCRIPTION' ...   v  checking for file 'C:\Users\gen01914\AppData\Local\Temp\RtmpQXG3OY\remotes2dd044fc3839\r-dbi-DBI-f9d1f6a/DESCRIPTION'
#>       -  preparing 'DBI': (1.5s)
#>    checking DESCRIPTION meta-information ...     checking DESCRIPTION meta-information ...   v  checking DESCRIPTION meta-information
#>       -  installing the package to process help pages
#>       -  checking for LF line-endings in source and make files and shell scripts (11.2s)
#>       -  checking for empty or unneeded directories
#>       -  building 'DBI_1.1.2.tar.gz'
#>      
#> 
library(bigrquery)
library(DBI)
conn <- dbConnect(
  drv = bigquery(),
  project = bq_test_project(),
  dataset = "SHARE"
)
test_df <- data.frame(VAR1 = c(TRUE, FALSE, TRUE))
dbRemoveTable(conn, "TEST_DF")
dbWriteTable(conn, "TEST_DF", sqlData(conn, test_df))
dbReadTable(conn, "TEST_DF")
#> # A tibble: 3 x 1
#>    VAR1
#>   <int>
#> 1     0
#> 2     1
#> 3     1
Created on 2022-01-06 by the reprex package (v2.0.1)

Possible fix

#' @rdname DBI
#' @export
setMethod(
  "dbQuoteLiteral", c("BigQueryConnection", "logical"),
  function(conn, x, ...) {
    x <- as.character(x)
    x[is.na(x)] <- "NULL"
    SQL(x, names = names(x))
  }
)
remotes::install_github("r-dbi/dbi@v1.1.2")
#> Skipping install of 'DBI' from a github remote, the SHA1 (84e82d81) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(bigrquery)
library(DBI)
conn <- dbConnect(
  drv = bigquery(),
  project = bq_test_project(),
  dataset = "SHARE"
)
test_df <- data.frame(VAR1 = c(TRUE, FALSE, TRUE))
dbRemoveTable(conn, "TEST_DF")
dbWriteTable(conn, "TEST_DF", sqlData(conn, test_df))
dbReadTable(conn, "TEST_DF")
#> # A tibble: 3 x 1
#>   VAR1 
#>   <lgl>
#> 1 FALSE
#> 2 TRUE 
#> 3 TRUE
Created on 2022-01-06 by the reprex package (v2.0.1)
meztez pushed a commit to meztez/bigrquery that referenced this issue Jan 6, 2022
@hadley
Copy link
Member

hadley commented Nov 3, 2023

Rather more minimal reprex:

library(DBI)
con <- dbConnect(
  drv = bigrquery::bigquery(),
  project = bigrquery::bq_test_project(),
)
dbQuoteLiteral(con, c(FALSE, TRUE, NA))
#> <SQL> 0
#> <SQL> 1
#> <SQL> NULL

Created on 2023-11-03 with reprex v2.0.2

The values should be TRUE, FALSE, and NULL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#boolean_type

@hadley hadley added bug an unexpected problem or unintended behavior DBI 🗃️ labels Nov 3, 2023
hadley pushed a commit that referenced this issue Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior DBI 🗃️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants