You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
str_detect and str_replace not treating periods (.) same in dbplyr with a snowlfake connection
str_replace() recognizes "\\." as looking for and replacing the period character, but str_detect() does not recognize it the same.
Seems to be a translation issue, when looking at the show_query details for both
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.3.3#> Warning: package 'ggplot2' was built under R version 4.3.3#> Warning: package 'tidyr' was built under R version 4.3.3#> Warning: package 'readr' was built under R version 4.3.3#> Warning: package 'dplyr' was built under R version 4.3.2#> Warning: package 'stringr' was built under R version 4.3.3
library(DBI)
#> Warning: package 'DBI' was built under R version 4.3.3
library(dbplyr)
#> Warning: package 'dbplyr' was built under R version 4.3.3#> #> Attaching package: 'dbplyr'#> The following objects are masked from 'package:dplyr':#> #> ident, sqlcon<-
dbConnect(
odbc::odbc(),
driver=*removed*,
uid=*removed*,
pwd=*removed*,
server=*removed*,
port=*removed*,
database=*removed*,
Warehouse=*removed*,
schema=*removed*,
)
tmp<-
copy_to(
con,
tibble(var= c("string.period", "string_no_period")),
name="test",
overwrite=TRUE
)
# expected resultstmp %>%
mutate(across(var, ~ str_replace(.x, "\\.", "FILLER"), .names="var_new"))
#> # Source: SQL [2 x 2]#> # Database: Snowflake 8.8.4[philden@Snowflake/HEALTHVERITY]#> var var_new #> <chr> <chr> #> 1 string.period stringFILLERperiod#> 2 string_no_period string_no_period# not detecting as expectedtmp %>%
mutate(across(var, ~ str_detect(.x, "\\."), .names="var_new"))
#> # Source: SQL [2 x 2]#> # Database: Snowflake 8.8.4[philden@Snowflake/HEALTHVERITY]#> var var_new#> <chr> <lgl> #> 1 string.period TRUE #> 2 string_no_period TRUEtmp %>%
mutate(across(var, ~ str_replace(.x, "\\.", "FILLER"))) %>%
show_query()
#> <SQL>#> SELECT REGEXP_REPLACE("var", '\\.', 'FILLER', 1.0, 1.0) AS "var"#> FROM "test"# seems to be missing a \ based on the abovetmp %>%
mutate(across(var, ~ str_detect(.x, "\\."))) %>%
show_query()
#> <SQL>#> SELECT ("var") REGEXP ('.*' || '\.' || '.*') AS "var"#> FROM "test"# seems to require double escapetmp %>%
mutate(across(var, ~ str_detect(.x, "\\\\."))) %>% show_query()
#> <SQL>#> SELECT ("var") REGEXP ('.*' || '\\.' || '.*') AS "var"#> FROM "test"# expected resulttmp %>%
mutate(across(var, ~ str_detect(.x, "\\\\."), .names="var_new"))
#> # Source: SQL [2 x 2]#> # Database: Snowflake 8.8.4[philden@Snowflake/HEALTHVERITY]#> var var_new#> <chr> <lgl> #> 1 string.period TRUE #> 2 string_no_period FALSE
str_detect and str_replace not treating periods (.) same in dbplyr with a snowlfake connection
str_replace() recognizes "\\." as looking for and replacing the period character, but str_detect() does not recognize it the same.
Seems to be a translation issue, when looking at the show_query details for both
Created on 2024-03-05 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: