@@ -77,14 +77,13 @@ public void testMatchAll() throws IOException {
77
77
testCase (new SingleValueQuery (new MatchAll (Source .EMPTY ), "foo" ).asBuilder (), false , false , this ::runCase );
78
78
}
79
79
80
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/102997" )
81
80
public void testMatchSome () throws IOException {
82
81
int max = between (1 , 100 );
83
82
testCase (
84
83
new SingleValueQuery .Builder (new RangeQueryBuilder ("i" ).lt (max ), "foo" , new SingleValueQuery .Stats (), Source .EMPTY ),
85
84
false ,
86
85
false ,
87
- (fieldValues , count ) -> runCase (fieldValues , count , null , max )
86
+ (fieldValues , count ) -> runCase (fieldValues , count , null , max , false )
88
87
);
89
88
}
90
89
@@ -138,14 +137,13 @@ public void testNotMatchNone() throws IOException {
138
137
);
139
138
}
140
139
141
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/102997" )
142
140
public void testNotMatchSome () throws IOException {
143
141
int max = between (1 , 100 );
144
142
testCase (
145
143
new SingleValueQuery (new RangeQuery (Source .EMPTY , "i" , null , false , max , false , null ), "foo" ).negate (Source .EMPTY ).asBuilder (),
146
144
false ,
147
145
true ,
148
- (fieldValues , count ) -> runCase (fieldValues , count , max , 100 )
146
+ (fieldValues , count ) -> runCase (fieldValues , count , max , 100 , true )
149
147
);
150
148
}
151
149
@@ -154,22 +152,34 @@ interface TestCase {
154
152
void run (List <List <Object >> fieldValues , int count ) throws IOException ;
155
153
}
156
154
157
- private void runCase (List <List <Object >> fieldValues , int count , Integer docsStart , Integer docsStop ) {
155
+ /**
156
+ * Helper to run the checks of some of the test cases. This will perform two verifications: one about the count of the values the query
157
+ * is supposed to match and one on the Warnings that are supposed to be raised.
158
+ * @param fieldValues The indexed values of the field the query runs against.
159
+ * @param count The count of the docs the query matched.
160
+ * @param docsStart The start of the slice in fieldValues we want to consider. If `null`, the start will be 0.
161
+ * @param docsStop The end of the slice in fieldValues we want to consider. If `null`, the end will be the fieldValues size.
162
+ * @param scanForMVs Should the check for Warnings scan the entire fieldValues? This will override the docsStart:docsStop interval,
163
+ * which is needed for some cases.
164
+ */
165
+ private void runCase (List <List <Object >> fieldValues , int count , Integer docsStart , Integer docsStop , boolean scanForMVs ) {
158
166
int expected = 0 ;
159
167
int min = docsStart != null ? docsStart : 0 ;
160
168
int max = docsStop != null ? docsStop : fieldValues .size ();
161
- int valuesCount = 0 ;
169
+ int mvCountInRange = 0 ;
162
170
for (int i = min ; i < max ; i ++) {
163
- int mvCount = fieldValues .get (i ).size ();
164
- if (mvCount == 1 ) {
171
+ int valuesCount = fieldValues .get (i ).size ();
172
+ if (valuesCount == 1 ) {
165
173
expected ++;
174
+ } else if (valuesCount > 1 ) {
175
+ mvCountInRange ++;
166
176
}
167
- valuesCount += mvCount ;
168
177
}
169
178
assertThat (count , equalTo (expected ));
170
179
171
- // query's count runs against the full set, not just min-to-max
172
- if (valuesCount > 0 && fieldValues .stream ().anyMatch (x -> x .size () > 1 )) {
180
+ // the SingleValueQuery.TwoPhaseIteratorForSortedNumericsAndTwoPhaseQueries can scan all docs - and generate warnings - even if
181
+ // inner query matches none, so warn if MVs have been encountered within given range, OR if a full scan is required
182
+ if (mvCountInRange > 0 || (scanForMVs && fieldValues .stream ().anyMatch (x -> x .size () > 1 ))) {
173
183
assertWarnings (
174
184
"Line -1:-1: evaluation of [] failed, treating result as null. Only first 20 failures recorded." ,
175
185
"Line -1:-1: java.lang.IllegalArgumentException: single-value function encountered multi-value"
@@ -178,7 +188,7 @@ private void runCase(List<List<Object>> fieldValues, int count, Integer docsStar
178
188
}
179
189
180
190
private void runCase (List <List <Object >> fieldValues , int count ) {
181
- runCase (fieldValues , count , null , null );
191
+ runCase (fieldValues , count , null , null , false );
182
192
}
183
193
184
194
private void testCase (SingleValueQuery .Builder builder , boolean rewritesToMatchNone , boolean subHasTwoPhase , TestCase testCase )
0 commit comments