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

    https://github.com/apache/drill/pull/907#discussion_r134035511
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
 ---
    @@ -57,22 +57,120 @@ private StringFunctions() {}
         @Output BitHolder out;
         @Workspace java.util.regex.Matcher matcher;
         @Workspace org.apache.drill.exec.expr.fn.impl.CharSequenceWrapper 
charSequenceWrapper;
    +    @Workspace 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlPatternInfo patternInfo;
     
         @Override
         public void setup() {
    -      matcher = 
java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike(
 //
    -          
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start,
  pattern.end,  pattern.buffer))).matcher("");
    +      patternInfo = 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike(
    +          
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start,
 pattern.end, pattern.buffer));
           charSequenceWrapper = new 
org.apache.drill.exec.expr.fn.impl.CharSequenceWrapper();
    -      matcher.reset(charSequenceWrapper);
    +
    +      // Use java regex and compile pattern only if it is not a simple 
pattern.
    +      if (patternInfo.getPatternType() == 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlPatternType.NOT_SIMPLE) {
    +        java.lang.String javaPatternString = 
patternInfo.getJavaPatternString();
    +        matcher = 
java.util.regex.Pattern.compile(javaPatternString).matcher("");
    +        matcher.reset(charSequenceWrapper);
    +      }
         }
     
         @Override
         public void eval() {
           charSequenceWrapper.setBuffer(input.start, input.end, input.buffer);
           // Reusing same charSequenceWrapper, no need to pass it in.
           // This saves one method call since reset(CharSequence) calls reset()
    -      matcher.reset();
    -      out.value = matcher.matches()? 1:0;
    +
    +      // Not a simple case. Just use Java regex.
    +      if (patternInfo.getPatternType() == 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlPatternType.NOT_SIMPLE) {
    +        matcher.reset();
    +        out.value = matcher.matches() ? 1 : 0;
    +      }
    +
    +      // This is a simple pattern that ends with a constant string i.e. 
%ABC
    +      // Compare the characters starting from end.
    +      if (patternInfo.getPatternType() == 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlPatternType.ENDS_WITH) {
    --- End diff --
    
    Chains of ifs are rather old-school. Do a switch on the enum. And, do it in 
the pattern class so it can be unit tested.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to