Skip to content

Commit

Permalink
datastore: fix the converter by replacing '.' by '.' in the facet…
Browse files Browse the repository at this point in the history
… field name results, #TASK-7151, #TASK-7134
  • Loading branch information
jtarraga committed Jan 20, 2025
1 parent 1184be3 commit 7255b42
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.*;

import static org.opencb.commons.datastore.mongodb.GenericDocumentComplexConverter.TO_REPLACE_DOTS;
import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.*;
import static org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.Accumulator.*;

Expand All @@ -18,6 +19,7 @@ public List<FacetField> convertToDataModelType(Document document) {
return Collections.emptyList();
}

String facetFieldName;
List<FacetField> facets = new ArrayList<>();
for (Map.Entry<String, Object> entry : document.entrySet()) {
String key = entry.getKey();
Expand Down Expand Up @@ -54,7 +56,7 @@ public List<FacetField> convertToDataModelType(Document document) {
value = documentValue.getDouble(aggregationName);
}
List<Double> aggregationValues = Collections.singletonList(value);
FacetField facetField = new FacetField(name, aggregationName, aggregationValues);
FacetField facetField = new FacetField(name.replace(TO_REPLACE_DOTS, "."), aggregationName, aggregationValues);
// Perhaps it’s redundant, as it is also set in the bucket
facetField.setCount(counter);
bucketFacetFields = Collections.singletonList(facetField);
Expand All @@ -63,8 +65,8 @@ public List<FacetField> convertToDataModelType(Document document) {
buckets.add(new FacetField.Bucket(bucketValue, counter, bucketFacetFields));
total += counter;
}
key = key.split(SEPARATOR)[0];
facets.add(new FacetField(key, total, buckets));
facetFieldName = key.split(SEPARATOR)[0].replace(TO_REPLACE_DOTS, ".");
facets.add(new FacetField(facetFieldName, total, buckets));
} else if (key.endsWith(RANGES_SUFFIX)) {
List<Double> facetFieldValues = new ArrayList<>();
Number start = null;
Expand All @@ -87,11 +89,11 @@ public List<FacetField> convertToDataModelType(Document document) {
}
}
}
key = key.split(SEPARATOR)[0].replace(GenericDocumentComplexConverter.TO_REPLACE_DOTS, ".");
facetFieldName = key.split(SEPARATOR)[0].replace(TO_REPLACE_DOTS, ".");
if (other != null) {
key += " (counts out of range: " + other + ")";
facetFieldName += " (counts out of range: " + other + ")";
}
FacetField facetField = new FacetField(key, "range", facetFieldValues)
FacetField facetField = new FacetField(facetFieldName, "range", facetFieldValues)
.setStart(start)
.setEnd(end)
.setStep(step);
Expand Down Expand Up @@ -119,12 +121,11 @@ public List<FacetField> convertToDataModelType(Document document) {
}
}
}
key = key.substring(0,
key.length() - RANGES_SUFFIX.length()).replace(GenericDocumentComplexConverter.TO_REPLACE_DOTS, ".");
facetFieldName = key.substring(0, key.length() - RANGES_SUFFIX.length()).replace(TO_REPLACE_DOTS, ".");
if (other != null) {
key += " (counts out of range: " + other + ")";
facetFieldName += " (counts out of range: " + other + ")";
}
FacetField facetField = new FacetField(key, "range", facetFieldValues)
FacetField facetField = new FacetField(facetFieldName, "range", facetFieldValues)
.setStart(start)
.setEnd(end)
.setStep(step);
Expand Down Expand Up @@ -156,7 +157,8 @@ public List<FacetField> convertToDataModelType(Document document) {
if (documentValue.containsKey("count")) {
count = Long.valueOf(documentValue.getInteger("count"));
}
facets.add(new FacetField(documentValue.getString(INTERNAL_ID), count, accumulator.name(), fieldValues));
facetFieldName = documentValue.getString(INTERNAL_ID).replace(TO_REPLACE_DOTS, ".");
facets.add(new FacetField(facetFieldName, count, accumulator.name(), fieldValues));
break;
}
default: {
Expand Down

0 comments on commit 7255b42

Please sign in to comment.