Skip to content

Commit

Permalink
Fix glue_sql2() uses (#1352)
Browse files Browse the repository at this point in the history
* Fix `enpar()`

* Fix snowflake periods translations

* Add some more tests for `[[` translation
  • Loading branch information
mgirlich authored Aug 16, 2023
1 parent 244ea87 commit ba01847
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
14 changes: 7 additions & 7 deletions R/backend-snowflake.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,25 @@ sql_translation.Snowflake <- function(con) {
sql_expr(EXTRACT("year", !!x))
},
seconds = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} second'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} second'")
},
minutes = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} minute'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} minute'")
},
hours = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} hour'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} hour'")
},
days = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} day'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} day'")
},
weeks = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} week'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} week'")
},
months = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} month'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} month'")
},
years = function(x) {
glue_sql2(sql_current_con(), "INTERVAL '{x} year'")
glue_sql2(sql_current_con(), "INTERVAL '{.val x} year'")
},
# https://docs.snowflake.com/en/sql-reference/functions/date_trunc.html
floor_date = function(x, unit = "seconds") {
Expand Down
2 changes: 1 addition & 1 deletion R/translate-sql-conditional.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ enpar <- function(x, tidy = TRUE, env = NULL) {
x_sql <- eval_bare(x, env = env)
}
if (quo_is_call(x)) {
glue_sql2(sql_current_con(), "({x_sql})")
glue_sql2(sql_current_con(), "({.val x_sql})")
} else {
x_sql
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ test_that("can translate subsetting", {
local_con(simulate_dbi())
expect_equal(test_translate_sql(a$b), sql("`a`.`b`"))
expect_equal(test_translate_sql(a[["b"]]), sql("`a`.`b`"))
expect_equal(test_translate_sql(f(a)[["b"]]), sql("f(`a`).`b`"))

expect_equal(test_translate_sql(a[["b"]][[1]]), sql('`a`.`b`[1]'))
expect_snapshot(error = TRUE, {
test_translate_sql(a[[x]])
test_translate_sql(a[[TRUE]])
})
})


Expand Down

0 comments on commit ba01847

Please sign in to comment.