From 9baf213e0e0ff538931c8c22d154d9d43eaca13e Mon Sep 17 00:00:00 2001 From: owenjonesuob <21007837+owenjonesuob@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:42:27 +0100 Subject: [PATCH 1/2] Use get_src_tbl_names to fetch Ids in all cases --- R/dm_from_con.R | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/R/dm_from_con.R b/R/dm_from_con.R index d2269efa4..9bf95a8b7 100644 --- a/R/dm_from_con.R +++ b/R/dm_from_con.R @@ -93,18 +93,14 @@ dm_from_con <- function(con = NULL, table_names = NULL, learn_keys = NULL, ) } - if (is_null(table_names)) { - src_tbl_names <- get_src_tbl_names(src, ..., names = .names) - } else { - src_tbl_names <- table_names - } + tbl_ids <- get_src_tbl_names(src, ..., names = .names) - nms <- purrr::map_chr(src_tbl_names, ~ .x@name[["table"]]) + # Fetch only the tbls which were specifically requested + if (!is.null(table_names)) { + tbl_ids <- tbl_ids[table_names] + } - tbls <- - set_names(src_tbl_names, nms) %>% - quote_ids(con) %>% - map(possibly(tbl, NULL), src = src) + tbls <- map(tbl_ids, possibly(tbl, NULL), src = src) bad <- map_lgl(tbls, is_null) if (any(bad)) { From 315ecc2d73dd72c3cb693993eef24375aa3cc39f Mon Sep 17 00:00:00 2001 From: owenjonesuob <21007837+owenjonesuob@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:41:57 +0100 Subject: [PATCH 2/2] Warn if specified table is not available --- R/dm_from_con.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/dm_from_con.R b/R/dm_from_con.R index 9bf95a8b7..f8adcc11f 100644 --- a/R/dm_from_con.R +++ b/R/dm_from_con.R @@ -97,7 +97,13 @@ dm_from_con <- function(con = NULL, table_names = NULL, learn_keys = NULL, # Fetch only the tbls which were specifically requested if (!is.null(table_names)) { - tbl_ids <- tbl_ids[table_names] + not_found <- setdiff(table_names, names(tbl_ids)) + + if (length(not_found) > 0) { + cli::cli_warn("Could not find table{?s}: {not_found}") + } + + tbl_ids <- tbl_ids[intersect(table_names, names(tbl_ids))] } tbls <- map(tbl_ids, possibly(tbl, NULL), src = src)