Skip to content

Commit

Permalink
Adding support for IIF for Synapse. Fixes #342
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 af865dd commit 71e2d9d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changes:

2. The `render()`, `translate()`, and `translateSingleStatement()` functions now preserve attributes of the SQL object.

3. Adding support for `IIF` for Synapse.

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 @@ -1341,6 +1341,7 @@ synapse,CREATE INDEX @index_name ON #@table (@variable);,-- synapse does not sup
synapse,"CONSTRAINT @a DEFAULT GETDATE()",""
synapse,"DEFAULT GETDATE()",""
synapse,CREATE INDEX @index_name ON @table (@variable) WHERE @b;,CREATE INDEX @index_name ON @table (@variable);
synapse,"IIF(@condition, @whentrue, @whenfalse)","CASE WHEN @condition THEN @whentrue ELSE @whenfalse END"
sql server,.@([^\s]+)p2...@([0-9]+)p3,x@p2...@p3
sql server,.@([^\s]+)p2...@([0-9]+)p3,x@p2...@p3
sql server,...@([0-9]+|y)a,xxx@a
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-translate-synapse.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ test_that("translate sql server -> synapse CREATE INDEX with WHERE", {
sql <- translate("CREATE INDEX idx_a ON a(c1, c2) WHERE c3 <> '';", targetDialect = "synapse")
expect_equal_ignore_spaces(sql, "CREATE INDEX idx_a ON a(c1, c2);")
})

test_that("translate sql server -> synapse IIF", {
sql <- translate("SELECT IIF(a>b, 1, b) AS max_val FROM table;", targetDialect = "synapse")
expect_equal_ignore_spaces(sql, "SELECT CASE WHEN a>b THEN 1 ELSE b END AS max_val FROM table ;")
})

0 comments on commit 71e2d9d

Please sign in to comment.