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) { if (idLookup != null) {
return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null); return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null);
} else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) { } else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) {
// Employ precomputed BitSet optimization // Employ caching BitSet optimization
return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value)); return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value));
} else { } else {
return makeNonDictionaryEncodedValueMatcherGeneric(selector, value); return makeNonDictionaryEncodedValueMatcherGeneric(selector, value);

View File

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

View File

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