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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to