mkhludnev commented on a change in pull request #1462: URL: https://github.com/apache/lucene-solr/pull/1462#discussion_r419706467
########## File path: lucene/grouping/src/test/org/apache/lucene/search/grouping/DocValuesPoolingReaderTest.java ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search.grouping; + +import java.io.IOException; + +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.document.BinaryDocValuesField; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.NumericDocValuesField; +import org.apache.lucene.document.SortedDocValuesField; +import org.apache.lucene.document.SortedNumericDocValuesField; +import org.apache.lucene.document.SortedSetDocValuesField; +import org.apache.lucene.index.BinaryDocValues; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.SortedDocValues; +import org.apache.lucene.index.SortedNumericDocValues; +import org.apache.lucene.index.SortedSetDocValues; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class DocValuesPoolingReaderTest extends LuceneTestCase { + + private static RandomIndexWriter w; + private static Directory dir; + private static DirectoryReader reader; + + @BeforeClass + public static void index() throws IOException { + dir = newDirectory(); + w = new RandomIndexWriter( + random(), + dir, + newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy())); + Document doc = new Document(); + doc.add(new BinaryDocValuesField("bin", new BytesRef("binary"))); + doc.add(new BinaryDocValuesField("bin2", new BytesRef("binary2"))); + + doc.add(new NumericDocValuesField("num", 1L)); + doc.add(new NumericDocValuesField("num2", 2L)); + + doc.add(new SortedNumericDocValuesField("sortnum", 3L)); + doc.add(new SortedNumericDocValuesField("sortnum2", 4L)); + + doc.add(new SortedDocValuesField("sort", new BytesRef("sorted"))); + doc.add(new SortedDocValuesField("sort2", new BytesRef("sorted2"))); + + doc.add(new SortedSetDocValuesField("sortset", new BytesRef("sortedset"))); + doc.add(new SortedSetDocValuesField("sortset2", new BytesRef("sortedset2"))); + + w.addDocument(doc); + w.commit(); + reader = w.getReader(); + w.close(); + } + + public void testDVCache() throws IOException { + assertFalse(reader.leaves().isEmpty()); + for (LeafReaderContext leaf : reader.leaves()) { + final DocValuesPoolingReader caching = new DocValuesPoolingReader(leaf.reader()); + + assertSame(assertBinaryDV(caching, "bin", "binary"), + caching.getBinaryDocValues("bin")); + assertSame(assertBinaryDV(caching, "bin2", "binary2"), + caching.getBinaryDocValues("bin2")); + + assertSame(assertNumericDV(caching, "num", 1L), + caching.getNumericDocValues("num")); + assertSame(assertNumericDV(caching, "num2", 2L), + caching.getNumericDocValues("num2")); + + assertSame(assertSortedNumericDV(caching, "sortnum", 3L), + caching.getSortedNumericDocValues("sortnum")); + assertSame(assertSortedNumericDV(caching, "sortnum2", 4L), + caching.getSortedNumericDocValues("sortnum2")); + + assertSame(assertSortedDV(caching, "sort", "sorted"), + caching.getSortedDocValues("sort")); + assertSame(assertSortedDV(caching, "sort2", "sorted2"), + caching.getSortedDocValues("sort2")); Review comment: Hi, @romseygeek , thanks for feedback. I agree to add more tests. I suppose such functionality is not necessary. Docs arrive into grouping collector in-order. Thus, different group heads might read vals one by one also in-order. When it needs to jump back and read cached values? Currently, test coverage is shallow, but it proves this read-once idea. ---------------------------------------------------------------- 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. 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