@@ -77,14 +77,13 @@ public void testMatchAll() throws IOException {
7777 testCase (new SingleValueQuery (new MatchAll (Source .EMPTY ), "foo" ).asBuilder (), false , false , this ::runCase );
7878 }
7979
80- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/102997" )
8180 public void testMatchSome () throws IOException {
8281 int max = between (1 , 100 );
8382 testCase (
8483 new SingleValueQuery .Builder (new RangeQueryBuilder ("i" ).lt (max ), "foo" , new SingleValueQuery .Stats (), Source .EMPTY ),
8584 false ,
8685 false ,
87- (fieldValues , count ) -> runCase (fieldValues , count , null , max )
86+ (fieldValues , count ) -> runCase (fieldValues , count , null , max , false )
8887 );
8988 }
9089
@@ -138,14 +137,13 @@ public void testNotMatchNone() throws IOException {
138137 );
139138 }
140139
141- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/102997" )
142140 public void testNotMatchSome () throws IOException {
143141 int max = between (1 , 100 );
144142 testCase (
145143 new SingleValueQuery (new RangeQuery (Source .EMPTY , "i" , null , false , max , false , null ), "foo" ).negate (Source .EMPTY ).asBuilder (),
146144 false ,
147145 true ,
148- (fieldValues , count ) -> runCase (fieldValues , count , max , 100 )
146+ (fieldValues , count ) -> runCase (fieldValues , count , max , 100 , true )
149147 );
150148 }
151149
@@ -154,22 +152,34 @@ interface TestCase {
154152 void run (List <List <Object >> fieldValues , int count ) throws IOException ;
155153 }
156154
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 ) {
158166 int expected = 0 ;
159167 int min = docsStart != null ? docsStart : 0 ;
160168 int max = docsStop != null ? docsStop : fieldValues .size ();
161- int valuesCount = 0 ;
169+ int mvCountInRange = 0 ;
162170 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 ) {
165173 expected ++;
174+ } else if (valuesCount > 1 ) {
175+ mvCountInRange ++;
166176 }
167- valuesCount += mvCount ;
168177 }
169178 assertThat (count , equalTo (expected ));
170179
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 ))) {
173183 assertWarnings (
174184 "Line -1:-1: evaluation of [] failed, treating result as null. Only first 20 failures recorded." ,
175185 "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
178188 }
179189
180190 private void runCase (List <List <Object >> fieldValues , int count ) {
181- runCase (fieldValues , count , null , null );
191+ runCase (fieldValues , count , null , null , false );
182192 }
183193
184194 private void testCase (SingleValueQuery .Builder builder , boolean rewritesToMatchNone , boolean subHasTwoPhase , TestCase testCase )
0 commit comments