From 3136dfa421833aa0d83fef7f5b08ebf697088b2d Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 25 Jan 2017 13:22:07 -0800 Subject: [PATCH] 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%'". --- .../main/java/io/druid/query/filter/LikeDimFilter.java | 10 +++++++--- .../main/java/io/druid/segment/filter/LikeFilter.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/processing/src/main/java/io/druid/query/filter/LikeDimFilter.java b/processing/src/main/java/io/druid/query/filter/LikeDimFilter.java index eee92f5c96e..236b52c171e 100644 --- a/processing/src/main/java/io/druid/query/filter/LikeDimFilter.java +++ b/processing/src/main/java/io/druid/query/filter/LikeDimFilter.java @@ -29,6 +29,7 @@ import com.google.common.io.BaseEncoding; import com.google.common.primitives.Chars; import io.druid.java.util.common.StringUtils; import io.druid.query.extraction.ExtractionFn; +import io.druid.segment.data.Indexed; import io.druid.segment.filter.LikeFilter; 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 - * of s are ignored. This method is useful if you've already independently verified the prefix. + * 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. 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 strings, final int i) { if (suffixMatch == SuffixMatch.MATCH_ANY) { return true; } else if (suffixMatch == SuffixMatch.MATCH_EMPTY) { + final String s = strings.get(i); return (s == null ? 0 : s.length()) == prefix.length(); } else { // suffixMatch is MATCH_PATTERN + final String s = strings.get(i); return matches(s); } } diff --git a/processing/src/main/java/io/druid/segment/filter/LikeFilter.java b/processing/src/main/java/io/druid/segment/filter/LikeFilter.java index 934b48929e1..8773da0c698 100644 --- a/processing/src/main/java/io/druid/segment/filter/LikeFilter.java +++ b/processing/src/main/java/io/druid/segment/filter/LikeFilter.java @@ -99,7 +99,7 @@ public class LikeFilter implements Filter @Override public ImmutableBitmap next() { - while (currIndex < endIndex && !likeMatcher.matchesSuffixOnly(dimValues.get(currIndex))) { + while (currIndex < endIndex && !likeMatcher.matchesSuffixOnly(dimValues, currIndex)) { currIndex++; }