You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2020/09/03 09:46:21 UTC

[lucene-solr] 01/02: Improve how Asserting* classes handle singleton doc values. (#1817)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit adb323c41caa24126bb533fcba1ce8968c900216
Author: Julie Tibshirani <ju...@elastic.co>
AuthorDate: Thu Sep 3 02:41:11 2020 -0700

    Improve how Asserting* classes handle singleton doc values. (#1817)
    
    Some queries use DocValues.unwrapSingleton to execute different logic for
    single-valued doc values. When tests use an AssertingLeafReader, unwrapSingleton
    will never unwrap the doc values, as they don't have the expected class. So some
    queries have code paths that are never exercised with an AssertingLeafReader.
    
    This change makes sure to preserve the expected classes when creating asserting
    doc values.
---
 lucene/CHANGES.txt                                 |  2 ++
 .../codecs/asserting/AssertingDocValuesFormat.java |  4 +--
 .../apache/lucene/index/AssertingLeafReader.java   | 32 ++++++++++++++++++----
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8fcb400..ba969ea 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -37,6 +37,8 @@ Improvements
 * LUCENE-9446: In BooleanQuery rewrite, always remove MatchAllDocsQuery filter clauses
   when possible. (Julie Tibshirani)
 
+* LUCENE-9501: Improve how Asserting* test classes handle singleton doc values.
+
 Optimizations
 ---------------------
 
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
index fd8c246..f246acf 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
@@ -274,7 +274,7 @@ public class AssertingDocValuesFormat extends DocValuesFormat {
       assert field.getDocValuesType() == DocValuesType.SORTED_NUMERIC;
       SortedNumericDocValues values = in.getSortedNumeric(field);
       assert values != null;
-      return new AssertingLeafReader.AssertingSortedNumericDocValues(values, maxDoc);
+      return AssertingLeafReader.AssertingSortedNumericDocValues.create(values, maxDoc);
     }
     
     @Override
@@ -285,7 +285,7 @@ public class AssertingDocValuesFormat extends DocValuesFormat {
       assert field.getDocValuesType() == DocValuesType.SORTED_SET;
       SortedSetDocValues values = in.getSortedSet(field);
       assert values != null;
-      return new AssertingLeafReader.AssertingSortedSetDocValues(values, maxDoc);
+      return AssertingLeafReader.AssertingSortedSetDocValues.create(values, maxDoc);
     }
     
     @Override
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.java b/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.java
index d89bd1f..b6c01f9 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.java
@@ -827,7 +827,7 @@ public class AssertingLeafReader extends FilterLeafReader {
       return result;
     }
   }
-  
+
   /** Wraps a SortedNumericDocValues but with additional asserts */
   public static class AssertingSortedNumericDocValues extends SortedNumericDocValues {
     private final Thread creationThread = Thread.currentThread();
@@ -836,12 +836,22 @@ public class AssertingLeafReader extends FilterLeafReader {
     private int lastDocID = -1;
     private int valueUpto;
     private boolean exists;
-    
-    public AssertingSortedNumericDocValues(SortedNumericDocValues in, int maxDoc) {
+
+    private AssertingSortedNumericDocValues(SortedNumericDocValues in, int maxDoc) {
       this.in = in;
       this.maxDoc = maxDoc;
     }
 
+    public static SortedNumericDocValues create(SortedNumericDocValues in, int maxDoc) {
+      NumericDocValues singleDocValues = DocValues.unwrapSingleton(in);
+      if (singleDocValues == null) {
+        return new AssertingSortedNumericDocValues(in, maxDoc);
+      } else {
+        NumericDocValues assertingDocValues = new AssertingNumericDocValues(singleDocValues, maxDoc);
+        return DocValues.singleton(assertingDocValues);
+      }
+    }
+
     @Override
     public int docID() {
       return in.docID();
@@ -924,13 +934,23 @@ public class AssertingLeafReader extends FilterLeafReader {
     private long lastOrd = NO_MORE_ORDS;
     private boolean exists;
     
-    public AssertingSortedSetDocValues(SortedSetDocValues in, int maxDoc) {
+    private AssertingSortedSetDocValues(SortedSetDocValues in, int maxDoc) {
       this.in = in;
       this.maxDoc = maxDoc;
       this.valueCount = in.getValueCount();
       assert valueCount >= 0;
     }
 
+    public static SortedSetDocValues create(SortedSetDocValues in, int maxDoc) {
+      SortedDocValues singleDocValues = DocValues.unwrapSingleton(in);
+      if (singleDocValues == null) {
+        return new AssertingSortedSetDocValues(in, maxDoc);
+      } else {
+        SortedDocValues assertingDocValues = new AssertingSortedDocValues(singleDocValues, maxDoc);
+        return DocValues.singleton(assertingDocValues);
+      }
+    }
+
     @Override
     public int docID() {
       assertThread("Sorted set doc values", creationThread);
@@ -1233,12 +1253,12 @@ public class AssertingLeafReader extends FilterLeafReader {
   
   @Override
   public SortedNumericDocValues getSortedNumericDocValues(String field) throws IOException {
-    SortedNumericDocValues dv = super.getSortedNumericDocValues(field);
     FieldInfo fi = getFieldInfos().fieldInfo(field);
+    SortedNumericDocValues dv = super.getSortedNumericDocValues(field);
     if (dv != null) {
       assert fi != null;
       assert fi.getDocValuesType() == DocValuesType.SORTED_NUMERIC;
-      return new AssertingSortedNumericDocValues(dv, maxDoc());
+      return AssertingSortedNumericDocValues.create(dv, maxDoc());
     } else {
       assert fi == null || fi.getDocValuesType() != DocValuesType.SORTED_NUMERIC;
       return null;