1818
1919import org .apache .logging .log4j .LogManager ;
2020import org .apache .logging .log4j .Logger ;
21- import org .apache .lucene .index .DocValues ;
22- import org .apache .lucene .index .NumericDocValues ;
2321import org .apache .lucene .index .SortedNumericDocValues ;
2422import org .apache .lucene .search .DocIdSetIterator ;
2523import org .apache .lucene .util .DocIdSetBuilder ;
@@ -51,11 +49,14 @@ static class StarTreeResult {
5149 final DocIdSetBuilder _matchedDocIds ;
5250 final Set <String > _remainingPredicateColumns ;
5351 final int numOfMatchedDocs ;
52+ final int maxMatchedDoc ;
5453
55- StarTreeResult (DocIdSetBuilder matchedDocIds , Set <String > remainingPredicateColumns , int numOfMatchedDocs ) {
54+ StarTreeResult (DocIdSetBuilder matchedDocIds , Set <String > remainingPredicateColumns , int numOfMatchedDocs ,
55+ int maxMatchedDoc ) {
5656 _matchedDocIds = matchedDocIds ;
5757 _remainingPredicateColumns = remainingPredicateColumns ;
5858 this .numOfMatchedDocs = numOfMatchedDocs ;
59+ this .maxMatchedDoc = maxMatchedDoc ;
5960 }
6061 }
6162
@@ -68,7 +69,6 @@ static class StarTreeResult {
6869
6970 DocIdSetBuilder .BulkAdder adder ;
7071 Map <String , SortedNumericDocValues > dimValueMap ;
71- int docNum ;
7272 public StarTreeFilter (
7373 StarTreeAggregatedValues starTreeAggrStructure ,
7474 Map <String , List <Predicate <Long >>> predicateEvaluators ,
@@ -82,7 +82,6 @@ public StarTreeFilter(
8282
8383 // TODO : this should be the maximum number of doc values
8484 docsWithField = new DocIdSetBuilder (Integer .MAX_VALUE );
85- docNum = 0 ;
8685 }
8786
8887 /**
@@ -97,13 +96,14 @@ public StarTreeFilter(
9796 // 1706268600 / (60*60*1000) * (60*60*1000)
9897 public DocIdSetIterator getStarTreeResult () throws IOException {
9998 StarTreeResult starTreeResult = traverseStarTree ();
99+ logger .info ("Matched docs in star tree : {}" , starTreeResult .numOfMatchedDocs );
100100 List <DocIdSetIterator > andIterators = new ArrayList <>();
101101 andIterators .add (starTreeResult ._matchedDocIds .build ().iterator ());
102102 DocIdSetIterator docIdSetIterator = andIterators .get (0 );
103103 int docCount = 0 ;
104104 for (String remainingPredicateColumn : starTreeResult ._remainingPredicateColumns ) {
105105 // TODO : set to max value of doc values
106- DocIdSetBuilder builder = new DocIdSetBuilder (starTreeResult .numOfMatchedDocs );
106+ DocIdSetBuilder builder = new DocIdSetBuilder (starTreeResult .maxMatchedDoc );
107107 List <Predicate <Long >> compositePredicateEvaluators = _predicateEvaluators .get (remainingPredicateColumn );
108108 SortedNumericDocValues ndv = this .dimValueMap .get (remainingPredicateColumn );
109109 List <Integer > docIds = new ArrayList <>();
@@ -166,6 +166,9 @@ private StarTreeResult traverseStarTree() throws IOException {
166166 globalRemainingPredicateColumns = new HashSet <>(remainingPredicateColumns );
167167 }
168168
169+ int matchedDocsCountInStarTree = 0 ;
170+ int maxDocNum = -1 ;
171+
169172 StarTreeNode starTreeNode ;
170173 List <Integer > docIds = new ArrayList <>();
171174 while ((starTreeNode = queue .poll ()) != null ) {
@@ -185,7 +188,8 @@ private StarTreeResult traverseStarTree() throws IOException {
185188 if (remainingPredicateColumns .isEmpty () && remainingGroupByColumns .isEmpty ()) {
186189 int docId = starTreeNode .getAggregatedDocId ();
187190 docIds .add (docId );
188- docNum = docId > docNum ? docId : docNum ;
191+ matchedDocsCountInStarTree ++;
192+ maxDocNum = docId > maxDocNum ? docId : maxDocNum ;
189193 continue ;
190194 }
191195
@@ -197,7 +201,8 @@ private StarTreeResult traverseStarTree() throws IOException {
197201 if (starTreeNode .isLeaf ()) {
198202 for (long i = starTreeNode .getStartDocId (); i < starTreeNode .getEndDocId (); i ++) {
199203 docIds .add ((int )i );
200- docNum = (int )i > docNum ? (int )i : docNum ;
204+ matchedDocsCountInStarTree ++;
205+ maxDocNum = (int )i > maxDocNum ? (int )i : maxDocNum ;
201206 }
202207 continue ;
203208 }
@@ -294,7 +299,8 @@ private StarTreeResult traverseStarTree() throws IOException {
294299 return new StarTreeResult (
295300 docsWithField ,
296301 globalRemainingPredicateColumns != null ? globalRemainingPredicateColumns : Collections .emptySet (),
297- docNum
302+ matchedDocsCountInStarTree ,
303+ maxDocNum
298304 );
299305 }
300306}
0 commit comments