Skip to content

Commit

Permalink
Translating double quotes to backticks for BigQuery. Part of #341
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Sep 6, 2023
1 parent 71e2d9d commit b7339ce
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Suggests:
testthat,
knitr,
rmarkdown,
stringr,
shiny,
shinydashboard
RoxygenNote: 7.2.3
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Changes:

3. Adding support for `IIF` for Synapse.

4. Translating double quotes to backticks for BigQuery.

SqlRender 1.15.2
================

Expand Down
1 change: 1 addition & 0 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ bigquery,NEWID(),GENERATE_UUID()
bigquery,"AS @(q[0-9]+)a","AS val_@a"
bigquery,"(@(q[0-9]+)a","(val_@a"
bigquery,"CHARINDEX(@a,@b)","STRPOS(@b,@a)"
bigquery,"\"","`"
sqlite,...@([0-9]+|y)a,xxx@a
sqlite,"AS drvd(@a)","AS drvd(<start>@a)"
sqlite,"<start>@a, @b)","<start>@a, <start>@b)"
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-replacement-patterns-file-format.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test_that("replacementPatterns.csv has valid format", {
lines <- readLines(system.file("csv", "replacementPatterns.csv", package = "SqlRender"))
for (line in lines) {
line_trim <- stringr::str_replace_all(line, '".[^"]+"', "")
comma_cnt <- stringr::str_count(line_trim, ",")
lineTrim <- gsub('"[^"]*"', "", gsub('\\\\"', "", line))
comma_cnt <- nchar(lineTrim) - nchar(gsub(",", "", lineTrim))
expect_equal(comma_cnt, 2, label = paste0("comma counts in string: ", line))
}
})
7 changes: 6 additions & 1 deletion tests/testthat/test-translate-bigquery.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test_that("translate sql server -> bigquery lowercase all but strings and variab
)
expect_equal_ignore_spaces(
sql,
"select x.y, 'Mixed Case String' from \"MixedCaseTableName.T\" where x.z=@camelCaseVar group by x.y"
"select x.y, 'Mixed Case String' from `MixedCaseTableName.T` where x.z=@camelCaseVar group by x.y"
)
})

Expand Down Expand Up @@ -544,3 +544,8 @@ test_that("translate sql server -> bigquery temp dplyr ... pattern", {
sql <- translate("SELECT * FROM table...1;", targetDialect = "bigquery")
expect_equal_ignore_spaces(sql, "select * from tablexxx1;")
})

test_that("translate sql server -> bigquery quotes", {
sql <- translate("SELECT \"a\" from t;", targetDialect = "bigquery")
expect_equal_ignore_spaces(sql, "select `a` from t;")
})

0 comments on commit b7339ce

Please sign in to comment.