Skip to content

Commit

Permalink
Fixed DuckDb translation of CAST(CONCATENATE(...) AS DATE). Fixes #369
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Jul 16, 2024
1 parent 3a6d8b3 commit 5f40748
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: SqlRender
Type: Package
Title: Rendering Parameterized SQL and Translation to Dialects
Version: 1.18.1
Date: 2024-06-04
Date: 2024-07-16s
Authors@R: c(
person("Martijn", "Schuemie", , "[email protected]", role = c("aut", "cre")),
person("Marc", "Suchard", role = c("aut"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changes:

1. Changing Spark translation of `DATEADD()` from `DATE_ADD()` to `DATEADD()` as required by some but not all Databricks instances.

Bugfixes:

1. Fixed DuckDb translation of `CAST(CONCATENATE(...) AS DATE)`.


SqlRender 1.18.0
================
Expand Down
3 changes: 3 additions & 0 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,9 @@ duckdb,"CONVERT(VARCHAR,@date,112)","STRFTIME(@date, '%Y%m%d')"
duckdb,GETDATE(),CURRENT_DATE
duckdb,"CONVERT(DATE, @a)","CAST(@a AS DATE)"
duckdb,"CAST('@a' AS DATE)","CAST(strptime('@a', '%Y%m%d') AS DATE)"
duckdb,"CAST('@a' + @b AS DATE)","CAST(strptime('@a' + @b, '%Y%m%d') AS DATE)"
duckdb,"CAST(@a + '@b' AS DATE)","CAST(strptime(@a + '@b', '%Y%m%d') AS DATE)"
duckdb,"CAST(CONCAT(@a) AS DATE)","CAST(strptime(CONCAT(@a), '%Y%m%d') AS DATE)"
duckdb,+ '@a',|| '@a'
duckdb,'@a' +,'@a' ||
duckdb,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) ||
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-translate-duckdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,11 @@ test_that("translate sql server -> duckdb NEWID", {
sql <- translate("SELECT NEWID()", targetDialect = "duckdb")
expect_equal_ignore_spaces(sql, "SELECT uuid()")
})

test_that("translate sql server -> DuckDB CONVERT(AS DATE) with literal from CONCAT", {
sql <- translate("CAST(CONCAT('2000', '0101') AS DATE);", targetDialect = "duckdb")
expect_equal_ignore_spaces(
sql,
"CAST(strptime(CONCAT('2000', '0101'), '%Y%m%d') AS DATE);"
)
})

0 comments on commit 5f40748

Please sign in to comment.