DyfanJones / RAthena

Connect R to Athena using Boto3 SDK (DBI Interface)
https://dyfanjones.github.io/RAthena/
Other
35 stars 6 forks source link

paste not translated correctly #65

Closed OssiLehtinen closed 4 years ago

OssiLehtinen commented 4 years ago

Issue Description

Doing something like

tbl(con, "table) %>% mutate(new_col = paste(col1, col2))

fails with an error about a missing fucntion (concat_ws).

I think we need to add paste (and paste0) to sql_translate_env's athtena specific translations.

Adding lines:

      paste = sql_prefix("CONCAT"),
      paste0 = sql_prefix("CONCAT"),

to sql_translator under sql_translate_env.AthenaConnection should do the trick.

DyfanJones commented 4 years ago

Currently on holiday, will look into this when I am back :)

OssiLehtinen commented 4 years ago

Have a good one!

DyfanJones commented 4 years ago

The problem with concat for paste, is that is doesn't offer a different value for sep. For paste0 this would work perfectly :D

DyfanJones commented 4 years ago

Should be able to support paste with option to change sep the helper function:

athena_paste <- function(..., sep = " ", con) {
  escape <- pkg_method("escape", "dbplyr")
  sql <- pkg_method("sql", "dplyr")
  sep <- paste0('||', sep, '||')
  pieces <- vapply(list(...), escape, con = con,collapse = sep, character(1))
  sql(paste(pieces))
}
DyfanJones commented 4 years ago

PR #66 seems to be fixed paste issue with athena