Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ public void parse(DocumentParserContext context) throws IOException {
);
}
NumericDocValuesField countField = new NumericDocValuesField(valuesCountSubFieldName(fullPath()), parsedTDigest.count());
NumericDocValuesField sumField = new NumericDocValuesField(
valuesSumSubFieldName(fullPath()),
NumericUtils.doubleToSortableLong(parsedTDigest.sum())
);
NumericDocValuesField sumField = null;
if (Double.isNaN(parsedTDigest.sum()) == false) {
sumField = new NumericDocValuesField(
valuesSumSubFieldName(fullPath()),
NumericUtils.doubleToSortableLong(parsedTDigest.sum())
);
}
if (context.doc().getByKey(fieldType().name()) != null) {
throw new IllegalArgumentException(
"Field ["
Expand All @@ -417,7 +420,9 @@ public void parse(DocumentParserContext context) throws IOException {
}
context.doc().addWithKey(fieldType().name(), digestField);
context.doc().add(countField);
context.doc().add(sumField);
if (sumField != null) {
context.doc().add(sumField);
}
if (maxField != null) {
context.doc().add(maxField);
}
Expand Down Expand Up @@ -564,8 +569,12 @@ public DocValuesLoader docValuesLoader(LeafReader leafReader, int[] docIdsInLeaf
max = Double.NaN;
}

sumValues.advanceExact(docId);
sum = NumericUtils.sortableLongToDouble(sumValues.longValue());
if (sumValues != null) {
sumValues.advanceExact(docId);
sum = NumericUtils.sortableLongToDouble(sumValues.longValue());
} else {
sum = Double.NaN;
}

binaryValue = docValues.binaryValue();
return true;
Expand Down Expand Up @@ -595,7 +604,9 @@ public void write(XContentBuilder b) throws IOException {
if (Double.isNaN(max) == false) {
b.field("max", max);
}
b.field("sum", sum);
if (Double.isNaN(sum) == false) {
b.field("sum", sum);
}

b.startArray(CENTROIDS_NAME);
while (value.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static ParsedTDigest parse(String mappedFieldName, XContentParser parser)
);
}
if (centroids.isEmpty()) {
sum = 0.0;
sum = null;
min = null;
max = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ TDigest with synthetic source and empty digest:
- match:
_source:
latency:
sum: 0.0
centroids: [ ]
counts: [ ]

Expand Down