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

Can no longer convert dbplyr_table_ident to character #1381

Closed
catalamarti opened this issue Oct 26, 2023 · 3 comments
Closed

Can no longer convert dbplyr_table_ident to character #1381

catalamarti opened this issue Oct 26, 2023 · 3 comments

Comments

@catalamarti
Copy link

This code worked with dbplyr 2.3.4 and no longer works for dbplyr 2.4.0

db <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
DBI::dbWriteTable(db, "x", dplyr::tibble(a = 1))
tab <- dplyr::tbl(db, "x")
as.character(tab[[2]]$x)
#> Error in `as.character()`:
#> ! Can't convert `x` <dbplyr_table_ident> to <character>.
#> Backtrace:
#>      ▆
#>   1. ├─base::as.character(tab[[2]]$x)
#>   2. ├─vctrs:::as.character.vctrs_vctr(tab[[2]]$x)
#>   3. │ └─vctrs::vec_cast(x, character())
#>   4. └─vctrs (local) `<fn>`()
#>   5.   └─vctrs::vec_default_cast(...)
#>   6.     ├─base::withRestarts(...)
#>   7.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>   8.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>   9.     └─vctrs::stop_incompatible_cast(...)
#>  10.       └─vctrs::stop_incompatible_type(...)
#>  11.         └─vctrs:::stop_incompatible(...)
#>  12.           └─vctrs:::stop_vctrs(...)
#>  13.             └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

Created on 2023-10-26 with reprex v2.0.2

Not sure if this was intentional or not?

FYI:
https://github.com/darwin-eu-dev/CDMConnector/issues/321
@ablack3 @edward-burn

@mgirlich
Copy link
Collaborator

This is intentional but maybe this should get a more helpful error message. The question is what you want to achieve with as.character(). Should the table identifier be escaped? Then you need a connection to escape it correctly. Do you want the name of the table or do you also care about the schema it might be in?
Also it is not a good idea to access the internals with something like tab[[2]]$x. Instead you should use remote_table() (to get the table identifier including the schema etc) and remote_name() (to get the table name. Note this might be NULL when the table name is already escaped).

@catalamarti
Copy link
Author

@ablack3 remote_name should be what we need.
Thank you @mgirlich

@mgirlich
Copy link
Collaborator

Happy to help 😄

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

No branches or pull requests

2 participants