Skip to content

Commit

Permalink
Add paste and paste0 translation
Browse files Browse the repository at this point in the history
  • Loading branch information
jarodmeng committed Apr 26, 2024
1 parent dd2232e commit 804c29a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# RPresto 1.4.6.9000

* Fixed a bug whereby nested CTEs result in nested WITH. (#261)
* Fixed `paste()` and `paste0()` translation (#266)

# RPresto 1.4.6

Expand Down
2 changes: 2 additions & 0 deletions R/dbplyr-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ presto_window_functions <- function() {
}
return(dbplyr::sql_translator(
.parent = dbplyr::base_win,
paste = dbplyr::sql_paste_infix(" ", "||", function(x) dbplyr::sql_expr(cast(!!x %as% varchar))),
paste0 = dbplyr::sql_paste_infix("", "||", function(x) dbplyr::sql_expr(cast(!!x %as% varchar))),
all = dbplyr::win_recycled("bool_and"),
any = dbplyr::win_recycled("bool_or"),
n_distinct = dbplyr::win_absent("n_distinct"),
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-translate_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,22 @@ with_locale(test.locale(), test_that)("first(), last(), and nth() work", {
dbplyr::sql('NTH_VALUE("x", 2) IGNORE NULLS OVER (ORDER BY "y")')
)
})

with_locale(test.locale(), test_that)("paste() works", {
s <- setup_mock_dplyr_connection()[["db"]]

expect_equal(
dbplyr::translate_sql(paste(a, b, c), con = s$con),
dbplyr::sql("\"a\" || ' ' || \"b\" || ' ' || \"c\"")
)

expect_equal(
dbplyr::translate_sql(paste(a, b, c, sep = "-"), con = s$con),
dbplyr::sql("\"a\" || '-' || \"b\" || '-' || \"c\"")
)

expect_equal(
dbplyr::translate_sql(paste0(a, b, c), con = s$con),
dbplyr::sql("\"a\" || \"b\" || \"c\"")
)
})

0 comments on commit 804c29a

Please sign in to comment.