From 11fa773ad7184e9732148352bbd8239f026f18e0 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Wed, 26 Nov 2025 12:01:53 +0100 Subject: [PATCH 1/2] Fix and unmute ExponentialHistogramFieldMapperTests.testFormattedDocValues --- muted-tests.yml | 3 --- .../ExponentialHistogramFieldMapperTests.java | 23 ++++++++++++++++--- ...xponentialHistogramAggregatorTestCase.java | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 07383b10c408b..588030dff14c0 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -429,9 +429,6 @@ tests: - class: org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT method: testCreatesEisChatCompletion_DoesNotRemoveEndpointWhenNoLongerAuthorized issue: https://github.com/elastic/elasticsearch/issues/138480 -- class: org.elasticsearch.xpack.exponentialhistogram.ExponentialHistogramFieldMapperTests - method: testFormattedDocValues - issue: https://github.com/elastic/elasticsearch/issues/138504 - class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackLookupJoinIT method: testLookupExplosionBigString issue: https://github.com/elastic/elasticsearch/issues/138510 diff --git a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java index d796052ad36b2..16a35837a5f17 100644 --- a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java +++ b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java @@ -7,11 +7,13 @@ package org.elasticsearch.xpack.exponentialhistogram; +import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.analysis.MockAnalyzer; import org.apache.lucene.tests.index.RandomIndexWriter; @@ -59,6 +61,7 @@ import java.util.Map; import java.util.OptionalDouble; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; import static org.elasticsearch.exponentialhistogram.ExponentialHistogram.MAX_INDEX; @@ -725,18 +728,31 @@ public void testFormattedDocValues() throws IOException { IndexWriterConfig config = LuceneTestCase.newIndexWriterConfig(random(), new MockAnalyzer(random())); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory, config); - inputHistograms.forEach(histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc(indexWriter, "field", histo)); + + // give each document a ID field because we are not guaranteed to read them in-order later + AtomicInteger currentId = new AtomicInteger(0); + inputHistograms.forEach(histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc( + indexWriter, + "field", + histo, + new NumericDocValuesField("histo_index", currentId.getAndIncrement()) + )); indexWriter.close(); + int seenCount = 0; try (DirectoryReader reader = DirectoryReader.open(directory)) { for (int i = 0; i < reader.leaves().size(); i++) { LeafReaderContext leaf = reader.leaves().get(i); - int docBase = leaf.docBase; LeafReader leafReader = leaf.reader(); int maxDoc = leafReader.maxDoc(); FormattedDocValues docValues = ExponentialHistogramFieldMapper.createFormattedDocValues(leafReader, "field"); + NumericDocValues histoIndex = leafReader.getNumericDocValues("histo_index"); for (int j = 0; j < maxDoc; j++) { - var expectedHistogram = inputHistograms.get(docBase + j); + assertThat(histoIndex.advanceExact(j), equalTo(true)); + int index = (int) histoIndex.longValue(); + var expectedHistogram = inputHistograms.get(index); + seenCount++; + if (expectedHistogram == null) { assertThat(docValues.advanceExact(j), equalTo(false)); expectThrows(IllegalStateException.class, docValues::nextValue); @@ -750,6 +766,7 @@ public void testFormattedDocValues() throws IOException { } } } + assertThat(seenCount, equalTo(inputHistograms.size())); } } diff --git a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java index 778a66d93ca9a..de51efcc485c5 100644 --- a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java +++ b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java @@ -52,7 +52,7 @@ public static void addHistogramDoc( ) { try { if (histogram == null) { - iw.addDocument(Collections.emptyList()); + iw.addDocument(List.of(additionalFields)); } else { ExponentialHistogramFieldMapper.HistogramDocValueFields docValues = ExponentialHistogramFieldMapper.buildDocValueFields( fieldName, From 30a75a8a7c6b8aabf814688634be617ab1e4300d Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Wed, 26 Nov 2025 11:12:53 +0000 Subject: [PATCH 2/2] [CI] Auto commit changes from spotless --- .../ExponentialHistogramFieldMapperTests.java | 14 ++++++++------ .../ExponentialHistogramAggregatorTestCase.java | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java index 16a35837a5f17..86817dc4d4168 100644 --- a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java +++ b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramFieldMapperTests.java @@ -731,12 +731,14 @@ public void testFormattedDocValues() throws IOException { // give each document a ID field because we are not guaranteed to read them in-order later AtomicInteger currentId = new AtomicInteger(0); - inputHistograms.forEach(histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc( - indexWriter, - "field", - histo, - new NumericDocValuesField("histo_index", currentId.getAndIncrement()) - )); + inputHistograms.forEach( + histo -> ExponentialHistogramAggregatorTestCase.addHistogramDoc( + indexWriter, + "field", + histo, + new NumericDocValuesField("histo_index", currentId.getAndIncrement()) + ) + ); indexWriter.close(); int seenCount = 0; diff --git a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java index de51efcc485c5..8b5134245a66b 100644 --- a/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java +++ b/x-pack/plugin/mapper-exponential-histogram/src/test/java/org/elasticsearch/xpack/exponentialhistogram/aggregations/ExponentialHistogramAggregatorTestCase.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.IntStream; import java.util.stream.Stream;