Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-burn committed Apr 5, 2024
1 parent 127a932 commit 43f9fb5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dbplyr (development version)
* The translation of `stringr::str_like()` now defaults to use case-sensitive LIKE when argument `ignore_case` is set as FALSE instead of when this argument is set as TRUE.(@edward-burn, #1488)

# dbplyr 2.5.0

Expand Down
3 changes: 2 additions & 1 deletion R/backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,13 @@ base_scalar <- sql_translator(
str_trim = sql_str_trim,
str_c = sql_paste(""),
str_sub = sql_str_sub("SUBSTR"),
# https://docs.getdbt.com/sql-reference/like is typically case sensitive
str_like = function(string, pattern, ignore_case = TRUE) {
if (isTRUE(ignore_case)) {
cli_abort(c(
"Backend does not support case insensitve {.fn str_like}.",
i = "Set ignore_case = FALSE for case sensitive match.",
i = "Note, using `tolower()` to cast string and pattern to lower case would also achieve a case insenitive match."
i = "Or use `tolower()` on both arguments to achieve a case insensitive match."
))
} else {
sql_expr(!!string %LIKE% !!pattern)
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-backend-.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ 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", ignore_case = FALSE))
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

0 comments on commit 43f9fb5

Please sign in to comment.