Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dbplyr (development version)

* Corrected translation of `stringr::str_like()` to use case-sensitive `LIKE` when argument `ignore_case` is set as `FALSE` (@edward-burn, #1488).
* Fixed overwrite flag in `copy_to()` to work when source is in the same DB as destination (@liudvikasakelis, #1535)
* Snowflake correctly translates `$` to `:` (@jsowder, #1608)
* `dbplyr_uncount()` now works with Redshift (@owenjonesuob, #1601).
Expand Down
12 changes: 8 additions & 4 deletions R/backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ base_scalar <- sql_translator(
str_trim = sql_str_trim,
str_c = sql_paste(""),
str_sub = sql_str_sub("SUBSTR"),
str_like = function(string, pattern, ignore_case = TRUE) {
check_bool(ignore_case)
# https://docs.getdbt.com/sql-reference/like is typically case sensitive (#1490)
str_like = function(string, pattern, ignore_case = FALSE) {
if (isTRUE(ignore_case)) {
sql_expr(!!string %LIKE% !!pattern)
cli_abort(c(
"Backend does not support case insensitive {.fn str_like}.",
i = "Set {.code ignore_case = FALSE} for case sensitive match.",
i = "Use {.fn tolower} on both arguments to achieve a case insensitive match."
))
} else {
cli::cli_abort("Backend only supports case insensitve {.fn str_like}.")
sql_expr(!!string %LIKE% !!pattern)
}
},

Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/backend-.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
Error in `x$id`:
! $ operator is invalid for atomic vectors

# can translate case insensitive like
# can only translate case sensitive str_like

Code
test_translate_sql(str_like(x, "abc", ignore_case = FALSE))
test_translate_sql(str_like(x, "abc", ignore_case = TRUE))
Condition
Error in `str_like()`:
! Backend only supports case insensitve `str_like()`.
! Backend does not support case insensitive `str_like()`.
i Set `ignore_case = FALSE` for case sensitive match.
i Use `tolower()` on both arguments to achieve a case insensitive match.

# default raw escapes translated correctly

Expand Down
13 changes: 10 additions & 3 deletions tests/testthat/test-backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ test_that("lead and lag translate n to integers", {

# strings -----------------------------------------------------------------

test_that("can translate case insensitive like", {
test_that("can only translate case sensitive str_like", {
local_con(simulate_dbi())
test_translate_sql(str_like(x, "abc"))
expect_snapshot(
expect_equal(
test_translate_sql(str_like(x, "abc", ignore_case = FALSE)),
sql("`x` LIKE 'abc'")
)
expect_equal(
test_translate_sql(str_like(x, "ABC", ignore_case = FALSE)),
sql("`x` LIKE 'ABC'")
)
expect_snapshot(
test_translate_sql(str_like(x, "abc", ignore_case = TRUE)),
error = TRUE
)
})
Expand Down
Loading