Search in sources :

Example 1 with VectorMatch

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;
        }
    };
}
Also used : ReadableVectorMatch(org.apache.druid.query.filter.vector.ReadableVectorMatch) VectorMatch(org.apache.druid.query.filter.vector.VectorMatch) ReadableVectorMatch(org.apache.druid.query.filter.vector.ReadableVectorMatch) BaseVectorValueMatcher(org.apache.druid.query.filter.vector.BaseVectorValueMatcher)

Example 2 with VectorMatch

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;
        }
    };
}
Also used : BaseVectorValueMatcher(org.apache.druid.query.filter.vector.BaseVectorValueMatcher) VectorValueMatcher(org.apache.druid.query.filter.vector.VectorValueMatcher) ReadableVectorMatch(org.apache.druid.query.filter.vector.ReadableVectorMatch) VectorMatch(org.apache.druid.query.filter.vector.VectorMatch) ReadableVectorMatch(org.apache.druid.query.filter.vector.ReadableVectorMatch) BaseVectorValueMatcher(org.apache.druid.query.filter.vector.BaseVectorValueMatcher)

Aggregations

BaseVectorValueMatcher (org.apache.druid.query.filter.vector.BaseVectorValueMatcher)2 ReadableVectorMatch (org.apache.druid.query.filter.vector.ReadableVectorMatch)2 VectorMatch (org.apache.druid.query.filter.vector.VectorMatch)2 VectorValueMatcher (org.apache.druid.query.filter.vector.VectorValueMatcher)1