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

compute(...) breaks with DBI connection when temporary=FALSE and name contains schema (in_schema(...) or DBI::Id()) #595

Closed
mszefler opened this issue Feb 9, 2021 · 0 comments · Fixed by #596

Comments

@mszefler
Copy link

mszefler commented Feb 9, 2021

Calls to compute(..., name=in_schema(...), temporary=FALSE) fail because connection object is not passed to as.sql(name) call in sql_query_save.DBIConnection. Similarly, when name=DBI::Id(..) same issue occurs.

library(dbplyr)
library(dplyr)
library(magrittr)
con <- ...  # This is DBI / RPostgres connection
DBI::dbExecute(con, "CREATE SCHEMA IF NOT EXISTS foo")  
DBI::dbWriteTable(con,DBI::Id(schema='foo',table='bar'),tibble::tibble(x=1:2), overwrite=TRUE, append=FALSE)
tbl(con, in_schema('foo','bar')) %>% compute(in_schema('foo','baz'), temporary=FALSE)

Note frames 12,16,17 in the following stack trace:

Error in escape(x$schema, con = con): argument "con" is missing, with no default
Traceback:

1. tbl(con, in_schema("foo", "bar")) %>% compute(in_schema("foo", 
 .     "baz"), temporary = FALSE)
2. compute(., in_schema("foo", "baz"), temporary = FALSE)
3. compute.tbl_sql(., in_schema("foo", "baz"), temporary = FALSE)
4. db_compute(x$src$con, name, sql, temporary = temporary, unique_indexes = unique_indexes, 
 .     indexes = indexes, analyze = analyze, ...)
5. db_compute.DBIConnection(x$src$con, name, sql, temporary = temporary, 
 .     unique_indexes = unique_indexes, indexes = indexes, analyze = analyze, 
 .     ...)
6. dbplyr_save_query(con, sql, table, temporary = temporary)
7. dbplyr_fallback(con, "db_save_query", ...)
8. eval_bare(expr((!!fun)(con, ...)))
9. db_save_query.DBIConnection(con, ...)
10. sql_query_save(con, sql, name, temporary = temporary, ...)
11. sql_query_save.DBIConnection(con, sql, name, temporary = temporary, 
  .     ...)
12. build_sql("CREATE ", if (temporary) sql("TEMPORARY "), "TABLE \n", 
  .     as.sql(name), " AS ", sql, con = con)
13. purrr::map_chr(enexprs(...), escape_expr, con = con)
14. .f(.x[[i]], ...)
15. eval_bare(x, .env)
16. as.sql(name)
17. as.sql.dbplyr_schema(name)
18. ident_q(paste0(escape(x$schema, con = con), ".", escape(x$table, 
  .     con = con)))
19. c_character(...)
20. paste0(escape(x$schema, con = con), ".", escape(x$table, con = con))
21. escape(x$schema, con = con)
R version 4.0.2 (2020-06-22)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: OpenShift

Matrix products: default
BLAS/LAPACK: /SCRATCH/szeflerm/.conda/envs/mybase/envs/osa-conda-R/lib/libopenblasp-r0.3.10.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] here_1.0.1        digest_0.6.27     codetools_0.2-18  pryr_0.1.4       
 [5] rjson_0.2.20      forcats_0.5.1     stringr_1.4.0     purrr_0.3.4      
 [9] readr_1.4.0       tidyr_1.1.2       tibble_3.0.6      ggplot2_3.3.3    
[13] tidyverse_1.3.0   haven_2.3.1       lubridate_1.7.9.2 jsonlite_1.7.2   
[17] dplyr_1.0.4       dbplyr_2.1.0      magrittr_2.0.1   

loaded via a namespace (and not attached):
 [1] httr_1.4.2          bit64_4.0.5         modelr_0.1.8       
 [4] assertthat_0.2.1    highr_0.8           blob_1.2.1         
 [7] renv_0.12.0         cellranger_1.1.0    yaml_2.2.1         
[10] pillar_1.4.7        backports_1.2.1     glue_1.4.2         
[13] uuid_0.1-4          rvest_0.3.6         colorspace_2.0-0   
[16] htmltools_0.5.1.1   pkgconfig_2.0.3     broom_0.7.4        
[19] RPostgres_1.3.1     config_0.3.1        scales_1.1.1       
[22] processx_3.4.5      generics_0.1.0      ellipsis_0.3.1     
[25] cachem_1.0.3        withr_2.4.0         repr_1.1.3         
[28] cli_2.2.0           crayon_1.3.4        readxl_1.3.1       
[31] evaluate_0.14       ps_1.5.0            fs_1.5.0           
[34] fansi_0.4.2         xml2_1.3.2          tools_4.0.2        
[37] hms_1.0.0           lifecycle_0.2.0     autocred_0.0.0.9000
[40] munsell_0.5.0       reprex_1.0.0        sodium_1.1         
[43] callr_3.5.1         compiler_4.0.2      rlang_0.4.10       
[46] grid_4.0.2          pbdZMQ_0.3-4        IRkernel_1.1.1     
[49] rstudioapi_0.13     rappdirs_0.3.1      rmarkdown_2.6      
[52] base64enc_0.1-3     gtable_0.3.0        DBI_1.1.1          
[55] R6_2.5.0            knitr_1.31          keyring_1.1.0      
[58] fastmap_1.1.0       bit_4.0.4           utf8_1.1.4         
[61] filelock_1.0.2      rprojroot_2.0.2     stringi_1.5.3      
[64] IRdisplay_1.0       Rcpp_1.0.6          vctrs_0.3.6        
[67] xfun_0.20           tidyselect_1.1.0 
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 a pull request may close this issue.

1 participant