use of org.apache.druid.query.filter.vector.VectorMatch in project druid by druid-io.
the class OrFilter method makeVectorMatcher.
private static VectorValueMatcher makeVectorMatcher(final VectorValueMatcher[] baseMatchers) {
Preconditions.checkState(baseMatchers.length > 0);
if (baseMatchers.length == 1) {
return baseMatchers[0];
}
return new BaseVectorValueMatcher(baseMatchers[0]) {
final VectorMatch currentMask = VectorMatch.wrap(new int[getMaxVectorSize()]);
final VectorMatch scratch = VectorMatch.wrap(new int[getMaxVectorSize()]);
final VectorMatch retVal = VectorMatch.wrap(new int[getMaxVectorSize()]);
@Override
public ReadableVectorMatch match(final ReadableVectorMatch mask) {
ReadableVectorMatch currentMatch = baseMatchers[0].match(mask);
// Initialize currentMask = mask, then progressively remove rows from the mask as we find matches for them.
// This isn't necessary for correctness (we could use the original "mask" on every call to "match") but it
// allows for short-circuiting on a row-by-row basis.
currentMask.copyFrom(mask);
// Initialize retVal = currentMatch, the rows matched by the first matcher. We'll add more as we loop over
// the rest of the matchers.
retVal.copyFrom(currentMatch);
for (int i = 1; i < baseMatchers.length; i++) {
if (retVal.isAllTrue(getCurrentVectorSize())) {
// Short-circuit if the entire vector is true.
break;
}
currentMask.removeAll(currentMatch);
currentMatch = baseMatchers[i].match(currentMask);
retVal.addAll(currentMatch, scratch);
if (currentMatch == currentMask) {
// baseMatchers[i] matched every remaining row. Short-circuit out.
break;
}
}
assert retVal.isValid(mask);
return retVal;
}
};
}
use of org.apache.druid.query.filter.vector.VectorMatch in project druid by druid-io.
the class NotFilter method makeVectorMatcher.
@Override
public VectorValueMatcher makeVectorMatcher(final VectorColumnSelectorFactory factory) {
final VectorValueMatcher baseMatcher = baseFilter.makeVectorMatcher(factory);
return new BaseVectorValueMatcher(baseMatcher) {
final VectorMatch scratch = VectorMatch.wrap(new int[factory.getMaxVectorSize()]);
@Override
public ReadableVectorMatch match(final ReadableVectorMatch mask) {
final ReadableVectorMatch baseMatch = baseMatcher.match(mask);
scratch.copyFrom(mask);
scratch.removeAll(baseMatch);
assert scratch.isValid(mask);
return scratch;
}
};
}
Aggregations