1818package org .apache .cassandra .index .sai .disk .v1 ;
1919
2020import java .io .IOException ;
21- import java .util .ArrayList ;
2221import java .util .Collection ;
23- import java .util .HashMap ;
2422import java .util .List ;
25- import java .util .Map ;
2623import java .util .stream .Collectors ;
2724
25+ import org .junit .Before ;
2826import org .junit .Test ;
2927
3028import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
3735import org .apache .cassandra .index .sai .SAIUtil ;
3836import org .apache .cassandra .index .sai .disk .MemtableTermsIterator ;
3937import org .apache .cassandra .index .sai .disk .PostingList ;
40- import org .apache .cassandra .index .sai .disk .RAMStringIndexer ;
4138import org .apache .cassandra .index .sai .disk .TermsIterator ;
4239import org .apache .cassandra .index .sai .disk .format .IndexComponentType ;
4340import org .apache .cassandra .index .sai .disk .format .IndexComponents ;
5047import org .apache .cassandra .index .sai .utils .SaiRandomizedTest ;
5148import org .apache .cassandra .index .sai .utils .TypeUtil ;
5249import org .apache .cassandra .io .util .FileHandle ;
53- import org .apache .cassandra .utils .ByteBufferUtil ;
5450import org .apache .cassandra .utils .Pair ;
5551import org .apache .cassandra .utils .bytecomparable .ByteComparable ;
5652import org .apache .cassandra .utils .bytecomparable .ByteSourceInverse ;
57- import org .apache .lucene .util .BytesRef ;
5853
5954import static org .apache .cassandra .index .sai .disk .v1 .InvertedIndexBuilder .buildStringTermsEnum ;
6055import static org .apache .cassandra .index .sai .metrics .QueryEventListeners .NO_OP_TRIE_LISTENER ;
@@ -63,6 +58,8 @@ public class TermsReaderTest extends SaiRandomizedTest
6358{
6459 public static final ByteComparable .Version VERSION = TypeUtil .BYTE_COMPARABLE_VERSION ;
6560
61+ private final Version version ;
62+
6663 @ ParametersFactory ()
6764 public static Collection <Object []> data ()
6865 {
@@ -72,7 +69,11 @@ public static Collection<Object[]> data()
7269 return Version .ALL .stream ().map (v -> new Object []{v }).collect (Collectors .toList ());
7370 }
7471
75- private final Version version ;
72+ @ Before
73+ public void setCurrentSAIVersion ()
74+ {
75+ SAIUtil .setCurrentVersion (version );
76+ }
7677
7778 public TermsReaderTest (Version version )
7879 {
@@ -239,6 +240,8 @@ private Int2IntHashMap createMockDocLengths(List<InvertedIndexBuilder.TermsEnum>
239240
240241 private List <InvertedIndexBuilder .TermsEnum > buildTermsEnum (Version version , int terms , int postings )
241242 {
242- return buildStringTermsEnum (version , terms , postings , () -> randomSimpleString (4 , 10 ), () -> nextInt (0 , Integer .MAX_VALUE ));
243+ // We use terms * postings * 2 as the upper bound on row ids used in the postings list to allow for a somewhat
244+ // sparse mapping but not one that is too sparse.
245+ return buildStringTermsEnum (version , terms , postings , () -> randomSimpleString (4 , 10 ), () -> nextInt (0 , terms * postings * 2 ));
243246 }
244247}
0 commit comments