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

Use default schema in dm_learn_from_db() #1448

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mgirlich
Copy link
Contributor

@mgirlich mgirlich commented Sep 2, 2022

Fixes #1440.
There already is a test
test_that("Standard learning from MSSQL (schema 'dbo') or Postgres (schema 'public') and get_src_tbl_names() works?"
but it seems it doesn't work correct. I had a quick look at it but wasn't quite sure how to fix it. @krlmlr maybe you want to have a look at the test.

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Thanks.

@TSchiefer: Could you please help with the tests?

Comment on lines +190 to +194
ident_q <- function(...) {
# to avoid dependency on dbplyr define `ident_q()` here (not exported from dplyr)
structure(c(...), class = c("ident_q", "ident", "character"))
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're using dbplyr::ident_q() elsewhere.

schema_mariadb <- function(con, schema) {
if (is_null(schema)) {
schema <- sql("database()")
schema <- ident_q("database()")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the advantage of using ident_q() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works better with %in% !!...:

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_postgres(con, schema)
} else if (is_mariadb(src)) {
# MariaDB
schema_mariadb(con, schema)
Copy link
Collaborator

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?

@krlmlr
Copy link
Collaborator

krlmlr commented Sep 20, 2022

@mgirlich: Would you like to do another iteration?

@krlmlr
Copy link
Collaborator

krlmlr commented Aug 14, 2023

Thank you for your patience. I think we want schema = NULL to get all tables from all schemas in dm. It's way easier to change the documentation 😏 .

@krlmlr krlmlr closed this Aug 14, 2023
@krlmlr
Copy link
Collaborator

krlmlr commented Aug 20, 2023

Scratch that, schema = NULL will do all schemas, schema = NA will do the "sensible" thing depending on the database. I still might go with a different implementation.

@krlmlr krlmlr reopened this Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

dm_from_con() does not default to schema = "public" for Postgres
2 participants