Skip to content

in_schema does not work inside compute for remote table #297

@willshen99

Description

@willshen99

Package Version:

RPresto: 1.4.7
DBI: 1.2.3
dbplyr: 2.5.0

Issue 1

This is a similar issue to #275
When I ran

dplyr::copy_to(
  conn, 
  some_remote_table,
  name = in_schema('test', 'test_table')
)

I got an error

Error in vapply(x, unclass, character(1)) : values must be length 1,
 but FUN(X[[1]]) result is length 0

The issue comes from the unconditional unname(). Similar issue was also reported in dbplyr tidyverse/dbplyr#938

RPresto/R/dbplyr-src.R

Lines 275 to 276 in 3013b53

.compute_tbl_presto <- function(x, name, temporary = FALSE, ..., cte = FALSE) {
name <- unname(name)

Issue 1 Fix

I'm able to fix this by adding a conditional unname()

  if (is_bare_character(x) || dbplyr::is.ident(x) || dbplyr::is.sql(x)) {
    name <- unname(name)

Issue 2

After applying fix above, the compute continues but outputs the table in connection schema, not the schema specified in in_schema.

> dplyr::copy_to(
+   conn, 
+   some_remote_table,
+   name = in_schema('test', 'test_table')
+ )
  query FINISHED [============================================>----]  91% in  3s> 
dbExistsTable(conn, in_schema("test", "test_table"))
[1] FALSE
> dbExistsTable(conn, in_schema("default", "test_table"))
[1] TRUE

Issue 2 Fix

The issue comes from sqlCreateTableAs calls dbplyr_table_path to get target table name. The function dbplyr_table_path returns the last component of the table path (i.e. the name of the table). So the schema name is omitted. I was able to fix it by removing table_path_name call.

if (inherits(name, "dbplyr_table_path")) { # dbplyr >= 2.5.0
name <- dbplyr::table_path_name(name, con)

I'm happy to start a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions