jpountz commented on code in PR #13346:
URL: https://github.com/apache/lucene/pull/13346#discussion_r1592546383


##########
lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseDocValuesFormatTestCase.java:
##########
@@ -1414,6 +1414,45 @@ protected void assertDVIterate(Directory dir) throws 
IOException {
     ir.close();
   }
 
+  protected void compareStoredFieldWithSortedNumericsDV(
+      DirectoryReader directoryReader, String storedField, String dvField) 
throws IOException {
+    for (LeafReaderContext leaf : directoryReader.leaves()) {
+      LeafReader reader = leaf.reader();
+      StoredFields storedFields = reader.storedFields();
+      SortedNumericDocValues docValues = 
reader.getSortedNumericDocValues(dvField);
+      if (docValues == null) {
+        // no stored values at all
+        for (int doc = 0; doc < reader.maxDoc(); doc++) {
+          assertArrayEquals(new String[0], 
storedFields.document(doc).getValues(storedField));
+        }
+        continue;
+      }
+      for (int doc = 0; doc < reader.maxDoc(); doc++) {
+        String[] storedValues = 
storedFields.document(doc).getValues(storedField);
+        if (storedValues.length == 0) {
+          assertFalse(docValues.advanceExact(doc));
+          continue;
+        }
+        switch (random().nextInt(3)) {
+          case 0 -> assertEquals(doc, docValues.nextDoc());
+          case 1 -> assertEquals(doc, docValues.advance(doc));
+          default -> assertTrue(docValues.advanceExact(doc));
+        }
+        assertEquals(doc, docValues.docID());
+        assertEquals(storedValues.length, docValues.docValueCount());
+        int repeats = 1 + random().nextInt(3);
+        for (int r = 0; r < repeats; r++) {
+          if (r > 0 || random().nextBoolean()) {
+            assertTrue(docValues.advanceExact(doc));
+          }
+          for (int v = 0; v < docValues.docValueCount(); v++) {
+            assertEquals(storedValues[v], 
Long.toString(docValues.nextValue()));
+          }
+        }
+      }
+    }

Review Comment:
   This loop looks good to me, I'm contemplating doing a second loop using 
advanceExact every Nth document in case there are bugs lurking in case we 
ignore some documents?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to