Skip to content

Commit

Permalink
standardizing column name case
Browse files Browse the repository at this point in the history
This should resolve errors with case sensitive platforms such as DuckDb where within the achilles package both upper case and lower case were used, standardized now on lower case.
  • Loading branch information
fdefalco committed Jul 20, 2023
1 parent 333924a commit 9c5f401
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
34 changes: 17 additions & 17 deletions R/Achilles.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ achilles <- function(connectionDetails,
if (!missing(analysisIds)) {
# If specific analysis_ids are given, run only those
analysisDetails <-
analysisDetails[analysisDetails$ANALYSIS_ID %in% analysisIds,]
analysisDetails[analysisDetails$analysis_id %in% analysisIds,]
} else if (defaultAnalysesOnly) {
# If specific analyses are not given, determine whether or not to run only default analyses
analysisDetails <-
analysisDetails[analysisDetails$IS_DEFAULT == 1,]
}

# Remove unwanted analyses that have not already been excluded, if any are specified
if (!missing(excludeAnalysisIds) && any(analysisDetails$ANALYSIS_ID %in% excludeAnalysisIds)) {
analysisDetails <- analysisDetails[-which(analysisDetails$ANALYSIS_ID %in% excludeAnalysisIds),]
if (!missing(excludeAnalysisIds) && any(analysisDetails$analysis_id %in% excludeAnalysisIds)) {
analysisDetails <- analysisDetails[-which(analysisDetails$analysis_id %in% excludeAnalysisIds),]
}

resultsTables <- list(
Expand All @@ -238,7 +238,7 @@ achilles <- function(connectionDetails,
file = system.file("csv", "schemas", "schema_achilles_results.csv", package = "Achilles"),
header = TRUE
),
analysisIds = analysisDetails[analysisDetails$DISTRIBUTION <=0, ]$ANALYSIS_ID
analysisIds = analysisDetails[analysisDetails$distribution <=0, ]$analysis_id
),
list(
detailType = "results_dist",
Expand All @@ -247,7 +247,7 @@ achilles <- function(connectionDetails,
file = system.file("csv","schemas","schema_achilles_results_dist.csv",package = "Achilles"),
header = TRUE
),
analysisIds = analysisDetails[abs(analysisDetails$DISTRIBUTION) == 1, ]$ANALYSIS_ID
analysisIds = analysisDetails[abs(analysisDetails$distribution) == 1, ]$analysis_id
)
)

Expand Down Expand Up @@ -376,7 +376,7 @@ achilles <- function(connectionDetails,
}

# Generate Main Analyses
mainAnalysisIds <- analysisDetails$ANALYSIS_ID
mainAnalysisIds <- analysisDetails$analysis_id

mainSqls <- lapply(mainAnalysisIds, function(analysisId) {
list(
Expand Down Expand Up @@ -409,7 +409,7 @@ achilles <- function(connectionDetails,
start <- Sys.time()
ParallelLogger::logInfo(sprintf("Analysis %d (%s) -- START",
mainSql$analysisId,
analysisDetails$ANALYSIS_NAME[analysisDetails$ANALYSIS_ID ==
analysisDetails$analysis_name[analysisDetails$analysis_id ==
mainSql$analysisId]))
tryCatch({
DatabaseConnector::executeSql(connection = connection,
Expand All @@ -435,7 +435,7 @@ achilles <- function(connectionDetails,
ParallelLogger::logInfo(sprintf("[Main Analysis] [START] %d (%s)",
as.integer(mainSql$analysisId),

analysisDetails$ANALYSIS_NAME[analysisDetails$ANALYSIS_ID == mainSql$analysisId]))
analysisDetails$ANALYSIS_NAME[analysisDetails$analysis_id == mainSql$analysisId]))
tryCatch({
DatabaseConnector::executeSql(connection = connection,
sql = mainSql$sql,
Expand All @@ -460,15 +460,15 @@ achilles <- function(connectionDetails,

# Merge scratch tables into final analysis tables
include <- sapply(resultsTables, function(d) {
any(d$analysisIds %in% analysisDetails$ANALYSIS_ID)
any(d$analysisIds %in% analysisDetails$analysis_id)
})
resultsTablesToMerge <- resultsTables[include]

mergeSqls <- lapply(resultsTablesToMerge, function(table) {
.mergeAchillesScratchTables(
resultsTable = table,
connectionDetails = connectionDetails,
analysisIds = analysisDetails$ANALYSIS_ID,
analysisIds = analysisDetails$analysis_id,
createTable = createTable,
schemaDelim = schemaDelim,
scratchDatabaseSchema = scratchDatabaseSchema,
Expand Down Expand Up @@ -581,7 +581,7 @@ achilles <- function(connectionDetails,
indicesSql <- "/* INDEX CREATION SKIPPED PER USER REQUEST */"

if (createIndices) {
achillesTables <- lapply(unique(analysisDetails$DISTRIBUTION), function(a) {
achillesTables <- lapply(unique(analysisDetails$distribution), function(a) {
if (a == 0) {
"achilles_results"
} else {
Expand Down Expand Up @@ -619,7 +619,7 @@ achilles <- function(connectionDetails,
resultsTable = "achilles_results",

resultsDistributionTable = "achilles_results_dist", analysis_table = "achilles_analysis", sourceName = sourceName,
analysisIds = analysisDetails$ANALYSIS_ID, achillesSql = paste(achillesSql, collapse = "\n\n"),
analysisIds = analysisDetails$analysis_id, achillesSql = paste(achillesSql, collapse = "\n\n"),
indicesSql = indicesSql, call = match.call())

class(achillesResults) <- "achillesResults"
Expand Down Expand Up @@ -807,18 +807,18 @@ dropAllScratchTables <- function(connectionDetails,
analysisDetails <- getAnalysisDetails()

if (defaultAnalysesOnly) {
resultsTables <- lapply(analysisDetails$ANALYSIS_ID[analysisDetails$DISTRIBUTION <= 0 & analysisDetails$IS_DEFAULT ==
resultsTables <- lapply(analysisDetails$analysis_id[analysisDetails$distribution <= 0 & analysisDetails$IS_DEFAULT ==
1], function(id) {
sprintf("%s_%d", tempAchillesPrefix, id)
})
} else {
resultsTables <- lapply(analysisDetails$ANALYSIS_ID[analysisDetails$DISTRIBUTION <= 0],
resultsTables <- lapply(analysisDetails$analysis_id[analysisDetails$distribution <= 0],
function(id) {
sprintf("%s_%d", tempAchillesPrefix, id)
})
}

resultsDistTables <- lapply(analysisDetails$ANALYSIS_ID[abs(analysisDetails$DISTRIBUTION) ==
resultsDistTables <- lapply(analysisDetails$analysis_id[abs(analysisDetails$distribution) ==
1], function(id) {
sprintf("%s_dist_%d", tempAchillesPrefix, id)
})
Expand Down Expand Up @@ -1059,8 +1059,8 @@ optimizeAtlasCache <- function(connectionDetails,
}

.deleteExistingResults <- function(connectionDetails, resultsDatabaseSchema, analysisDetails) {
resultIds <- analysisDetails$ANALYSIS_ID[analysisDetails$DISTRIBUTION == 0]
distIds <- analysisDetails$ANALYSIS_ID[analysisDetails$DISTRIBUTION == 1]
resultIds <- analysisDetails$analysis_id[analysisDetails$distribution == 0]
distIds <- analysisDetails$analysis_id[analysisDetails$distribution == 1]

if (length(resultIds) > 0) {
sql <- SqlRender::render(sql = "delete from @resultsDatabaseSchema.achilles_results where analysis_id in (@analysisIds);",
Expand Down
6 changes: 1 addition & 5 deletions R/listMissingAnalyses.r
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ listMissingAnalyses <- function(connectionDetails, resultsDatabaseSchema) {

missingAnalysisIds <- setdiff(allAnalysisIds, existingAnalysisIds)

colsToDisplay <- c("ANALYSIS_ID",
"DISTRIBUTION",
"CATEGORY",
"IS_DEFAULT",
"ANALYSIS_NAME")
colsToDisplay <- c("analysis_id","distribution","category","is_default","analysis_name")
retVal <- analysisDetails[analysisDetails$ANALYSIS_ID %in% missingAnalysisIds, colsToDisplay]
retVal <- retVal[order(retVal$ANALYSIS_ID), ]

Expand Down
2 changes: 1 addition & 1 deletion inst/csv/achilles/achilles_analysis_details.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ANALYSIS_ID,DISTRIBUTION,DISTRIBUTED_FIELD,ANALYSIS_NAME,STRATUM_1_NAME,STRATUM_2_NAME,STRATUM_3_NAME,STRATUM_4_NAME,STRATUM_5_NAME,IS_DEFAULT,CATEGORY
analysis_id,distribution,distributed_field,analysis_name,stratum_1_name,stratum_2_name,stratum_3_name,stratum_4_name,stratum_5_name,is_default,category
0,-1,,Source name,,,,,,1,General
1,0,,Number of persons,,,,,,1,Person
2,0,,Number of persons by gender,gender_concept_id,,,,,1,Person
Expand Down
2 changes: 1 addition & 1 deletion inst/csv/schemas/schema_achilles_results.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FIELD_NAME,FIELD_TYPE
field_name,field_type
analysis_id,int
stratum_1,varchar(255)
stratum_2,varchar(255)
Expand Down
2 changes: 1 addition & 1 deletion inst/csv/schemas/schema_achilles_results_concept_count.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FIELD_NAME,FIELD_TYPE
field_name,field_type
concept_id,int
record_count,bigint
descendant_record_count,bigint
2 changes: 1 addition & 1 deletion inst/csv/schemas/schema_achilles_results_dist.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FIELD_NAME,FIELD_TYPE
field_name,field_type
analysis_id,int
stratum_1,varchar(255)
stratum_2,varchar(255)
Expand Down

0 comments on commit 9c5f401

Please sign in to comment.