Skip to content

Commit e2315f2

Browse files
Admin_mschuemiAdmin_mschuemi
Admin_mschuemi
authored and
Admin_mschuemi
committed
On DataBricks, a translation of DATEADD() now returns a DATE if the input was a DATE, to be consistent with other platforms. Updating copyright year
1 parent a0dad78 commit e2315f2

19 files changed

+45
-19
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SqlRender
22
Type: Package
33
Title: Rendering Parameterized SQL and Translation to Dialects
4-
Version: 1.19.1
5-
Date: 2024-11-29
4+
Version: 1.19.2
5+
Date: 2025-01-30
66
Authors@R: c(
77
person("Martijn", "Schuemie", , "[email protected]", role = c("aut", "cre")),
88
person("Marc", "Suchard", role = c("aut"))

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
SqlRender 1.19.2
2+
================
3+
4+
Bugfixes:
5+
6+
1. On DataBricks, a translation of `DATEADD()` now returns a `DATE` if the input was a `DATE`, to be consistent with other platforms. (Requires input field name to end with '_date')
7+
8+
19
SqlRender 1.19.1
210
================
311

R/HelperFunctions.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @file HelperFunctions.R
22
#
3-
# Copyright 2024 Observational Health Data Sciences and Informatics
3+
# Copyright 2025 Observational Health Data Sciences and Informatics
44
#
55
# This file is part of SqlRender
66
#

R/RenderSql.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @file RenderSql
22
#
3-
# Copyright 2024 Observational Health Data Sciences and Informatics
3+
# Copyright 2025 Observational Health Data Sciences and Informatics
44
#
55
# This file is part of SqlRender
66
#

R/ShinyApps.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Observational Health Data Sciences and Informatics
1+
# Copyright 2025 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of SqlRender
44
#

R/SparkSql.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Observational Health Data Sciences and Informatics
1+
# Copyright 2025 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of SqlRender
44
#

R/SqlRender.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Observational Health Data Sciences and Informatics
1+
# Copyright 2025 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of SqlRender
44
#

SqlRender.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 172808d3-be61-43ad-8098-ce800f3e8439
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

extras/PackageMaintenance.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Observational Health Data Sciences and Informatics
1+
# Copyright 2025 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of SqlRender
44
#

inst/csv/replacementPatterns.csv

+2
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ spark,UPDATE STATISTICS @a;,
11441144
spark,"SELECT @columns FROM (@a) @x,(@b) @y;","SELECT @columns FROM (@a) @x cross join (@b) @y;"
11451145
spark,"ALTER TABLE @table ADD COLUMN @([\w_-]+)column @type DEFAULT @default;","ALTER TABLE @table ADD COLUMN @column @type; \nALTER TABLE @table SET TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported'); \nALTER TABLE @table ALTER COLUMN @column SET DEFAULT @default;"
11461146
spark,"CAST(@a AS DATE)","IF(try_cast(@a AS DATE) IS NULL, to_date(cast(@a AS STRING), 'yyyyMMdd'), try_cast(@a AS DATE))"
1147+
spark,"DATEADD(@part,@amount,@([0-9a-zA-Z_]+_date)date)","CAST(DATEA##(@part,@amount,@date) AS DATE)"
1148+
spark,DATEA##,DATEADD
11471149
sqlite extended,"IIF(@condition, @whentrue, @whenfalse)","CASE WHEN @condition THEN @whentrue ELSE @whenfalse END"
11481150
sqlite extended,"ROUND(@a,@b)","ROUND(CAST(@a AS REAL),@b)"
11491151
sqlite extended,+ '@a',|| '@a'

java/org/ohdsi/sql/BigQuerySparkTranslate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/JarChecksum.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/MainClass.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/SqlRender.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/SqlSplit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/SqlTranslate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

java/org/ohdsi/sql/StringUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2024 Observational Health Data Sciences and Informatics
2+
* Copyright 2025 Observational Health Data Sciences and Informatics
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>org.ohdsi.sql</groupId>
77
<artifactId>SqlRender</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.19.1-SNAPSHOT</version>
9+
<version>1.19.2-SNAPSHOT</version>
1010
<name>SqlRender</name>
1111
<scm>
1212
<connection>scm:git:https://github.com/OHDSI/SqlRender</connection>

tests/testthat/test-translate-spark.R

+18-3
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,17 @@ test_that("translate sql server -> spark DATEADD DAY with float", {
422422
sql <- translate("select DATEADD(DAY, 1.0, some_date) from my_table;",
423423
targetDialect = "spark"
424424
)
425-
expect_equal_ignore_spaces(sql, "select DATEADD(DAY, 1, some_date) from my_table;")
425+
expect_equal_ignore_spaces(sql, "select CAST(DATEADD(DAY, 1, some_date) AS DATE) from my_table;")
426426
})
427427

428428
test_that("translate sql server -> spark DATEADD YEAR with float", {
429429
sql <- translate("select DATEADD(YEAR, 1.0, some_date) from my_table;",
430430
targetDialect = "spark"
431431
)
432-
expect_equal_ignore_spaces(sql, "select DATEADD(YEAR, 1, some_date) from my_table;")
432+
expect_equal_ignore_spaces(sql, "select CAST(DATEADD(YEAR, 1, some_date) AS DATE) from my_table;")
433433
})
434434

435-
test_that("translate sql server -> spark DATEADD YEAR with float", {
435+
test_that("translate sql server -> spark CTE", {
436436
sql <- translate("WITH cte AS (SELECT * FROM table) SELECT * INTO tmp.table FROM cte;",
437437
targetDialect = "spark"
438438
)
@@ -468,3 +468,18 @@ test_that("translate sql server -> spark create temp table if not exists", {
468468
sql <- translate("CREATE TABLE IF NOT EXISTS #temp (x INT);", targetDialect = "spark", tempEmulationSchema = "ts")
469469
expect_equal_ignore_spaces(sql, sprintf("CREATE TABLE IF NOT EXISTS ts.%stemp \nUSING DELTA\n AS\nSELECT\nCAST(NULL AS int) AS x WHERE 1 = 0;", getTempTablePrefix()))
470470
})
471+
472+
rJava::J('org.ohdsi.sql.SqlTranslate')$setReplacementPatterns('inst/csv/replacementPatterns.csv')
473+
474+
test_that("translate sql server -> spark DATEADD for DATE column", {
475+
# If field is a date, it should remain a date after DATEADD to be consistent with other platforms:
476+
sql <- translate("SELECT DATEADD(DAY, 1, start_date) FROM table;", targetDialect = "spark")
477+
expect_equal_ignore_spaces(sql, "SELECT CAST(DATEADD(DAY,1,start_date) AS DATE) FROM table;")
478+
479+
sql <- translate("SELECT DATEADD(DAY, 1, START_DATE) FROM table;", targetDialect = "spark")
480+
expect_equal_ignore_spaces(sql, "SELECT CAST(DATEADD(DAY,1,START_DATE) AS DATE) FROM table;")
481+
482+
sql <- translate("SELECT DATEADD(DAY, 1, start_datetime) FROM table;", targetDialect = "spark")
483+
expect_equal_ignore_spaces(sql, "SELECT DATEADD(DAY,1,start_datetime) FROM table;")
484+
})
485+

0 commit comments

Comments
 (0)