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

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

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

    https://github.com/apache/drill/pull/1015#discussion_r149555002
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
 ---
    @@ -17,33 +17,30 @@
      */
     package org.apache.drill.exec.expr.fn.impl;
     
    -public class SqlPatternEndsWithMatcher implements SqlPatternMatcher {
    -  final String patternString;
    -  CharSequence charSequenceWrapper;
    -  final int patternLength;
    -
    -  public SqlPatternEndsWithMatcher(String patternString, CharSequence 
charSequenceWrapper) {
    -    this.charSequenceWrapper = charSequenceWrapper;
    -    this.patternString = patternString;
    -    this.patternLength = patternString.length();
    +import io.netty.buffer.DrillBuf;
    +
    +public class SqlPatternEndsWithMatcher extends AbstractSqlPatternMatcher {
    +
    +  public SqlPatternEndsWithMatcher(String patternString) {
    +    super(patternString);
       }
     
       @Override
    -  public int match() {
    -    int txtIndex = charSequenceWrapper.length();
    -    int patternIndex = patternLength;
    -    boolean matchFound = true; // if pattern is empty string, we always 
match.
    +  public int match(int start, int end, DrillBuf drillBuf) {
    +
    +    if ( (end - start) < patternLength) { // No match if input string 
length is less than pattern length.
    +      return 0;
    +    }
     
         // simplePattern string has meta characters i.e % and _ and escape 
characters removed.
         // so, we can just directly compare.
    -    while (patternIndex > 0 && txtIndex > 0) {
    -      if (charSequenceWrapper.charAt(--txtIndex) != 
patternString.charAt(--patternIndex)) {
    -        matchFound = false;
    -        break;
    +    for (int index = 1; index <= patternLength; index++) {
    --- End diff --
    
    ```
    int txtStart = end - patternLength;
    if (txtStart < start) { return 0; }
    for (int index = 0; index < patternLength; index++) {
       ... patternByteBuffer.get(index) ... drillBuf.getByte(txtStart + index) 
...
    ```



> Simple pattern matchers can work with DrillBuf directly
> -------------------------------------------------------
>
>                 Key: DRILL-5899
>                 URL: https://issues.apache.org/jira/browse/DRILL-5899
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Execution - Flow
>            Reporter: Padma Penumarthy
>            Assignee: Padma Penumarthy
>            Priority: Critical
>
> For the 4 simple patterns we have i.e. startsWith, endsWith, contains and 
> constant,, we do not need the overhead of charSequenceWrapper. We can work 
> with DrillBuf directly. This will save us from doing isAscii check and UTF8 
> decoding for each row.
> UTF-8 encoding ensures that no UTF-8 character is a prefix of any other valid 
> character. So, instead of decoding varChar from each row we are processing, 
> encode the patternString once during setup and do raw byte comparison. 
> Instead of bounds checking and reading one byte at a time, we get the whole 
> buffer in one shot and use that for comparison.
> This improved overall performance for filter operator by around 20%. 



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

Reply via email to