Skip to content

Commit

Permalink
Casting interval to int on DuckDb. Fixes OHDSI/DatabaseConnector#241
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Jul 4, 2023
1 parent 45ee2c5 commit d841ea7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SqlRender
Type: Package
Title: Rendering Parameterized SQL and Translation to Dialects
Version: 1.15.1
Date: 2023-06-29
Version: 1.15.2
Date: 2023-07-04
Authors@R: c(
person("Martijn", "Schuemie", , "schuemie@ohdsi.org", role = c("aut", "cre")),
person("Marc", "Suchard", role = c("aut"))
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
SqlRender 1.15.2
================

Bugfixes:

1. Fixing translation of `DATEADD()` for DuckDB when number to add is not an integer.


SqlRender 1.15.1
================

Expand Down
24 changes: 12 additions & 12 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,18 @@ duckdb,TRY_CAST(@a),CAST(@a)
duckdb,"IIF(@condition, @whentrue, @whenfalse)","CASE WHEN @condition THEN @whentrue ELSE @whenfalse END"
duckdb,"ROUND(@a,@b)","ROUND(CAST(@a AS NUMERIC),@b)"
duckdb,"HASHBYTES('MD5',@a)","MD5(@a)"
duckdb,"DATEADD(second,@seconds,@datetime)",(@datetime + TO_SECONDS(@seconds))
duckdb,"DATEADD(minute,@minutes,@datetime)",(@datetime + TO_MINUTES(@minutes))
duckdb,"DATEADD(hour,@hours,@datetime)",(@datetime + TO_HOURS(@hours))
duckdb,"DATEADD(d,@days,@date)",(@date + TO_DAYS(@days))
duckdb,"DATEADD(dd,@days,@date)",(@date + TO_DAYS(@days))
duckdb,"DATEADD(day,@days,@date)",(@date + TO_DAYS(@days))
duckdb,"DATEADD(m,@months,@date)",(@date + TO_MONTHS(@months))
duckdb,"DATEADD(mm,@months,@date)",(@date + TO_MONTHS(@months))
duckdb,"DATEADD(month,@months,@date)",(@date + TO_MONTHS(@months))
duckdb,"DATEADD(yy,@years,@date)",(@date + TO_YEAR(@years))
duckdb,"DATEADD(yyyy,@years,@date)",(@date + TO_YEAR(@years))
duckdb,"DATEADD(year,@years,@date)",(@date + TO_YEAR(@years))
duckdb,"DATEADD(second,@seconds,@datetime)",(@datetime + TO_SECONDS(CAST(@seconds AS INTEGER)))
duckdb,"DATEADD(minute,@minutes,@datetime)",(@datetime + TO_MINUTES(CAST(@minutes AS INTEGER)))
duckdb,"DATEADD(hour,@hours,@datetime)",(@datetime + TO_HOURS(CAST(@hours AS INTEGER)))
duckdb,"DATEADD(d,@days,@date)",(@date + TO_DAYS(CAST(@days AS INTEGER)))
duckdb,"DATEADD(dd,@days,@date)",(@date + TO_DAYS(CAST(@days AS INTEGER)))
duckdb,"DATEADD(day,@days,@date)",(@date + TO_DAYS(CAST(@days AS INTEGER)))
duckdb,"DATEADD(m,@months,@date)",(@date + TO_MONTHS(CAST(@months AS INTEGER)))
duckdb,"DATEADD(mm,@months,@date)",(@date + TO_MONTHS(CAST(@months AS INTEGER)))
duckdb,"DATEADD(month,@months,@date)",(@date + TO_MONTHS(CAST(@months AS INTEGER)))
duckdb,"DATEADD(yy,@years,@date)",(@date + TO_YEAR(CAST(@years AS INTEGER)))
duckdb,"DATEADD(yyyy,@years,@date)",(@date + TO_YEAR(CAST(@years AS INTEGER)))
duckdb,"DATEADD(year,@years,@date)",(@date + TO_YEAR(CAST(@years AS INTEGER)))
duckdb,INTERVAL'@(-?[0-9]+)a.0 @b',INTERVAL'@a @b'
duckdb,"DATEDIFF(d,@start, @end)","(CONVERT(DATE, @end) - CAST(@start AS DATE))"
duckdb,"DATEDIFF(dd,@start, @end)",(CAST(@end AS DATE) - CAST(@start AS DATE))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.ohdsi.sql</groupId>
<artifactId>SqlRender</artifactId>
<packaging>jar</packaging>
<version>1.15.1-SNAPSHOT</version>
<version>1.15.2-SNAPSHOT</version>
<name>SqlRender</name>
<scm>
<connection>scm:git:https://github.com/OHDSI/SqlRender</connection>
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-translate-duckdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_that("translate sql server -> DuckDB add months", {
sql <- translate("DATEADD(mm,2,date)", targetDialect = "duckdb")
expect_equal_ignore_spaces(
sql,
"(date + TO_MONTHS(2))"
"(date + TO_MONTHS(CAST(2 AS INTEGER)))"
)
})

Expand Down Expand Up @@ -224,6 +224,6 @@ test_that("translate sql server -> DuckDB add days with period", {
sql <- translate("DATEADD(DAY, -2.0, date)", targetDialect = "duckdb")
expect_equal_ignore_spaces(
sql,
"(date + TO_DAYS(-2.0))"
"(date + TO_DAYS(CAST(-2.0 AS INTEGER)))"
)
})

0 comments on commit d841ea7

Please sign in to comment.