Skip to content

Commit

Permalink
Merge pull request #501 from katy-sadowski/katy__warnings
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
katy-sadowski authored Nov 4, 2023
2 parents ef06bfc + 460ffb1 commit eb295b0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ importFrom(tools,file_path_sans_ext)
importFrom(utils,install.packages)
importFrom(utils,menu)
importFrom(utils,packageVersion)
importFrom(utils,write.table)
importFrom(utils,write.table)
8 changes: 8 additions & 0 deletions R/executeDqChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion R/runCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions R/writeDBResultsTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +27,6 @@
#'

writeDBResultsToJson <- function(connection,
connectionDetails,
resultsDatabaseSchema,
cdmDatabaseSchema,
writeTableName,
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions man/writeDBResultsToJson.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions tests/testthat/test-writeDBResultsTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit eb295b0

Please sign in to comment.