-
Notifications
You must be signed in to change notification settings - Fork 48
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
Use default schema in dm_learn_from_db()
#1448
base: main
Are you sure you want to change the base?
Changes from 1 commit
4f7b4d7
5fa9ad5
a534124
f89bf40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,33 +115,25 @@ repair_table_names_for_db <- function(table_names, temporary, con, schema = NULL | |
} | ||
|
||
get_src_tbl_names <- function(src, schema = NULL, dbname = NULL) { | ||
schema <- check_schema(src, schema) | ||
|
||
if (!is_mssql(src) && !is_postgres(src) && !is_mariadb(src)) { | ||
warn_if_arg_not(schema, only_on = c("MSSQL", "Postgres", "MariaDB")) | ||
warn_if_arg_not(dbname, only_on = "MSSQL") | ||
return(set_names(src_tbls(src))) | ||
} | ||
|
||
con <- con_from_src_or_con(src) | ||
|
||
if (!is.null(schema)) { | ||
check_param_class(schema, "character") | ||
check_param_length(schema) | ||
} | ||
|
||
if (is_mssql(src)) { | ||
# MSSQL | ||
schema <- schema_mssql(con, schema) | ||
dbname_sql <- dbname_mssql(con, dbname) | ||
names_table <- get_names_table_mssql(con, dbname_sql) | ||
dbname <- names(dbname_sql) | ||
} else if (is_postgres(src)) { | ||
# Postgres | ||
schema <- schema_postgres(con, schema) | ||
dbname <- warn_if_arg_not(dbname, only_on = "MSSQL") | ||
names_table <- get_names_table_postgres(con) | ||
} else if (is_mariadb(src)) { | ||
# MariaDB | ||
schema <- schema_mariadb(con, schema) | ||
dbname <- warn_if_arg_not(dbname, only_on = "MSSQL") | ||
names_table <- get_names_table_mariadb(con) | ||
} | ||
|
@@ -155,6 +147,31 @@ get_src_tbl_names <- function(src, schema = NULL, dbname = NULL) { | |
deframe() | ||
} | ||
|
||
check_schema <- function(src, schema) { | ||
if (!is_mssql(src) && !is_postgres(src) && !is_mariadb(src)) { | ||
warn_if_arg_not(schema, only_on = c("MSSQL", "Postgres", "MariaDB")) | ||
return(schema) | ||
} | ||
|
||
con <- con_from_src_or_con(src) | ||
|
||
if (!is.null(schema)) { | ||
check_param_class(schema, "character") | ||
check_param_length(schema) | ||
} | ||
|
||
if (is_mssql(src)) { | ||
# MSSQL | ||
schema_mssql(con, schema) | ||
} else if (is_postgres(src)) { | ||
# Postgres | ||
schema_postgres(con, schema) | ||
} else if (is_mariadb(src)) { | ||
# MariaDB | ||
schema_mariadb(con, schema) | ||
} | ||
} | ||
|
||
# `schema_*()` : default schema if NULL, otherwise unchanged | ||
schema_mssql <- function(con, schema) { | ||
if (is_null(schema)) { | ||
|
@@ -170,9 +187,14 @@ schema_postgres <- function(con, schema) { | |
schema | ||
} | ||
|
||
ident_q <- function(...) { | ||
# to avoid dependency on dbplyr define `ident_q()` here (not exported from dplyr) | ||
structure(c(...), class = c("ident_q", "ident", "character")) | ||
} | ||
|
||
Comment on lines
+237
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're using |
||
schema_mariadb <- function(con, schema) { | ||
if (is_null(schema)) { | ||
schema <- sql("database()") | ||
schema <- ident_q("database()") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the advantage of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works better with library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)
lf <- lazy_frame(x = 1)
lf %>% filter(x %in% !!sql("1"))
#> <SQL>
#> SELECT *
#> FROM `df`
#> WHERE (`x` IN 1)
lf %>% filter(x %in% !!ident_q("1"))
#> <SQL>
#> SELECT *
#> FROM `df`
#> WHERE (`x` IN (1)) Created on 2022-09-05 with reprex v2.0.2 |
||
} | ||
schema | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, we're using a filter with
DATABASE()
elsewhere. Do we still need that?