4040 */
4141class DocValuesConsumerUtil {
4242
43- static final MergeStats UNSUPPORTED = new MergeStats (false , -1 , -1 , false );
43+ static final MergeStats UNSUPPORTED = new MergeStats (false , -1 , -1 );
4444
4545 abstract static class TsdbDocValuesProducer extends EmptyDocValuesProducer {
4646
@@ -52,7 +52,7 @@ abstract static class TsdbDocValuesProducer extends EmptyDocValuesProducer {
5252
5353 }
5454
55- record MergeStats (boolean supported , long sumNumValues , int sumNumDocsWithField , boolean sumNumDocsWithFieldAccurate ) {}
55+ record MergeStats (boolean supported , long sumNumValues , int sumNumDocsWithField ) {}
5656
5757 static MergeStats compatibleWithOptimizedMerge (boolean optimizedMergeEnabled , MergeState mergeState , FieldInfo fieldInfo )
5858 throws IOException {
@@ -69,20 +69,16 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
6969
7070 long sumNumValues = 0 ;
7171 int sumNumDocsWithField = 0 ;
72- boolean sumNumDocsWithFieldAccurate = true ;
73-
7472 // TODO bring back codec version check? (per field doc values producer sits between ES87TSDBDocValuesConsumer)
7573 for (int i = 0 ; i < mergeState .docValuesProducers .length ; i ++) {
7674 DocValuesProducer docValuesProducer = mergeState .docValuesProducers [i ];
7775 switch (fieldInfo .getDocValuesType ()) {
7876 case NUMERIC -> {
7977 var numeric = docValuesProducer .getNumeric (fieldInfo );
8078 if (numeric instanceof ES87TSDBDocValuesProducer .BaseNumericDocValues baseNumeric ) {
81- sumNumDocsWithFieldAccurate = false ;
8279 var entry = baseNumeric .entry ;
8380 sumNumValues += entry .numValues ;
84- int numDocsWithField = getNumDocsWithField (entry , mergeState .maxDocs [i ]);
85- sumNumDocsWithField += numDocsWithField ;
81+ sumNumDocsWithField += entry .numDocsWithField ;
8682 } else if (numeric != null ) {
8783 return UNSUPPORTED ;
8884 }
@@ -96,12 +92,9 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
9692 } else {
9793 var singleton = DocValues .unwrapSingleton (sortedNumeric );
9894 if (singleton instanceof ES87TSDBDocValuesProducer .BaseNumericDocValues baseNumeric ) {
99- sumNumDocsWithFieldAccurate = false ;
10095 var entry = baseNumeric .entry ;
10196 sumNumValues += entry .numValues ;
102- // In this case the numDocsWithField doesn't get recorded in meta:
103- int numDocsWithField = getNumDocsWithField (entry , mergeState .maxDocs [i ]);
104- sumNumDocsWithField += numDocsWithField ;
97+ sumNumDocsWithField += entry .numDocsWithField ;
10598 } else if (sortedNumeric != null ) {
10699 return UNSUPPORTED ;
107100 }
@@ -110,12 +103,9 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
110103 case SORTED -> {
111104 var sorted = docValuesProducer .getSorted (fieldInfo );
112105 if (sorted instanceof ES87TSDBDocValuesProducer .BaseSortedDocValues baseSortedDocValues ) {
113- sumNumDocsWithFieldAccurate = false ;
114106 var entry = baseSortedDocValues .entry ;
115107 sumNumValues += entry .ordsEntry .numValues ;
116- // In this case the numDocsWithField doesn't get recorded in meta:v
117- int numDocsWithField = getNumDocsWithField (entry .ordsEntry , mergeState .maxDocs [i ]);
118- sumNumDocsWithField += numDocsWithField ;
108+ sumNumDocsWithField += entry .ordsEntry .numDocsWithField ;
119109 } else if (sorted != null ) {
120110 return UNSUPPORTED ;
121111 }
@@ -129,12 +119,9 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
129119 } else {
130120 var singleton = DocValues .unwrapSingleton (sortedSet );
131121 if (singleton instanceof ES87TSDBDocValuesProducer .BaseSortedDocValues baseSorted ) {
132- sumNumDocsWithFieldAccurate = false ;
133122 var entry = baseSorted .entry ;
134123 sumNumValues += entry .ordsEntry .numValues ;
135- // In this case the numDocsWithField doesn't get recorded in meta:
136- int numDocsWithField = getNumDocsWithField (entry .ordsEntry , mergeState .maxDocs [i ]);
137- sumNumDocsWithField += numDocsWithField ;
124+ sumNumDocsWithField += entry .ordsEntry .numDocsWithField ;
138125 } else if (sortedSet != null ) {
139126 return UNSUPPORTED ;
140127 }
@@ -144,19 +131,7 @@ static MergeStats compatibleWithOptimizedMerge(boolean optimizedMergeEnabled, Me
144131 }
145132 }
146133
147- return new MergeStats (true , sumNumValues , sumNumDocsWithField , sumNumDocsWithFieldAccurate );
148- }
149-
150- private static int getNumDocsWithField (ES87TSDBDocValuesProducer .NumericEntry entry , int maxDoc ) {
151- // In this case the numDocsWithField doesn't get recorded in meta:
152- if (entry .docsWithFieldOffset == -2 ) {
153- return 0 ;
154- } else if (entry .docsWithFieldOffset == -1 ) {
155- return maxDoc ;
156- } else {
157- // numDocsWithField doesn't matter in this case:
158- return 1 ;
159- }
134+ return new MergeStats (true , sumNumValues , sumNumDocsWithField );
160135 }
161136
162137 static DocValuesProducer mergeNumericProducer (MergeStats mergeStats , FieldInfo mergeFieldInfo , MergeState mergeState ) {
0 commit comments