2929import org .elasticsearch .compute .data .BytesRefVector ;
3030import org .elasticsearch .compute .data .DocBlock ;
3131import org .elasticsearch .compute .data .DoubleBlock ;
32+ import org .elasticsearch .compute .data .DoubleVector ;
3233import org .elasticsearch .compute .data .ElementType ;
3334import org .elasticsearch .compute .data .Page ;
3435import org .elasticsearch .compute .data .Vector ;
@@ -71,7 +72,7 @@ public void testDenseCollectorSmall() throws IOException {
7172 collector .finish ();
7273 try (T result = (T ) collector .build ()) {
7374 for (int i = 0 ; i <= 2 ; i ++) {
74- assertEquals ( getValueAt ( result , i ), valueForMatch () );
75+ assertCollectedResultMatch ( result , i , true );
7576 }
7677 }
7778 }
@@ -86,7 +87,7 @@ public void testDenseCollectorSimple() throws IOException {
8687 collector .finish ();
8788 try (T result = (T ) collector .build ()) {
8889 for (int i = 0 ; i < 11 ; i ++) {
89- assertEquals ( getValueAt ( result , i ) , i == 2 || i == 5 ? valueForMatch () : valueForNoMatch () );
90+ assertCollectedResultMatch ( result , i , i == 2 || i == 5 );
9091 }
9192 }
9293 }
@@ -109,12 +110,22 @@ public void testDenseCollector() throws IOException {
109110 collector .finish ();
110111 try (T result = (T ) collector .build ()) {
111112 for (int i = 0 ; i < length ; i ++) {
112- assertEquals ( getValueAt ( result , i ) , expected [i ] ? valueForMatch () : valueForNoMatch () );
113+ assertCollectedResultMatch ( result , i , expected [i ]);
113114 }
114115 }
115116 }
116117 }
117118
119+ /**
120+ * Create a dense collector for the given range.
121+ */
122+ protected abstract LuceneQueryEvaluator .DenseCollector <U > createDenseCollector (int min , int max );
123+
124+ /**
125+ * Chceks that the collected results at the given position corresponds to a match or no match
126+ */
127+ protected abstract void assertCollectedResultMatch (T resultVector , int position , boolean isMatch );
128+
118129 public void testTermQuery () throws IOException {
119130 Set <String > values = values ();
120131 String term = values .iterator ().next ();
@@ -162,7 +173,7 @@ protected void assertTermsQuery(List<Page> results, Set<String> matching, int ex
162173 for (int i = 0 ; i < page .getPositionCount (); i ++) {
163174 BytesRef termAtPosition = terms .getBytesRef (i , new BytesRef ());
164175 boolean isMatch = matching .contains (termAtPosition .utf8ToString ());
165- assertResultMatch (resultVector , i , isMatch );
176+ assertTermResultMatch (resultVector , i , isMatch );
166177 if (isMatch ) {
167178 matchCount ++;
168179 }
@@ -171,7 +182,10 @@ protected void assertTermsQuery(List<Page> results, Set<String> matching, int ex
171182 assertThat (matchCount , equalTo (expectedMatchCount ));
172183 }
173184
174- protected abstract void assertResultMatch (T resultVector , int position , boolean isMatch );
185+ /**
186+ * Checks that the result at the given position corresponds to a term match or no match
187+ */
188+ protected abstract void assertTermResultMatch (T resultVector , int position , boolean isMatch );
175189
176190 private List <Page > runQuery (Set <String > values , Query query , boolean shuffleDocs ) throws IOException {
177191 DriverContext driverContext = driverContext ();
@@ -278,31 +292,11 @@ private static LuceneOperator.Factory luceneOperatorFactory(IndexReader reader,
278292 // Returns the block index for the results to check
279293 protected abstract int resultsBlockIndex (Page page );
280294
281- /**
282- * Create a dense collector for the given range.
283- */
284- protected abstract LuceneQueryEvaluator .DenseCollector <U > createDenseCollector (int min , int max );
285-
286295 /**
287296 * Returns a test scorer to use for scoring docs. Can be null
288297 */
289298 protected abstract Scorable getScorer ();
290299
291- /**
292- * Retrieves the value at a given index from the vector. Need to do this as Vector does not export a generic get() method
293- */
294- protected abstract Object getValueAt (T vector , int i );
295-
296- /**
297- * Value that should be returned for a matching doc from the resulting vector
298- */
299- protected abstract Object valueForMatch ();
300-
301- /**
302- * Value that should be returned for a non-matching doc from the resulting vector
303- */
304- protected abstract Object valueForNoMatch ();
305-
306300 /**
307301 * Create the operator to test
308302 */
0 commit comments