Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix distribution query to work with Oracle or Postgres #51

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Project settings
group = "org.veupathdb.eda"
version = "4.16.8"
version = "4.16.9"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,26 +782,27 @@ static String generateDistributionSql(String appDbSchema, Entity outputEntity, V

String tallTblAbbrev = "tall";
String ancestorTblAbbrev = "subset";
String distTblAbbrev = "dist";
return
// with clauses create an entity-named filtered result for each relevant entity
generateFilterWithClauses(appDbSchema, prunedEntityTree, filters) + NL +
generateDistributionSelectClause(distributionVariable) + NL +
generateDistributionSelectClause(distributionVariable, distTblAbbrev) + NL +
" FROM ( " + NL +
generateTabularSelectClause(outputEntity, ancestorTblAbbrev) + NL +
generateTabularFromClause(outputEntity, prunedEntityTree, ancestorTblAbbrev) + NL +
// left join to attributes table so we always get at least one row per subset
// record, even if no data exists for requested vars (or no vars requested).
// null rows will be handled in the tall-to-wide rows conversion
generateLeftJoin(appDbSchema, outputEntity, ListBuilder.asList(distributionVariable), ancestorTblAbbrev, tallTblAbbrev) + NL +
" ) " + NL +
generateDistributionGroupByClause(distributionVariable) + NL +
"ORDER BY " + distributionVariable.getType().getTallTableColumnName() + " ASC";
" ) dist" + NL +
generateDistributionGroupByClause(distributionVariable, distTblAbbrev) + NL +
"ORDER BY " + distTblAbbrev + "." + distributionVariable.getType().getTallTableColumnName() + " ASC";
}

static String generateDistributionSelectClause(VariableWithValues distributionVariable) {
static String generateDistributionSelectClause(VariableWithValues distributionVariable, String tableAbbrev) {
return "SELECT " +
distributionVariable.getType().getTallTableColumnName() +
", count(" + distributionVariable.getEntity().getPKColName() + ") as " + COUNT_COLUMN_NAME;
tableAbbrev + "." + distributionVariable.getType().getTallTableColumnName() +
", count(" + tableAbbrev + "." + distributionVariable.getEntity().getPKColName() + ") as " + COUNT_COLUMN_NAME;
}

static String generateDistributionFromClause(String appDbSchema, Entity outputEntity) {
Expand Down Expand Up @@ -888,8 +889,8 @@ static String generateTabularOrderByClause(Entity outputEntity) {
return "ORDER BY " + String.join(", ", cols);
}

static String generateDistributionGroupByClause(VariableWithValues outputVariable) {
return "GROUP BY " + outputVariable.getType().getTallTableColumnName();
static String generateDistributionGroupByClause(VariableWithValues outputVariable, String tableAbbrev) {
return "GROUP BY " + tableAbbrev + "." + outputVariable.getType().getTallTableColumnName();
}

private static String quote(String s) {
Expand Down
Loading