Skip to content

Commit

Permalink
Fixes Concept Set optimization for Impala
Browse files Browse the repository at this point in the history
  • Loading branch information
pavgra committed Feb 26, 2019
1 parent 7b8f8e6 commit 3414220
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/java/org/ohdsi/webapi/service/VocabularyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,28 +1064,28 @@ public ConceptSetOptimizationResult optimizeConceptSet(@PathParam("sourceKey") S
// Find all of the concepts that should be considered for optimization
// Create a hashtable to hold all of the contents of the ConceptSetExpression
// for use later
Hashtable<String, ConceptSetExpression.ConceptSetItem> allConceptSetItems = new Hashtable<String, ConceptSetExpression.ConceptSetItem>();
ArrayList<String> includedConcepts = new ArrayList<String>();
ArrayList<String> descendantConcepts = new ArrayList<String>();
ArrayList<String> allOtherConcepts = new ArrayList<String>();
Hashtable<Integer, ConceptSetExpression.ConceptSetItem> allConceptSetItems = new Hashtable<>();
ArrayList<Integer> includedConcepts = new ArrayList<>();
ArrayList<Integer> descendantConcepts = new ArrayList<>();
ArrayList<Integer> allOtherConcepts = new ArrayList<>();
for(ConceptSetExpression.ConceptSetItem item : conceptSetExpression.items) {
allConceptSetItems.put(item.concept.conceptId.toString(), item);
allConceptSetItems.put(item.concept.conceptId.intValue(), item);
if (!item.isExcluded) {
includedConcepts.add(item.concept.conceptId.toString());
includedConcepts.add(item.concept.conceptId.intValue());
if (item.includeDescendants) {
descendantConcepts.add(item.concept.conceptId.toString());
descendantConcepts.add(item.concept.conceptId.intValue());
}
} else {
allOtherConcepts.add(item.concept.conceptId.toString());
allOtherConcepts.add(item.concept.conceptId.intValue());
}
}

// If no descendant concepts are specified, initialize this field to use concept_id = 0 so the query will work properly
if (descendantConcepts.isEmpty())
descendantConcepts.add("0");
descendantConcepts.add(0);

String allConceptsList = this.JoinArray(includedConcepts.toArray(new String[includedConcepts.size()]));
String descendantConceptsList = this.JoinArray(descendantConcepts.toArray(new String[descendantConcepts.size()]));
String allConceptsList = includedConcepts.stream().map(Object::toString).collect(Collectors.joining(", "));
String descendantConceptsList = descendantConcepts.stream().map(Object::toString).collect(Collectors.joining(", "));

sql_statement = SqlRender.renderSql(sql_statement, new String[]{"allConcepts", "descendantConcepts", "cdm_database_schema"}, new String[]{allConceptsList, descendantConceptsList, tableQualifier});
sql_statement = SqlTranslate.translateSql(sql_statement, source.getSourceDialect());
Expand All @@ -1099,7 +1099,7 @@ public ConceptSetOptimizationResult optimizeConceptSet(@PathParam("sourceKey") S
ArrayList<ConceptSetExpression.ConceptSetItem> removedExpressionItems = new ArrayList<>();
List<Map<String, Object>> rows = getSourceJdbcTemplate(source).queryForList(sql_statement);
for (Map rs : rows) {
String conceptId = String.valueOf(rs.get("concept_id"));
Integer conceptId = Integer.parseInt(rs.get("concept_id").toString());
String removed = String.valueOf(rs.get("removed"));
ConceptSetExpression.ConceptSetItem csi = allConceptSetItems.get(conceptId);
if (removed.equals("0")) {
Expand All @@ -1110,7 +1110,7 @@ public ConceptSetOptimizationResult optimizeConceptSet(@PathParam("sourceKey") S
}
// Re-add back the other concepts that are not considered
// as part of the optimizatin process
for(String conceptId : allOtherConcepts) {
for(Integer conceptId : allOtherConcepts) {
ConceptSetExpression.ConceptSetItem csi = allConceptSetItems.get(conceptId);
optimzedExpressionItems.add(csi);
}
Expand Down

0 comments on commit 3414220

Please sign in to comment.