mirror of https://github.com/apache/druid.git
LikeFilter: Read value lazily when doing a prefix-based match. (#3880)
This speeds up cases where we don't actually need to read the value, such as "LIKE 'foo%'".
This commit is contained in:
parent
b3dae0efc3
commit
3136dfa421
|
@ -29,6 +29,7 @@ import com.google.common.io.BaseEncoding;
|
||||||
import com.google.common.primitives.Chars;
|
import com.google.common.primitives.Chars;
|
||||||
import io.druid.java.util.common.StringUtils;
|
import io.druid.java.util.common.StringUtils;
|
||||||
import io.druid.query.extraction.ExtractionFn;
|
import io.druid.query.extraction.ExtractionFn;
|
||||||
|
import io.druid.segment.data.Indexed;
|
||||||
import io.druid.segment.filter.LikeFilter;
|
import io.druid.segment.filter.LikeFilter;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -154,17 +155,20 @@ public class LikeDimFilter implements DimFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the suffix of "s" matches the suffix of this matcher. The first prefix.length characters
|
* Checks if the suffix of strings.get(i) matches the suffix of this matcher. The first prefix.length characters
|
||||||
* of s are ignored. This method is useful if you've already independently verified the prefix.
|
* of s are ignored. This method is useful if you've already independently verified the prefix. This method
|
||||||
|
* evalutes strings.get(i) lazily to save time when it isn't necessary to actually look at the string.
|
||||||
*/
|
*/
|
||||||
public boolean matchesSuffixOnly(@Nullable final String s)
|
public boolean matchesSuffixOnly(final Indexed<String> strings, final int i)
|
||||||
{
|
{
|
||||||
if (suffixMatch == SuffixMatch.MATCH_ANY) {
|
if (suffixMatch == SuffixMatch.MATCH_ANY) {
|
||||||
return true;
|
return true;
|
||||||
} else if (suffixMatch == SuffixMatch.MATCH_EMPTY) {
|
} else if (suffixMatch == SuffixMatch.MATCH_EMPTY) {
|
||||||
|
final String s = strings.get(i);
|
||||||
return (s == null ? 0 : s.length()) == prefix.length();
|
return (s == null ? 0 : s.length()) == prefix.length();
|
||||||
} else {
|
} else {
|
||||||
// suffixMatch is MATCH_PATTERN
|
// suffixMatch is MATCH_PATTERN
|
||||||
|
final String s = strings.get(i);
|
||||||
return matches(s);
|
return matches(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class LikeFilter implements Filter
|
||||||
@Override
|
@Override
|
||||||
public ImmutableBitmap next()
|
public ImmutableBitmap next()
|
||||||
{
|
{
|
||||||
while (currIndex < endIndex && !likeMatcher.matchesSuffixOnly(dimValues.get(currIndex))) {
|
while (currIndex < endIndex && !likeMatcher.matchesSuffixOnly(dimValues, currIndex)) {
|
||||||
currIndex++;
|
currIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue