Skip to content

Commit

Permalink
CAST(@A AS DATE) handling for Snowflake - fixes #372
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Aug 8, 2024
1 parent 4b3cd01 commit d935545
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,10 @@ snowflake,"HASHBYTES('MD5',@a)","MD5(@a)"
snowflake,"CONVERT(VARBINARY, @a, 1)","CAST(CONCAT('x', @a) AS BIT(32))"
snowflake,"CONVERT(DATE, @a)","TO_DATE(@a, 'yyyymmdd')"
snowflake,"CONVERT(VARCHAR,@date,112)","TO_CHAR(@date, 'YYYYMMDD')"
snowflake,"CAST('@a' AS DATE)","TO_DATE('@a', 'YYYYMMDD')"
snowflake,"CAST('@a' + @b AS DATE)","TO_DATE('@a' + @b, 'YYYYMMDD')"
snowflake,"CAST(@a + '@b' AS DATE)","TO_DATE(@a + '@b', 'YYYYMMDD')"
snowflake,"CAST(CONCAT(@a) AS DATE)","TO_DATE(CONCAT(@a), 'YYYYMMDD')"
snowflake,GETDATE(),CURRENT_DATE
snowflake,+ '@a',|| '@a'
snowflake,'@a' +,'@a' ||
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-translate-snowflake.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,9 @@ test_that("translate sql server -> snowflake bitwise and", {
expect_equal_ignore_spaces(sql, "SELECT BITAND((a+b) , c/123) FROM table ;")
})

test_that("translate sql server -> Snowflake CAST(AS DATE)", {
sql <- translate("CAST('20000101' AS DATE);", targetDialect = "snowflake")
expect_equal_ignore_spaces(sql, "TO_DATE('20000101', 'YYYYMMDD');")
})

# rJava::J('org.ohdsi.sql.SqlTranslate')$setReplacementPatterns('inst/csv/replacementPatterns.csv')

0 comments on commit d935545

Please sign in to comment.