diff --git a/DESCRIPTION b/DESCRIPTION index f153f76c..ee602902 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: SqlRender Type: Package Title: Rendering Parameterized SQL and Translation to Dialects -Version: 1.16.1 -Date: 2023-10-07 +Version: 1.17.0 +Date: 2024-03-20 Authors@R: c( person("Martijn", "Schuemie", , "schuemie@ohdsi.org", role = c("aut", "cre")), person("Marc", "Suchard", role = c("aut")) diff --git a/NEWS.md b/NEWS.md index 8266f114..1f809b71 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,21 @@ +SqlRender 1.17.0 +================ + +Changes: + +1. Adding datetime calculations to Spark translation. + +Bugfixes: + +1. Fix translation of `NEWID()` for DuckDB. + +2. Fix `LEFT()` and `RIGHT()` translation on Spark. + +3. Fix some date functions on SQLite. + +4. Fix `DROP TABLE IF EXISTS` and `CREATE TABLE IF EXISTS` translation for Synapse. + + SqlRender 1.16.1 ================ diff --git a/R/HelperFunctions.R b/R/HelperFunctions.R index b75de345..d708b815 100644 --- a/R/HelperFunctions.R +++ b/R/HelperFunctions.R @@ -1,6 +1,6 @@ # @file HelperFunctions.R # -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # diff --git a/R/RenderSql.R b/R/RenderSql.R index 1f1c9800..010b1042 100644 --- a/R/RenderSql.R +++ b/R/RenderSql.R @@ -1,6 +1,6 @@ # @file RenderSql # -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # diff --git a/R/ShinyApps.R b/R/ShinyApps.R index 5bd501e9..067c5f19 100644 --- a/R/ShinyApps.R +++ b/R/ShinyApps.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # diff --git a/R/SparkSql.R b/R/SparkSql.R index eff161fd..327a3421 100644 --- a/R/SparkSql.R +++ b/R/SparkSql.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # diff --git a/R/SqlRender.R b/R/SqlRender.R index 4ba2a347..8c46f5cd 100644 --- a/R/SqlRender.R +++ b/R/SqlRender.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of SqlRender # diff --git a/cran-comments.md b/cran-comments.md index f7c34389..35169ef1 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,4 +1,4 @@ -There are 2 changes and 1 bugfixes (see NEWS.md). +There is 1 change and 4 bugfixes (see NEWS.md). --- @@ -6,7 +6,7 @@ There are 2 changes and 1 bugfixes (see NEWS.md). * Ubuntu 20.03, R 4.3.1 * Microsoft Windows Server 2019, R 4.3.1 * MacOS, R 4.3.1 -* Windows 10, R 4.2.3 +* MacOS, R 4.2.3 ## R CMD check results diff --git a/docs/404.html b/docs/404.html index 8b73ac0e..8e131d81 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@
diff --git a/docs/articles/UsingSqlRender.html b/docs/articles/UsingSqlRender.html index 38abc735..0fd79bac 100644 --- a/docs/articles/UsingSqlRender.html +++ b/docs/articles/UsingSqlRender.html @@ -33,7 +33,7 @@ @@ -88,7 +88,7 @@vignettes/UsingSqlRender.Rmd
UsingSqlRender.Rmd
sql <- "SELECT * FROM #children;"
translate(sql, targetDialect = "oracle", tempEmulationSchema = "temp_schema")
-## [1] "SELECT * FROM temp_schema.cfarvxt0children ;"
+## [1] "SELECT * FROM temp_schema.o7y7pd60children ;"
## attr(,"sqlDialect")
## [1] "oracle"
Note that the user will need to have write privileges on
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 06219f85..058b894c 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -17,7 +17,7 @@
diff --git a/docs/authors.html b/docs/authors.html
index 6141b144..add70664 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -17,7 +17,7 @@
@@ -81,14 +81,14 @@ Citation
- Schuemie M, Suchard M (2023).
+
Schuemie M, Suchard M (2024).
SqlRender: Rendering Parameterized SQL and Translation to Dialects.
https://ohdsi.github.io/SqlRender/, https://github.com/OHDSI/SqlRender.
@Manual{,
title = {SqlRender: Rendering Parameterized SQL and Translation to Dialects},
author = {Martijn Schuemie and Marc Suchard},
- year = {2023},
+ year = {2024},
note = {https://ohdsi.github.io/SqlRender/, https://github.com/OHDSI/SqlRender},
}
diff --git a/docs/index.html b/docs/index.html
index 904878b3..b6e49910 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -36,7 +36,7 @@
diff --git a/docs/news/index.html b/docs/news/index.html
index df9f12d7..cb2a220b 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -17,7 +17,7 @@
@@ -64,7 +64,17 @@ Changelog
-SqlRender 1.16.1
+SqlRender 1.17.0
+Changes:
+- Adding datetime calculations to Spark translation.
+
Bugfixes:
+Fix translation of NEWID()
for DuckDB.
+Fix LEFT()
and RIGHT()
translation on Spark.
+Fix some date functions on SQLite.
+Fix DROP TABLE IF EXISTS
and CREATE TABLE IF EXISTS
translation for Synapse.
+
+
+SqlRender 1.16.12023-10-07
Changes:
Adding support for ALTER TABLE ADD COLUMN
for PostgreSQL, even though it is not correct OhdsiSql (because it is not valid SQL Server SQL).
Removing translation of DELETE
and INSERT
rules for DataBricks as no longer needed.
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index 40c23c0f..1fb7bda9 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
UsingSqlRender: UsingSqlRender.html
-last_built: 2023-10-07T04:21Z
+last_built: 2024-03-20T12:31Z
diff --git a/docs/pull_request_template.html b/docs/pull_request_template.html
index 58d94d34..1ce25b35 100644
--- a/docs/pull_request_template.html
+++ b/docs/pull_request_template.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/SqlRender-package.html b/docs/reference/SqlRender-package.html
index 7b1937ce..6863371e 100644
--- a/docs/reference/SqlRender-package.html
+++ b/docs/reference/SqlRender-package.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/camelCaseToSnakeCase.html b/docs/reference/camelCaseToSnakeCase.html
index f0380556..70c24136 100644
--- a/docs/reference/camelCaseToSnakeCase.html
+++ b/docs/reference/camelCaseToSnakeCase.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/camelCaseToSnakeCaseNames.html b/docs/reference/camelCaseToSnakeCaseNames.html
index d84ab9c3..8dffa2d5 100644
--- a/docs/reference/camelCaseToSnakeCaseNames.html
+++ b/docs/reference/camelCaseToSnakeCaseNames.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/camelCaseToTitleCase.html b/docs/reference/camelCaseToTitleCase.html
index 892774ec..5755aa8a 100644
--- a/docs/reference/camelCaseToTitleCase.html
+++ b/docs/reference/camelCaseToTitleCase.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/createRWrapperForSql.html b/docs/reference/createRWrapperForSql.html
index 3fa60071..df70042a 100644
--- a/docs/reference/createRWrapperForSql.html
+++ b/docs/reference/createRWrapperForSql.html
@@ -19,7 +19,7 @@
diff --git a/docs/reference/getTempTablePrefix.html b/docs/reference/getTempTablePrefix.html
index 2efd96e8..d392a8b1 100644
--- a/docs/reference/getTempTablePrefix.html
+++ b/docs/reference/getTempTablePrefix.html
@@ -20,7 +20,7 @@
@@ -87,7 +87,7 @@ Value
Examples
getTempTablePrefix()
-#> [1] "kwc6cvd1"
+#> [1] "gyc7mdy8"
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 63bae290..98c0586b 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/launchSqlRenderDeveloper.html b/docs/reference/launchSqlRenderDeveloper.html
index 3b883062..a525bb5f 100644
--- a/docs/reference/launchSqlRenderDeveloper.html
+++ b/docs/reference/launchSqlRenderDeveloper.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/listSupportedDialects.html b/docs/reference/listSupportedDialects.html
index afa9ad03..074209b2 100644
--- a/docs/reference/listSupportedDialects.html
+++ b/docs/reference/listSupportedDialects.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/loadRenderTranslateSql.html b/docs/reference/loadRenderTranslateSql.html
index d3abdfa3..93511009 100644
--- a/docs/reference/loadRenderTranslateSql.html
+++ b/docs/reference/loadRenderTranslateSql.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/readSql.html b/docs/reference/readSql.html
index 678c2b73..5bd9a3de 100644
--- a/docs/reference/readSql.html
+++ b/docs/reference/readSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/render.html b/docs/reference/render.html
index cf3746b5..5097e1d4 100644
--- a/docs/reference/render.html
+++ b/docs/reference/render.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/renderSql.html b/docs/reference/renderSql.html
index facba3a4..8a51a362 100644
--- a/docs/reference/renderSql.html
+++ b/docs/reference/renderSql.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/renderSqlFile.html b/docs/reference/renderSqlFile.html
index 4c7b3398..eca3e8a2 100644
--- a/docs/reference/renderSqlFile.html
+++ b/docs/reference/renderSqlFile.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/snakeCaseToCamelCase.html b/docs/reference/snakeCaseToCamelCase.html
index 286b1642..36b065dd 100644
--- a/docs/reference/snakeCaseToCamelCase.html
+++ b/docs/reference/snakeCaseToCamelCase.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/snakeCaseToCamelCaseNames.html b/docs/reference/snakeCaseToCamelCaseNames.html
index d95f9ba6..10352cd8 100644
--- a/docs/reference/snakeCaseToCamelCaseNames.html
+++ b/docs/reference/snakeCaseToCamelCaseNames.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/sparkHandleInsert.html b/docs/reference/sparkHandleInsert.html
index 693edf44..0ba469f7 100644
--- a/docs/reference/sparkHandleInsert.html
+++ b/docs/reference/sparkHandleInsert.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/splitSql.html b/docs/reference/splitSql.html
index 20b0a3cb..37cca4eb 100644
--- a/docs/reference/splitSql.html
+++ b/docs/reference/splitSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/supportsJava8.html b/docs/reference/supportsJava8.html
index d95f267a..8ccce69e 100644
--- a/docs/reference/supportsJava8.html
+++ b/docs/reference/supportsJava8.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/translate.html b/docs/reference/translate.html
index 0818d906..4ea02abb 100644
--- a/docs/reference/translate.html
+++ b/docs/reference/translate.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/translateSingleStatement.html b/docs/reference/translateSingleStatement.html
index 2e650cda..d13e9d4d 100644
--- a/docs/reference/translateSingleStatement.html
+++ b/docs/reference/translateSingleStatement.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/translateSql.html b/docs/reference/translateSql.html
index 21b841ba..d2b71823 100644
--- a/docs/reference/translateSql.html
+++ b/docs/reference/translateSql.html
@@ -18,7 +18,7 @@
diff --git a/docs/reference/translateSqlFile.html b/docs/reference/translateSqlFile.html
index 64cdee46..74324337 100644
--- a/docs/reference/translateSqlFile.html
+++ b/docs/reference/translateSqlFile.html
@@ -17,7 +17,7 @@
diff --git a/docs/reference/writeSql.html b/docs/reference/writeSql.html
index 6d04233b..c15af345 100644
--- a/docs/reference/writeSql.html
+++ b/docs/reference/writeSql.html
@@ -17,7 +17,7 @@
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index b6a9b77f..89c1b0de 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -4,10 +4,10 @@
/404.html
- /articles/index.html
+ /articles/UsingSqlRender.html
- /articles/UsingSqlRender.html
+ /articles/index.html
/authors.html
@@ -21,6 +21,12 @@
/pull_request_template.html
+
+ /reference/SqlRender-package.html
+
+
+ /reference/SqlRender.html
+
/reference/camelCaseToSnakeCase.html
@@ -72,12 +78,6 @@
/reference/splitSql.html
-
- /reference/SqlRender-package.html
-
-
- /reference/SqlRender.html
-
/reference/supportsJava8.html
diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R
index 54643cb7..7f239843 100644
--- a/extras/PackageMaintenance.R
+++ b/extras/PackageMaintenance.R
@@ -1,4 +1,4 @@
-# Copyright 2023 Observational Health Data Sciences and Informatics
+# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of SqlRender
#
diff --git a/extras/SqlRender.pdf b/extras/SqlRender.pdf
index d97359be..a0ba8b96 100644
Binary files a/extras/SqlRender.pdf and b/extras/SqlRender.pdf differ
diff --git a/inst/doc/UsingSqlRender.pdf b/inst/doc/UsingSqlRender.pdf
index 37e6321f..e3eb0c15 100644
Binary files a/inst/doc/UsingSqlRender.pdf and b/inst/doc/UsingSqlRender.pdf differ
diff --git a/java/org/ohdsi/sql/BigQuerySparkTranslate.java b/java/org/ohdsi/sql/BigQuerySparkTranslate.java
index 9e1a2aeb..9be9c3b3 100644
--- a/java/org/ohdsi/sql/BigQuerySparkTranslate.java
+++ b/java/org/ohdsi/sql/BigQuerySparkTranslate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/JarChecksum.java b/java/org/ohdsi/sql/JarChecksum.java
index 80fae708..0437800d 100644
--- a/java/org/ohdsi/sql/JarChecksum.java
+++ b/java/org/ohdsi/sql/JarChecksum.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/MainClass.java b/java/org/ohdsi/sql/MainClass.java
index c7660506..892391f5 100644
--- a/java/org/ohdsi/sql/MainClass.java
+++ b/java/org/ohdsi/sql/MainClass.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/SqlRender.java b/java/org/ohdsi/sql/SqlRender.java
index 9d17c0a7..02810a00 100644
--- a/java/org/ohdsi/sql/SqlRender.java
+++ b/java/org/ohdsi/sql/SqlRender.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/SqlSplit.java b/java/org/ohdsi/sql/SqlSplit.java
index c9d703ee..06c38a2e 100644
--- a/java/org/ohdsi/sql/SqlSplit.java
+++ b/java/org/ohdsi/sql/SqlSplit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/SqlTranslate.java b/java/org/ohdsi/sql/SqlTranslate.java
index 5e674a5e..bd56c375 100644
--- a/java/org/ohdsi/sql/SqlTranslate.java
+++ b/java/org/ohdsi/sql/SqlTranslate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/java/org/ohdsi/sql/StringUtils.java b/java/org/ohdsi/sql/StringUtils.java
index b8467111..6aae76ab 100644
--- a/java/org/ohdsi/sql/StringUtils.java
+++ b/java/org/ohdsi/sql/StringUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright 2023 Observational Health Data Sciences and Informatics
+ * Copyright 2024 Observational Health Data Sciences and Informatics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/tests/testthat.R b/tests/testthat.R
index c8e35d3c..7a15e372 100644
--- a/tests/testthat.R
+++ b/tests/testthat.R
@@ -1,4 +1,4 @@
-if (SqlRender::supportsJava8()) {
- library(testthat)
- test_check("SqlRender")
-}
+if (SqlRender::supportsJava8()) {
+ library(testthat)
+ test_check("SqlRender")
+}
diff --git a/tests/testthat/test-helperFunctions.R b/tests/testthat/test-helperFunctions.R
index bb40c2ad..089565c7 100644
--- a/tests/testthat/test-helperFunctions.R
+++ b/tests/testthat/test-helperFunctions.R
@@ -1,132 +1,132 @@
-library("testthat")
-
-# test_that("Designed to fail", {
-# expect_true(FALSE)
-# })
-
-test_that("SQL read write", {
- fileName <- tempfile()
- sql1 <- "SELECT * FROM table"
- writeSql(sql1, fileName)
- sql2 <- readSql(fileName)
- file.remove(fileName)
- expect_equal(sql1, sql2)
-})
-
-test_that("renderSqlFile", {
- fileName1 <- tempfile()
- fileName2 <- tempfile()
- sql1 <- "SELECT * FROM @table"
- writeSql(sql1, fileName1)
- renderSqlFile(fileName1, fileName2, table = "person")
- sql2 <- readSql(fileName2)
- file.remove(fileName1)
- file.remove(fileName2)
- expect_equal(sql2, "SELECT * FROM person")
-})
-
-test_that("translateSqlFile", {
- fileName1 <- tempfile()
- fileName2 <- tempfile()
- sql1 <- "SELECT DATEADD(dd,1,observation_period_start_date) FROM observation_period"
- writeSql(sql1, fileName1)
- translateSqlFile(fileName1, fileName2, targetDialect = "postgresql")
- sql2 <- readSql(fileName2)
- file.remove(fileName1)
- file.remove(fileName2)
- expect_equivalent(
- sql2,
- "SELECT (observation_period_start_date + 1*INTERVAL'1 day') FROM observation_period"
- )
-})
-
-test_that("Warning in translateSqlFile when using oracleTempSchema", {
- fileName1 <- tempfile()
- fileName2 <- tempfile()
- sql1 <- "SELECT DATEADD(dd,1,observation_period_start_date) FROM observation_period"
- writeSql(sql1, fileName1)
- clearWarningBlock()
- expect_warning(translateSqlFile(fileName1, fileName2, targetDialect = "oracle", oracleTempSchema = "scratch"))
- file.remove(fileName1)
- file.remove(fileName2)
-})
-
-test_that("snakeCaseToCamelCase", {
- string1 <- "cdm_database_schema"
- string2 <- snakeCaseToCamelCase(string1)
- expect_equal(string2, "cdmDatabaseSchema")
-
- string1 <- "EXPOSURE_ID_1"
- string2 <- snakeCaseToCamelCase(string1)
- expect_equal(string2, "exposureId1")
-})
-
-test_that("camelCaseToSnakeCase ", {
- string1 <- "cdmDatabaseSchema"
- string2 <- camelCaseToSnakeCase(string1)
- expect_equal(string2, "cdm_database_schema")
-
- string1 <- "exposureId1"
- string2 <- camelCaseToSnakeCase(string1)
- expect_equal(string2, "exposure_id_1")
-})
-
-test_that("camelCaseToTitleCase ", {
- string1 <- "cdmDatabaseSchema"
- string2 <- camelCaseToTitleCase(string1)
- expect_equal(string2, "Cdm Database Schema")
-
- string1 <- "exposureId1"
- string2 <- camelCaseToTitleCase(string1)
- expect_equal(string2, "Exposure Id 1")
-})
-
-test_that("loadRenderTranslateSql ", {
- sql <- loadRenderTranslateSql("test.sql", "SqlRender", "sql server")
- sql <- gsub("[\r\n]", "", sql)
- expect_equivalent(sql, "SELECT a FROM #my_table WHERE my_id = 123;")
-
- sql <- loadRenderTranslateSql("test.sql", "SqlRender", "postgresql")
- sql <- gsub("[\r\n]", "", sql)
- expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
-
- sql <- loadRenderTranslateSql("test.sql", "SqlRender", "oracle")
- sql <- gsub("[\r\n]", "", sql)
- expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
-})
-
-test_that("loadRenderTranslateSql from sql folder", {
- sql <- loadRenderTranslateSql(sqlFilename = "test2.sql", packageName = "SqlRender", dbms = "postgresql")
- sql <- gsub("[\r\n]", "", sql)
- expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
-})
-
-test_that("Warning using loadRenderTranslateSql with oracleTempSchema", {
- clearWarningBlock()
- expect_warning(loadRenderTranslateSql(sqlFilename = "test.sql", packageName = "SqlRender", dbms = "oracle", oracleTempSchema = "scratch"))
-})
-
-test_that("createRWrapperForSql", {
- fileName <- tempfile()
- createRWrapperForSql(sqlFilename = "test.sql", rFilename = fileName, packageName = "SqlRender", createRoxygenTemplate = TRUE)
- expect_true(file.exists(fileName))
- file.remove(fileName)
-})
-
-test_that("listSupportedDialects", {
- dialects <- listSupportedDialects()
- expect_s3_class(dialects, "data.frame")
- expect_true("dialect" %in% colnames(dialects))
-})
-
-test_that("snakeCaseToCamelCaseNames", {
- x <- data.frame(concept_id = 1, concept_name = "b")
- x <- snakeCaseToCamelCaseNames(x)
- expect_equal(names(x), c("conceptId", "conceptName"))
-})
-
-test_that("camelCaseToSnakeCaseNames", {
- x <- data.frame(conceptId = 1, conceptName = "b")
- x <- camelCaseToSnakeCaseNames(x)
- expect_equal(names(x), c("concept_id", "concept_name"))
-})
+library("testthat")
+
+# test_that("Designed to fail", {
+# expect_true(FALSE)
+# })
+
+test_that("SQL read write", {
+ fileName <- tempfile()
+ sql1 <- "SELECT * FROM table"
+ writeSql(sql1, fileName)
+ sql2 <- readSql(fileName)
+ file.remove(fileName)
+ expect_equal(sql1, sql2)
+})
+
+test_that("renderSqlFile", {
+ fileName1 <- tempfile()
+ fileName2 <- tempfile()
+ sql1 <- "SELECT * FROM @table"
+ writeSql(sql1, fileName1)
+ renderSqlFile(fileName1, fileName2, table = "person")
+ sql2 <- readSql(fileName2)
+ file.remove(fileName1)
+ file.remove(fileName2)
+ expect_equal(sql2, "SELECT * FROM person")
+})
+
+test_that("translateSqlFile", {
+ fileName1 <- tempfile()
+ fileName2 <- tempfile()
+ sql1 <- "SELECT DATEADD(dd,1,observation_period_start_date) FROM observation_period"
+ writeSql(sql1, fileName1)
+ translateSqlFile(fileName1, fileName2, targetDialect = "postgresql")
+ sql2 <- readSql(fileName2)
+ file.remove(fileName1)
+ file.remove(fileName2)
+ expect_equivalent(
+ sql2,
+ "SELECT (observation_period_start_date + 1*INTERVAL'1 day') FROM observation_period"
+ )
+})
+
+test_that("Warning in translateSqlFile when using oracleTempSchema", {
+ fileName1 <- tempfile()
+ fileName2 <- tempfile()
+ sql1 <- "SELECT DATEADD(dd,1,observation_period_start_date) FROM observation_period"
+ writeSql(sql1, fileName1)
+ clearWarningBlock()
+ expect_warning(translateSqlFile(fileName1, fileName2, targetDialect = "oracle", oracleTempSchema = "scratch"))
+ file.remove(fileName1)
+ file.remove(fileName2)
+})
+
+test_that("snakeCaseToCamelCase", {
+ string1 <- "cdm_database_schema"
+ string2 <- snakeCaseToCamelCase(string1)
+ expect_equal(string2, "cdmDatabaseSchema")
+
+ string1 <- "EXPOSURE_ID_1"
+ string2 <- snakeCaseToCamelCase(string1)
+ expect_equal(string2, "exposureId1")
+})
+
+test_that("camelCaseToSnakeCase ", {
+ string1 <- "cdmDatabaseSchema"
+ string2 <- camelCaseToSnakeCase(string1)
+ expect_equal(string2, "cdm_database_schema")
+
+ string1 <- "exposureId1"
+ string2 <- camelCaseToSnakeCase(string1)
+ expect_equal(string2, "exposure_id_1")
+})
+
+test_that("camelCaseToTitleCase ", {
+ string1 <- "cdmDatabaseSchema"
+ string2 <- camelCaseToTitleCase(string1)
+ expect_equal(string2, "Cdm Database Schema")
+
+ string1 <- "exposureId1"
+ string2 <- camelCaseToTitleCase(string1)
+ expect_equal(string2, "Exposure Id 1")
+})
+
+test_that("loadRenderTranslateSql ", {
+ sql <- loadRenderTranslateSql("test.sql", "SqlRender", "sql server")
+ sql <- gsub("[\r\n]", "", sql)
+ expect_equivalent(sql, "SELECT a FROM #my_table WHERE my_id = 123;")
+
+ sql <- loadRenderTranslateSql("test.sql", "SqlRender", "postgresql")
+ sql <- gsub("[\r\n]", "", sql)
+ expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
+
+ sql <- loadRenderTranslateSql("test.sql", "SqlRender", "oracle")
+ sql <- gsub("[\r\n]", "", sql)
+ expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
+})
+
+test_that("loadRenderTranslateSql from sql folder", {
+ sql <- loadRenderTranslateSql(sqlFilename = "test2.sql", packageName = "SqlRender", dbms = "postgresql")
+ sql <- gsub("[\r\n]", "", sql)
+ expect_equivalent(sql, "SELECT a FROM my_table WHERE my_id = 123;")
+})
+
+test_that("Warning using loadRenderTranslateSql with oracleTempSchema", {
+ clearWarningBlock()
+ expect_warning(loadRenderTranslateSql(sqlFilename = "test.sql", packageName = "SqlRender", dbms = "oracle", oracleTempSchema = "scratch"))
+})
+
+test_that("createRWrapperForSql", {
+ fileName <- tempfile()
+ createRWrapperForSql(sqlFilename = "test.sql", rFilename = fileName, packageName = "SqlRender", createRoxygenTemplate = TRUE)
+ expect_true(file.exists(fileName))
+ file.remove(fileName)
+})
+
+test_that("listSupportedDialects", {
+ dialects <- listSupportedDialects()
+ expect_s3_class(dialects, "data.frame")
+ expect_true("dialect" %in% colnames(dialects))
+})
+
+test_that("snakeCaseToCamelCaseNames", {
+ x <- data.frame(concept_id = 1, concept_name = "b")
+ x <- snakeCaseToCamelCaseNames(x)
+ expect_equal(names(x), c("conceptId", "conceptName"))
+})
+
+test_that("camelCaseToSnakeCaseNames", {
+ x <- data.frame(conceptId = 1, conceptName = "b")
+ x <- camelCaseToSnakeCaseNames(x)
+ expect_equal(names(x), c("concept_id", "concept_name"))
+})
diff --git a/tests/testthat/test-splitSql.R b/tests/testthat/test-splitSql.R
index 999555b6..d2999d34 100644
--- a/tests/testthat/test-splitSql.R
+++ b/tests/testthat/test-splitSql.R
@@ -1,61 +1,61 @@
-library("testthat")
-
-test_that("splitSql split simple statements", {
- sql <- splitSql("SELECT * INTO a FROM b; USE x; DROP TABLE c;")
- expect_equal(sql, c("SELECT * INTO a FROM b", "USE x", "DROP TABLE c"))
-})
-
-test_that("splitSql split with BEGIN...END", {
- sql <- splitSql("BEGIN\nSELECT * INTO a FROM b;\nEND;\nUSE x;")
- expect_equal(sql, c("BEGIN\nSELECT * INTO a FROM b;\nEND;", "USE x"))
-})
-
-test_that("splitSql split with CASE...END", {
- sql <- splitSql("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END AS x INTO a FROM b;\nUSE x;")
- expect_equal(sql, c("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END AS x INTO a FROM b", "USE x"))
-})
-
-
-test_that("splitSql split with 'end' in quoted text", {
- sql <- splitSql("insert into a (x) values ('end');\n insert into a (x) values ('begin');")
- expect_equal(sql, c("insert into a (x) values ('end')", "insert into a (x) values ('begin')"))
-})
-
-test_that("splitSql split with case end at the end", {
- sql <- splitSql("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END FROM a GROUP BY CASE WHEN x=1 THEN 0 ELSE 1 END;")
- expect_equal(
- sql,
- c("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END FROM a GROUP BY CASE WHEN x=1 THEN 0 ELSE 1 END")
- )
-})
-
-
-test_that("splitSql split with reserved word 'end' as field name", {
- sql <- splitSql("INSERT INTO CDM_CPRD_TESTING_RAW.dbo.hes_linkage_coverage (data_source, start, [end]) VALUES ('hes', '1990-01-01', '2014-12-31');")
- expect_equal(
- sql,
- c("INSERT INTO CDM_CPRD_TESTING_RAW.dbo.hes_linkage_coverage (data_source, start, [end]) VALUES ('hes', '1990-01-01', '2014-12-31')")
- )
-})
-
-test_that("splitSql split with last line containing comment and having no EOL", {
- sql <- splitSql("SELECT * FROM table;\n-- end")
- expect_equal(sql, c("SELECT * FROM table"))
-})
-
-test_that("splitSql split with hint at start", {
- sql <- splitSql("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
- expect_equal(
- sql,
- c("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
- )
-})
-
-test_that("splitSql split with hint in second statement", {
- sql <- splitSql("DROP TABLE blah;\n--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist;")
- expect_equal(sql[1], c("DROP TABLE blah"))
- expect_equal(
- sql[2],
- c("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
- )
-})
+library("testthat")
+
+test_that("splitSql split simple statements", {
+ sql <- splitSql("SELECT * INTO a FROM b; USE x; DROP TABLE c;")
+ expect_equal(sql, c("SELECT * INTO a FROM b", "USE x", "DROP TABLE c"))
+})
+
+test_that("splitSql split with BEGIN...END", {
+ sql <- splitSql("BEGIN\nSELECT * INTO a FROM b;\nEND;\nUSE x;")
+ expect_equal(sql, c("BEGIN\nSELECT * INTO a FROM b;\nEND;", "USE x"))
+})
+
+test_that("splitSql split with CASE...END", {
+ sql <- splitSql("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END AS x INTO a FROM b;\nUSE x;")
+ expect_equal(sql, c("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END AS x INTO a FROM b", "USE x"))
+})
+
+
+test_that("splitSql split with 'end' in quoted text", {
+ sql <- splitSql("insert into a (x) values ('end');\n insert into a (x) values ('begin');")
+ expect_equal(sql, c("insert into a (x) values ('end')", "insert into a (x) values ('begin')"))
+})
+
+test_that("splitSql split with case end at the end", {
+ sql <- splitSql("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END FROM a GROUP BY CASE WHEN x=1 THEN 0 ELSE 1 END;")
+ expect_equal(
+ sql,
+ c("SELECT CASE WHEN x=1 THEN 0 ELSE 1 END FROM a GROUP BY CASE WHEN x=1 THEN 0 ELSE 1 END")
+ )
+})
+
+
+test_that("splitSql split with reserved word 'end' as field name", {
+ sql <- splitSql("INSERT INTO CDM_CPRD_TESTING_RAW.dbo.hes_linkage_coverage (data_source, start, [end]) VALUES ('hes', '1990-01-01', '2014-12-31');")
+ expect_equal(
+ sql,
+ c("INSERT INTO CDM_CPRD_TESTING_RAW.dbo.hes_linkage_coverage (data_source, start, [end]) VALUES ('hes', '1990-01-01', '2014-12-31')")
+ )
+})
+
+test_that("splitSql split with last line containing comment and having no EOL", {
+ sql <- splitSql("SELECT * FROM table;\n-- end")
+ expect_equal(sql, c("SELECT * FROM table"))
+})
+
+test_that("splitSql split with hint at start", {
+ sql <- splitSql("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
+ expect_equal(
+ sql,
+ c("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
+ )
+})
+
+test_that("splitSql split with hint in second statement", {
+ sql <- splitSql("DROP TABLE blah;\n--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist;")
+ expect_equal(sql[1], c("DROP TABLE blah"))
+ expect_equal(
+ sql[2],
+ c("--HINT DISTRIBUTE_ON_KEY(analysis_id)\nCREATE TABLE results.achilles_results_dist")
+ )
+})
diff --git a/tests/testthat/test-translate-sql_server.R b/tests/testthat/test-translate-sql_server.R
index c40a8af6..3a087312 100644
--- a/tests/testthat/test-translate-sql_server.R
+++ b/tests/testthat/test-translate-sql_server.R
@@ -29,4 +29,4 @@ test_that("translate -> sql server CREATE TABLE IF NOT EXISTS", {
test_that("translate sql server -> sql server temp dplyr ... pattern", {
sql <- translate("SELECT * FROM cdm.dbo.my_table AS cdm.dbo.my_table...1;", targetDialect = "sql server")
expect_equal_ignore_spaces(sql, "SELECT * FROM cdm.dbo.my_table AS cdmxdboxmy_tablexxx1;")
-})
\ No newline at end of file
+})
diff --git a/tests/testthat/test-translate-sqlite.R b/tests/testthat/test-translate-sqlite.R
index 200ec5d9..1c1c8de4 100644
--- a/tests/testthat/test-translate-sqlite.R
+++ b/tests/testthat/test-translate-sqlite.R
@@ -161,7 +161,7 @@ test_that("translate sql server -> sqlite DATEDIFF with literals", {
sql <- translate("SELECT DATEDIFF(DAY, '20000131', '20000101');", targetDialect = "sqlite")
expect_equal_ignore_spaces(
sql,
- "SELECT JULIANDAY(CAST(STRFTIME('%s', SUBSTR(CAST('20000101' AS TEXT), 1, 4) || '-' || SUBSTR(CAST('20000101' AS TEXT), 5, 2) || '-' || SUBSTR(CAST('20000101' AS TEXT), 7)) AS REAL), 'unixepoch') - JULIANDAY(CAST(STRFTIME('%s', SUBSTR(CAST('20000131' AS TEXT), 1, 4) || '-' || SUBSTR(CAST('20000131' AS TEXT), 5, 2) || '-' || SUBSTR(CAST('20000131' AS TEXT), 7)) AS REAL), 'unixepoch');"
+ "SELECT (JULIANDAY(CAST(STRFTIME('%s', SUBSTR(CAST('20000101' AS TEXT), 1, 4) || '-' || SUBSTR(CAST('20000101' AS TEXT), 5, 2) || '-' || SUBSTR(CAST('20000101' AS TEXT), 7)) AS REAL), 'unixepoch') - JULIANDAY(CAST(STRFTIME('%s', SUBSTR(CAST('20000131' AS TEXT), 1, 4) || '-' || SUBSTR(CAST('20000131' AS TEXT), 5, 2) || '-' || SUBSTR(CAST('20000131' AS TEXT), 7)) AS REAL), 'unixepoch'));"
)
})
@@ -169,7 +169,7 @@ test_that("translate sql server -> sqlite DATEDIFF with date fields", {
sql <- translate("SELECT DATEDIFF(DAY, date1, date2);", targetDialect = "sqlite")
expect_equal_ignore_spaces(
sql,
- "SELECT JULIANDAY(date2, 'unixepoch') - JULIANDAY(date1, 'unixepoch');"
+ "SELECT (JULIANDAY(date2, 'unixepoch') - JULIANDAY(date1, 'unixepoch'));"
)
})