drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sachouche <...@git.apache.org>
Subject [GitHub] drill pull request #1072: DRILL-5879: Improved SQL Pattern Contains Performa...
Date Wed, 20 Dec 2017 16:40:27 GMT
Github user sachouche commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1072#discussion_r158074289
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
---
    @@ -19,44 +19,283 @@
     
     import io.netty.buffer.DrillBuf;
     
    -public class SqlPatternContainsMatcher extends AbstractSqlPatternMatcher {
    +/** SQL Pattern Contains implementation */
    +public final class SqlPatternContainsMatcher extends AbstractSqlPatternMatcher {
    +  private final MatcherFcn matcherFcn;
     
       public SqlPatternContainsMatcher(String patternString) {
         super(patternString);
    +
    +    // Pattern matching is 1) a CPU intensive operation and 2) pattern and input dependent.
The conclusion is
    +    // that there is no single implementation that can do it all well. So, we use multiple
implementations
    +    // chosen based on the pattern length.
    +    if (patternLength == 1) {
    +      matcherFcn = new Matcher1();
    +    } else if (patternLength == 2) {
    +      matcherFcn = new Matcher2();
    +    } else if (patternLength == 3) {
    +      matcherFcn = new Matcher3();
    +    } else if (patternLength < 10) {
    +      matcherFcn = new MatcherN();
    +    } else {
    +      matcherFcn = new BoyerMooreMatcher();
    +    }
       }
     
       @Override
       public int match(int start, int end, DrillBuf drillBuf) {
    +    return matcherFcn.match(start, end, drillBuf);
    +  }
    +
    +  //--------------------------------------------------------------------------
    +  // Inner Data Structure
    +  // --------------------------------------------------------------------------
    +
    +  /** Abstract matcher class to allow us pick the most efficient implementation */
    +  private abstract class MatcherFcn {
    +    protected final byte[] patternArray;
    +
    +    protected MatcherFcn() {
    +      assert patternByteBuffer.hasArray();
    --- End diff --
    
    HeapByteBuffer will always create an internal buffer. Empty string will have a byte array
with zero bytes.


---

Mime
View raw message