diff --git a/NAMESPACE b/NAMESPACE index 26cb2a43..8420f28a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,4 +31,4 @@ importFrom(tools,file_path_sans_ext) importFrom(utils,install.packages) importFrom(utils,menu) importFrom(utils,packageVersion) -importFrom(utils,write.table) \ No newline at end of file +importFrom(utils,write.table) diff --git a/R/executeDqChecks.R b/R/executeDqChecks.R index 5e9d1070..29082f33 100644 --- a/R/executeDqChecks.R +++ b/R/executeDqChecks.R @@ -93,6 +93,10 @@ executeDqChecks <- function(connectionDetails, if (!str_detect(cdmVersion, regex(acceptedCdmRegex))) { stop("cdmVersion must contain a version of the form '5.X' where X is an integer between 2 and 4 inclusive.") } + + if (sqlOnlyIncrementalInsert == TRUE && sqlOnly == FALSE) { + stop("Set `sqlOnly` to TRUE in order to use `sqlOnlyIncrementalInsert` mode.") + } stopifnot(is.character(cdmDatabaseSchema), is.character(resultsDatabaseSchema), is.numeric(numThreads)) stopifnot(is.character(cdmSourceName), is.logical(sqlOnly), is.character(outputFolder), is.logical(verboseMode)) @@ -134,6 +138,10 @@ executeDqChecks <- function(connectionDetails, if (nrow(metadata) < 1) { stop("Please populate the cdm_source table before executing data quality checks.") } + if (nrow(metadata) > 1) { + metadata <- metadata[1,] + warning("The cdm_source table has more than 1 row. A single row from this table has been selected to populate DQD metadata.") + } metadata$dqdVersion <- as.character(packageVersion("DataQualityDashboard")) DatabaseConnector::disconnect(connection) } else { diff --git a/R/runCheck.R b/R/runCheck.R index 85c31945..e4e2bd78 100644 --- a/R/runCheck.R +++ b/R/runCheck.R @@ -124,7 +124,7 @@ dfs <- do.call(rbind, dfs) - if (sqlOnlyIncrementalInsert) { + if (sqlOnly && sqlOnlyIncrementalInsert) { sqlToUnion <- dfs$query if (length(sqlToUnion) > 0) { .writeSqlOnlyQueries(sqlToUnion, sqlOnlyUnionCount, resultsDatabaseSchema, writeTableName, connectionDetails$dbms, outputFolder, checkDescription) diff --git a/R/writeDBResultsTo.R b/R/writeDBResultsTo.R index 66134ae5..39ef902f 100644 --- a/R/writeDBResultsTo.R +++ b/R/writeDBResultsTo.R @@ -17,7 +17,6 @@ #' Write DQD results database table to json #' #' @param connection A connection object -#' @param connectionDetails A connectionDetails object for connecting to the CDM database #' @param resultsDatabaseSchema The fully qualified database name of the results schema #' @param cdmDatabaseSchema The fully qualified database name of the CDM schema #' @param writeTableName Name of DQD results table in the database to read from @@ -28,7 +27,6 @@ #' writeDBResultsToJson <- function(connection, - connectionDetails, resultsDatabaseSchema, cdmDatabaseSchema, writeTableName, @@ -37,18 +35,16 @@ writeDBResultsToJson <- function(connection, metadata <- DatabaseConnector::renderTranslateQuerySql( connection, sql = "select * from @cdmDatabaseSchema.cdm_source;", - cdmDatabaseSchema = cdmDatabaseSchema, - targetDialect = connectionDetails$dbms, - snakeCaseToCamelCase = TRUE + snakeCaseToCamelCase = TRUE, + cdmDatabaseSchema = cdmDatabaseSchema ) checkResults <- DatabaseConnector::renderTranslateQuerySql( connection, sql = "select * from @resultsDatabaseSchema.@writeTableName;", + snakeCaseToCamelCase = TRUE, resultsDatabaseSchema = resultsDatabaseSchema, - writeTableName = writeTableName, - targetDialect = connectionDetails$dbms, - snakeCaseToCamelCase = TRUE + writeTableName = writeTableName ) # Quick patch for missing value issues related to SQL Only Implementation diff --git a/man/writeDBResultsToJson.Rd b/man/writeDBResultsToJson.Rd index 67f23ac4..3efc6b03 100644 --- a/man/writeDBResultsToJson.Rd +++ b/man/writeDBResultsToJson.Rd @@ -6,7 +6,6 @@ \usage{ writeDBResultsToJson( connection, - connectionDetails, resultsDatabaseSchema, cdmDatabaseSchema, writeTableName, @@ -17,18 +16,16 @@ writeDBResultsToJson( \arguments{ \item{connection}{A connection object} -\item{connectionDetails}{A connectionDetails object for connecting to the CDM database} - \item{resultsDatabaseSchema}{The fully qualified database name of the results schema} \item{cdmDatabaseSchema}{The fully qualified database name of the CDM schema} -\item{writeTableName}{Name of table in the database to write results to} +\item{writeTableName}{Name of DQD results table in the database to read from} -\item{outputFolder}{The output folder} +\item{outputFolder}{The folder to output the json results file to} -\item{outputFile}{The output filename} +\item{outputFile}{The output filename of the json results file} } \description{ Write DQD results database table to json -} \ No newline at end of file +} diff --git a/tests/testthat/test-writeDBResultsTo.R b/tests/testthat/test-writeDBResultsTo.R index 66159efc..312f4607 100644 --- a/tests/testthat/test-writeDBResultsTo.R +++ b/tests/testthat/test-writeDBResultsTo.R @@ -8,25 +8,26 @@ test_that("Write DB results to json", { resultsDatabaseSchemaEunomia <- "main" writeTableName <- "dqdashboard_results" - results <- DataQualityDashboard::executeDqChecks( - connectionDetails = connectionDetailsEunomia, - cdmDatabaseSchema = cdmDatabaseSchemaEunomia, - resultsDatabaseSchema = resultsDatabaseSchemaEunomia, - cdmSourceName = "Eunomia", - checkNames = "measurePersonCompleteness", - outputFolder = outputFolder, - writeToTable = TRUE, - writeTableName = writeTableName + expect_warning( + results <- DataQualityDashboard::executeDqChecks( + connectionDetails = connectionDetailsEunomia, + cdmDatabaseSchema = cdmDatabaseSchemaEunomia, + resultsDatabaseSchema = resultsDatabaseSchemaEunomia, + cdmSourceName = "Eunomia", + checkNames = "measurePersonCompleteness", + outputFolder = outputFolder, + writeToTable = TRUE, + writeTableName = writeTableName + ), + regexp = "^Missing check names.*" ) - connection <- DatabaseConnector::connect(connectionDetailsEunomia) testExportFile <- "dq-result-test.json" DataQualityDashboard::writeDBResultsToJson( connection, - connectionDetailsEunomia, resultsDatabaseSchemaEunomia, cdmDatabaseSchemaEunomia, writeTableName, @@ -46,7 +47,6 @@ test_that("Write DB results to json", { sql = "select count(*) from @resultsDatabaseSchema.@writeTableName;", resultsDatabaseSchema = resultsDatabaseSchemaEunomia, writeTableName = writeTableName, - targetDialect = connectionDetailsEunomia$dbms, snakeCaseToCamelCase = TRUE ) expect_true(length(results$CheckResults) == table_rows)