Apache Solr open-source search software
Improve how Asserting* classes handle singleton doc values. (#1817)
Julie Tibshirani4fa432928759
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 2edfad575e7..2eb12284154 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -198,6 +198,8 @@ Improvements* LUCENE-9446: In BooleanQuery rewrite, always remove MatchAllDocsQuery filter clauseswhen 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.javaindex fd8c246ed5c..f246acfda7b 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);}@Overridediff --git a/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.java b/lucene/test-framework/src/java/org/apache/lucene/index/AssertingLeafReader.javaindex c7d15194427..d8a1c0c9e93 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);+ }+ }+@Overridepublic 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);+ }+ }+@Overridepublic int docID() {assertThread("Sorted set doc values", creationThread);@@ -1233,12 +1253,12 @@ public class AssertingLeafReader extends FilterLeafReader {@Overridepublic 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;