Skip to content

Commit c5526ba

Browse files
authored
Fix and unmute ExponentialHistogramFieldMapperTests.testFormattedDocValues (#138659)
1 parent cdf5112 commit c5526ba

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@ tests:
427427
- class: org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT
428428
method: testCreatesEisChatCompletion_DoesNotRemoveEndpointWhenNoLongerAuthorized
429429
issue: https://github.com/elastic/elasticsearch/issues/138480
430-
- class: org.elasticsearch.xpack.exponentialhistogram.ExponentialHistogramFieldMapperTests
431-
method: testFormattedDocValues
432-
issue: https://github.com/elastic/elasticsearch/issues/138504
433430
- class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackLookupJoinIT
434431
method: testLookupExplosionBigString
435432
issue: https://github.com/elastic/elasticsearch/issues/138510

x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
package org.elasticsearch.xpack.exponentialhistogram;
99

10+
import org.apache.lucene.document.NumericDocValuesField;
1011
import org.apache.lucene.index.DirectoryReader;
1112
import org.apache.lucene.index.IndexWriterConfig;
1213
import org.apache.lucene.index.IndexableField;
1314
import org.apache.lucene.index.LeafReader;
1415
import org.apache.lucene.index.LeafReaderContext;
16+
import org.apache.lucene.index.NumericDocValues;
1517
import org.apache.lucene.store.Directory;
1618
import org.apache.lucene.tests.analysis.MockAnalyzer;
1719
import org.apache.lucene.tests.index.RandomIndexWriter;
@@ -59,6 +61,7 @@
5961
import java.util.Map;
6062
import java.util.OptionalDouble;
6163
import java.util.Set;
64+
import java.util.concurrent.atomic.AtomicInteger;
6265
import java.util.stream.IntStream;
6366

6467
import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_INDEX;
@@ -725,18 +728,33 @@ public void testFormattedDocValues() throws IOException {
725728

726729
IndexWriterConfig config = LuceneTestCase.newIndexWriterConfig(random(), new MockAnalyzer(random()));
727730
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory, config);
728-
inputHistograms.forEach(histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc(indexWriter, "field", histo));
731+
732+
// give each document a ID field because we are not guaranteed to read them in-order later
733+
AtomicInteger currentId = new AtomicInteger(0);
734+
inputHistograms.forEach(
735+
histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc(
736+
indexWriter,
737+
"field",
738+
histo,
739+
new NumericDocValuesField("histo_index", currentId.getAndIncrement())
740+
)
741+
);
729742
indexWriter.close();
730743

744+
int seenCount = 0;
731745
try (DirectoryReader reader = DirectoryReader.open(directory)) {
732746
for (int i = 0; i < reader.leaves().size(); i++) {
733747
LeafReaderContext leaf = reader.leaves().get(i);
734-
int docBase = leaf.docBase;
735748
LeafReader leafReader = leaf.reader();
736749
int maxDoc = leafReader.maxDoc();
737750
FormattedDocValues docValues = ExponentialHistogramFieldMapper.createFormattedDocValues(leafReader, "field");
751+
NumericDocValues histoIndex = leafReader.getNumericDocValues("histo_index");
738752
for (int j = 0; j < maxDoc; j++) {
739-
var expectedHistogram = inputHistograms.get(docBase + j);
753+
assertThat(histoIndex.advanceExact(j), equalTo(true));
754+
int index = (int) histoIndex.longValue();
755+
var expectedHistogram = inputHistograms.get(index);
756+
seenCount++;
757+
740758
if (expectedHistogram == null) {
741759
assertThat(docValues.advanceExact(j), equalTo(false));
742760
expectThrows(IllegalStateException.class, docValues::nextValue);
@@ -750,6 +768,7 @@ public void testFormattedDocValues() throws IOException {
750768
}
751769
}
752770
}
771+
assertThat(seenCount, equalTo(inputHistograms.size()));
753772
}
754773
}
755774

x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.io.IOException;
2323
import java.util.Arrays;
24-
import java.util.Collections;
2524
import java.util.List;
2625
import java.util.stream.IntStream;
2726
import java.util.stream.Stream;
@@ -52,7 +51,7 @@ public static void addHistogramDoc(
5251
) {
5352
try {
5453
if (histogram == null) {
55-
iw.addDocument(Collections.emptyList());
54+
iw.addDocument(List.of(additionalFields));
5655
} else {
5756
ExponentialHistogramFieldMapper.HistogramDocValueFields docValues = ExponentialHistogramFieldMapper.buildDocValueFields(
5857
fieldName,

0 commit comments

Comments
 (0)