Lazy-ify IncrementalIndex filtering too. (#5852)

* Lazy-ify IncrementalIndex filtering too.

Follow-up to #5403, which only lazy-ified cursor-based filtering
on QueryableIndex.

* Fix logic error.
This commit is contained in:
Gian Merlino 2018-06-06 18:03:34 -07:00 committed by Jonathan Wei
parent 37409dc2f4
commit 3af95913a9
3 changed files with 19 additions and 7 deletions

View File

@ -52,7 +52,7 @@ public final class DimensionSelectorUtils
if (idLookup != null) {
return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null);
} else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) {
// Employ precomputed BitSet optimization
// Employ caching BitSet optimization
return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value));
} else {
return makeNonDictionaryEncodedValueMatcherGeneric(selector, value);

View File

@ -177,7 +177,7 @@ public class StringDimensionIndexer implements DimensionIndexer<Integer, int[],
this.idToIndex = new int[length];
this.indexToId = new int[length];
int index = 0;
for (IntIterator iterator = sortedMap.values().iterator(); iterator.hasNext();) {
for (IntIterator iterator = sortedMap.values().iterator(); iterator.hasNext(); ) {
int id = iterator.nextInt();
idToIndex[id] = index;
indexToId[index] = id;
@ -496,7 +496,7 @@ public class StringDimensionIndexer implements DimensionIndexer<Integer, int[],
return BooleanValueMatcher.of(false);
}
} else {
// Employ precomputed BitSet optimization
// Employ caching BitSet optimization
return makeValueMatcher(Predicates.equalTo(value));
}
}
@ -504,8 +504,11 @@ public class StringDimensionIndexer implements DimensionIndexer<Integer, int[],
@Override
public ValueMatcher makeValueMatcher(final Predicate<String> predicate)
{
final BitSet predicateMatchingValueIds = DimensionSelectorUtils.makePredicateMatchingSet(this, predicate);
final BitSet checkedIds = new BitSet(maxId);
final BitSet matchingIds = new BitSet(maxId);
final boolean matchNull = predicate.apply(null);
// Lazy matcher; only check an id if matches() is called.
return new ValueMatcher()
{
@Override
@ -522,8 +525,17 @@ public class StringDimensionIndexer implements DimensionIndexer<Integer, int[],
}
for (int id : dimsInt) {
if (predicateMatchingValueIds.get(id)) {
return true;
if (checkedIds.get(id)) {
if (matchingIds.get(id)) {
return true;
}
} else {
final boolean matches = predicate.apply(lookupName(id));
checkedIds.set(id);
if (matches) {
matchingIds.set(id);
return true;
}
}
}
return false;

View File

@ -259,7 +259,7 @@ public class SimpleDictionaryEncodedColumn implements DictionaryEncodedColumn<St
return BooleanValueMatcher.of(false);
}
} else {
// Employ precomputed BitSet optimization
// Employ caching BitSet optimization
return makeValueMatcher(Predicates.equalTo(value));
}
}