[ 
https://issues.apache.org/jira/browse/DRILL-5697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16133515#comment-16133515
 ] 

ASF GitHub Bot commented on DRILL-5697:
---------------------------------------

Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/907#discussion_r134034498
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/RegexpUtil.java 
---
    @@ -76,12 +113,24 @@ public static String sqlToRegexLike(
       /**
        * Translates a SQL LIKE pattern to Java regex pattern.
        */
    -  public static String sqlToRegexLike(
    +  public static sqlPatternInfo sqlToRegexLike(
           String sqlPattern,
           char escapeChar) {
         int i;
         final int len = sqlPattern.length();
         final StringBuilder javaPattern = new StringBuilder(len + len);
    +    final StringBuilder simplePattern = new StringBuilder(len);
    +
    +    // Figure out the pattern type and build simplePatternString
    +    // as we are going through the sql pattern string
    +    // to build java regex pattern string. This is better instead of using
    +    // regex later for determining if a pattern is simple or not.
    +    // Saves CPU cycles.
    +    sqlPatternType patternType = sqlPatternType.NOT_SIMPLE;
    +    boolean startsWith = false;
    +    boolean endsWith = false;
    +    boolean notSimple = false;
    --- End diff --
    
    Or, since your enum represents terminal states, create a new enum with 
internal states. CONST_ONLY, WILDCARD, COMPLEX with transitions
    ```
    initial: CONST_ONLY
    all constant caracters, CONST_ONLY: -> CONST_ONLY
    %, CONST_ONLY --> WILDCARD
    any other special char, any state --> COMPLEX
    %, WILDCARD --> COMPLEX
    ```
    Or, even better, define a simple recursive decent parser in which states 
are encoded as methods rather than as state variables.
    ```
    parseConstant() ...
    - parseWildcard()
    - parseComplex()
    
    parseWildcard() ...
    - parseComplex()
    
    parseComplex() ...
    ```
    
    Here, I'm ignoring the details of detecting abc, abc%, ab%c, %abc. These 
can also be represented as states with the resulting transitions.


> Improve performance of filter operator for pattern matching
> -----------------------------------------------------------
>
>                 Key: DRILL-5697
>                 URL: https://issues.apache.org/jira/browse/DRILL-5697
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Execution - Flow
>    Affects Versions: 1.11.0
>            Reporter: Padma Penumarthy
>            Assignee: Padma Penumarthy
>
> Queries using filter with sql like operator use Java regex library for 
> pattern matching. However, for cases like %abc (ends with abc), abc% (starts 
> with abc), %abc% (contains abc), it is observed that implementing these cases 
> with simple code instead of using regex library provides good performance 
> boost (4-6x). Idea is to use special case code for simple, common cases and 
> fall back to Java regex library for complicated ones. That will provide good 
> performance benefit for most common cases.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to