DRILL-5899: Simple pattern matchers can work with DrillBuf directly

closes #1015


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/df95709a
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/df95709a
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/df95709a

Branch: refs/heads/master
Commit: df95709a2dac47e46be59c47dc776efbbe615726
Parents: dfd43d0
Author: Padma Penumarthy <ppenuma...@yahoo.com>
Authored: Wed Oct 25 13:37:25 2017 -0700
Committer: Arina Ielchiieva <arina.yelchiy...@gmail.com>
Committed: Mon Nov 13 11:06:34 2017 +0200

----------------------------------------------------------------------
 .../expr/fn/impl/AbstractSqlPatternMatcher.java |  66 ++
 .../expr/fn/impl/SqlPatternComplexMatcher.java  |  18 +-
 .../expr/fn/impl/SqlPatternConstantMatcher.java |  29 +-
 .../expr/fn/impl/SqlPatternContainsMatcher.java |  59 +-
 .../expr/fn/impl/SqlPatternEndsWithMatcher.java |  35 +-
 .../exec/expr/fn/impl/SqlPatternFactory.java    |  15 +-
 .../exec/expr/fn/impl/SqlPatternMatcher.java    |   4 +-
 .../fn/impl/SqlPatternStartsWithMatcher.java    |  32 +-
 .../exec/expr/fn/impl/StringFunctions.java      |  16 +-
 .../exec/expr/fn/impl/TestSqlPatterns.java      | 729 +++++++------------
 .../exec/expr/fn/impl/TestStringFunctions.java  | 149 ++++
 11 files changed, 574 insertions(+), 578 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AbstractSqlPatternMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AbstractSqlPatternMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AbstractSqlPatternMatcher.java
new file mode 100644
index 0000000..245d585
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/AbstractSqlPatternMatcher.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.expr.fn.impl;
+
+import com.google.common.base.Charsets;
+import org.apache.drill.common.exceptions.UserException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetEncoder;
+import static org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.logger;
+
+/**
+ * To get good performance for most commonly used pattern matches
+ * CONSTANT('ABC') {@link SqlPatternConstantMatcher}
+ * STARTSWITH('%ABC') {@link SqlPatternStartsWithMatcher}
+ * ENDSWITH('ABC%') {@link SqlPatternEndsWithMatcher }
+ * CONTAINS('%ABC%') {@link SqlPatternContainsMatcher}
+ * we have simple pattern matchers.
+ * Idea is to have our own implementation for simple pattern matchers so we can
+ * avoid heavy weight regex processing, skip UTF-8 decoding and char 
conversion.
+ * Instead, we encode the pattern string and do byte comparison against native 
memory.
+ * Overall, this approach
+ * gives us orders of magnitude performance improvement for simple pattern 
matches.
+ * Anything that is not simple is considered
+ * complex pattern and we use Java regex for complex pattern matches.
+ */
+
+public abstract class AbstractSqlPatternMatcher implements SqlPatternMatcher {
+  protected final String patternString;
+  protected final int patternLength;
+  protected final ByteBuffer patternByteBuffer;
+
+  public AbstractSqlPatternMatcher(String patternString) {
+    this.patternString = patternString;
+
+    final CharsetEncoder charsetEncoder = Charsets.UTF_8.newEncoder();
+    final CharBuffer patternCharBuffer = CharBuffer.wrap(patternString);
+
+    try {
+      patternByteBuffer = charsetEncoder.encode(patternCharBuffer);
+    } catch (CharacterCodingException e) {
+      throw UserException.validationError(e)
+          .message("Failure to encode pattern %s using UTF-8", patternString)
+          .addContext("Message: ", e.getMessage())
+          .build(logger);
+    }
+    patternLength = patternByteBuffer.limit();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternComplexMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternComplexMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternComplexMatcher.java
index 91cc85d..abe46ab 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternComplexMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternComplexMatcher.java
@@ -17,18 +17,22 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
+import io.netty.buffer.DrillBuf;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
 public class SqlPatternComplexMatcher implements SqlPatternMatcher {
-  java.util.regex.Matcher matcher;
-  CharSequence charSequenceWrapper;
+  private final Matcher matcher;
+  private final CharSequenceWrapper charSequenceWrapper;
 
-  public SqlPatternComplexMatcher(String patternString, CharSequence 
charSequenceWrapper) {
-    this.charSequenceWrapper = charSequenceWrapper;
-    matcher = java.util.regex.Pattern.compile(patternString).matcher("");
-    matcher.reset(charSequenceWrapper);
+  public SqlPatternComplexMatcher(String patternString) {
+    charSequenceWrapper = new CharSequenceWrapper();
+    matcher = Pattern.compile(patternString).matcher(charSequenceWrapper);
   }
 
   @Override
-  public int match() {
+  public int match(int start, int end, DrillBuf drillBuf) {
+    charSequenceWrapper.setBuffer(start, end, drillBuf);
     matcher.reset();
     return matcher.matches() ? 1 : 0;
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternConstantMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternConstantMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternConstantMatcher.java
index 3294575..d0e8aca 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternConstantMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternConstantMatcher.java
@@ -17,36 +17,31 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
-public class SqlPatternConstantMatcher implements SqlPatternMatcher {
-  final String patternString;
-  CharSequence charSequenceWrapper;
-  final int patternLength;
-
-  public SqlPatternConstantMatcher(String patternString, CharSequence 
charSequenceWrapper) {
-    this.patternString = patternString;
-    this.charSequenceWrapper = charSequenceWrapper;
-    patternLength = patternString.length();
+import io.netty.buffer.DrillBuf;
+
+public class SqlPatternConstantMatcher extends AbstractSqlPatternMatcher {
+
+  public SqlPatternConstantMatcher(String patternString) {
+    super(patternString);
   }
 
   @Override
-  public int match() {
-    int index = 0;
+  public int match(int start, int end, DrillBuf drillBuf) {
 
     // If the lengths are not same, there cannot be a match
-    if (patternLength != charSequenceWrapper.length()) {
+    if (patternLength != (end - start)) {
       return 0;
     }
 
     // simplePattern string has meta characters i.e % and _ and escape 
characters removed.
     // so, we can just directly compare.
-    while (index < patternLength) {
-      if (patternString.charAt(index) != charSequenceWrapper.charAt(index)) {
-        break;
+    for (int index = 0; index < patternLength; index++) {
+      if (patternByteBuffer.get(index) != drillBuf.getByte(start + index)) {
+        return 0;
       }
-      index++;
     }
 
-    return index == patternLength ? 1 : 0;
+    return 1;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
index 2602dc8..04f5dac 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternContainsMatcher.java
@@ -17,37 +17,46 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
-public class SqlPatternContainsMatcher implements SqlPatternMatcher {
-  final String patternString;
-  CharSequence charSequenceWrapper;
-  final int patternLength;
-
-  public SqlPatternContainsMatcher(String patternString, CharSequence 
charSequenceWrapper) {
-    this.patternString = patternString;
-    this.charSequenceWrapper = charSequenceWrapper;
-    patternLength = patternString.length();
+import io.netty.buffer.DrillBuf;
+
+public class SqlPatternContainsMatcher extends AbstractSqlPatternMatcher {
+
+  public SqlPatternContainsMatcher(String patternString) {
+    super(patternString);
   }
 
   @Override
-  public int match() {
-    final int txtLength = charSequenceWrapper.length();
-    int patternIndex = 0;
-    int txtIndex = 0;
-
-    // simplePattern string has meta characters i.e % and _ and escape 
characters removed.
-    // so, we can just directly compare.
-    while (patternIndex < patternLength && txtIndex < txtLength) {
-      if (patternString.charAt(patternIndex) != 
charSequenceWrapper.charAt(txtIndex)) {
-        // Go back if there is no match
-        txtIndex = txtIndex - patternIndex;
-        patternIndex = 0;
-      } else {
-        patternIndex++;
+  public int match(int start, int end, DrillBuf drillBuf) {
+
+    if (patternLength == 0) { // Everything should match for null pattern 
string
+      return 1;
+    }
+
+    final int txtLength = end - start;
+
+    // no match if input string length is less than pattern length
+    if (txtLength < patternLength) {
+      return 0;
+    }
+
+
+    final int outerEnd = txtLength - patternLength;
+
+    outer:
+    for (int txtIndex = 0; txtIndex <= outerEnd; txtIndex++) {
+
+      // simplePattern string has meta characters i.e % and _ and escape 
characters removed.
+      // so, we can just directly compare.
+      for (int patternIndex = 0; patternIndex < patternLength; patternIndex++) 
{
+        if (patternByteBuffer.get(patternIndex) != drillBuf.getByte(start + 
txtIndex + patternIndex)) {
+          continue outer;
+        }
       }
-      txtIndex++;
+
+      return 1;
     }
 
-    return patternIndex == patternLength ? 1 : 0;
+    return  0;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
index 15fed22..7c83c91 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternEndsWithMatcher.java
@@ -17,33 +17,32 @@
  */
 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) {
+
+    // No match if input string length is less than pattern length.
+    final int txtStart = end - patternLength;
+    if (txtStart < start) {
+      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 = 0; index < patternLength; index++) {
+      if (patternByteBuffer.get(index) != drillBuf.getByte(txtStart + index)) {
+        return 0;
       }
     }
 
-    return (patternIndex == 0 && matchFound == true) ? 1 : 0;
+    return 1;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternFactory.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternFactory.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternFactory.java
index 9c85a01..871f660 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternFactory.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternFactory.java
@@ -18,21 +18,22 @@
 
 package org.apache.drill.exec.expr.fn.impl;
 
+import org.apache.drill.exec.expr.fn.impl.RegexpUtil.SqlPatternInfo;
+
 public class SqlPatternFactory {
-  public static SqlPatternMatcher 
getSqlPatternMatcher(org.apache.drill.exec.expr.fn.impl.RegexpUtil.SqlPatternInfo
 patternInfo,
-                                                       CharSequence 
charSequenceWrapper)
+  public static SqlPatternMatcher getSqlPatternMatcher(SqlPatternInfo 
patternInfo)
   {
     switch (patternInfo.getPatternType()) {
       case COMPLEX:
-        return new 
SqlPatternComplexMatcher(patternInfo.getJavaPatternString(), 
charSequenceWrapper);
+        return new 
SqlPatternComplexMatcher(patternInfo.getJavaPatternString());
       case STARTS_WITH:
-        return new 
SqlPatternStartsWithMatcher(patternInfo.getSimplePatternString(), 
charSequenceWrapper);
+        return new 
SqlPatternStartsWithMatcher(patternInfo.getSimplePatternString());
       case CONSTANT:
-        return new 
SqlPatternConstantMatcher(patternInfo.getSimplePatternString(), 
charSequenceWrapper);
+        return new 
SqlPatternConstantMatcher(patternInfo.getSimplePatternString());
       case ENDS_WITH:
-        return new 
SqlPatternEndsWithMatcher(patternInfo.getSimplePatternString(), 
charSequenceWrapper);
+        return new 
SqlPatternEndsWithMatcher(patternInfo.getSimplePatternString());
       case CONTAINS:
-        return new 
SqlPatternContainsMatcher(patternInfo.getSimplePatternString(), 
charSequenceWrapper);
+        return new 
SqlPatternContainsMatcher(patternInfo.getSimplePatternString());
       default:
         break;
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternMatcher.java
index 9c0c6e2..98c4877 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternMatcher.java
@@ -17,6 +17,8 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
+import io.netty.buffer.DrillBuf;
+
 public interface SqlPatternMatcher {
-  public int match();
+  int match(int start, int end, DrillBuf drillBuf);
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternStartsWithMatcher.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternStartsWithMatcher.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternStartsWithMatcher.java
index 9faae8a..d17ca21 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternStartsWithMatcher.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/SqlPatternStartsWithMatcher.java
@@ -17,32 +17,30 @@
  */
 package org.apache.drill.exec.expr.fn.impl;
 
-public class SqlPatternStartsWithMatcher implements SqlPatternMatcher {
-  final String patternString;
-  CharSequence charSequenceWrapper;
-  final int patternLength;
-
-  public SqlPatternStartsWithMatcher(String patternString, CharSequence 
charSequenceWrapper) {
-    this.charSequenceWrapper = charSequenceWrapper;
-    this.patternString = patternString;
-    patternLength = patternString.length();
+import io.netty.buffer.DrillBuf;
+
+public class SqlPatternStartsWithMatcher extends AbstractSqlPatternMatcher {
+
+  public SqlPatternStartsWithMatcher(String patternString) {
+    super(patternString);
   }
 
   @Override
-  public int match() {
-    int index = 0;
-    final int txtLength = charSequenceWrapper.length();
+  public int match(int start, int end, DrillBuf drillBuf) {
+
+    if (patternLength > (end - start)) {
+      return 0;
+    }
 
     // simplePattern string has meta characters i.e % and _ and escape 
characters removed.
     // so, we can just directly compare.
-    while (index < patternLength && index < txtLength) {
-      if (patternString.charAt(index) != charSequenceWrapper.charAt(index)) {
-        break;
+    for (int index = 0; index < patternLength; index++) {
+      if (patternByteBuffer.get(index) != drillBuf.getByte(start + index)) {
+        return 0;
       }
-      index++;
     }
 
-    return (index == patternLength ? 1 : 0);
+    return 1;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 2a99ffa..ad3f379 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -55,7 +55,6 @@ public class StringFunctions{
     @Param VarCharHolder input;
     @Param(constant=true) VarCharHolder pattern;
     @Output BitHolder out;
-    @Workspace org.apache.drill.exec.expr.fn.impl.CharSequenceWrapper 
charSequenceWrapper;
     @Workspace org.apache.drill.exec.expr.fn.impl.RegexpUtil.SqlPatternInfo 
sqlPatternInfo;
     @Workspace org.apache.drill.exec.expr.fn.impl.SqlPatternMatcher 
sqlPatternMatcher;
 
@@ -63,15 +62,12 @@ public class StringFunctions{
     public void setup() {
       sqlPatternInfo = 
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();
-      sqlPatternMatcher = 
org.apache.drill.exec.expr.fn.impl.SqlPatternFactory.getSqlPatternMatcher(sqlPatternInfo,
 charSequenceWrapper);
+      sqlPatternMatcher = 
org.apache.drill.exec.expr.fn.impl.SqlPatternFactory.getSqlPatternMatcher(sqlPatternInfo);
     }
 
     @Override
     public void eval() {
-      // Reusing same charSequenceWrapper, no need to pass it in.
-      charSequenceWrapper.setBuffer(input.start, input.end, input.buffer);
-      out.value = sqlPatternMatcher.match();
+      out.value = sqlPatternMatcher.match(input.start, input.end, 
input.buffer);
     }
   }
 
@@ -82,7 +78,6 @@ public class StringFunctions{
     @Param(constant=true) VarCharHolder pattern;
     @Param(constant=true) VarCharHolder escape;
     @Output BitHolder out;
-    @Workspace org.apache.drill.exec.expr.fn.impl.CharSequenceWrapper 
charSequenceWrapper;
     @Workspace org.apache.drill.exec.expr.fn.impl.RegexpUtil.SqlPatternInfo 
sqlPatternInfo;
     @Workspace org.apache.drill.exec.expr.fn.impl.SqlPatternMatcher 
sqlPatternMatcher;
 
@@ -91,15 +86,12 @@ public class StringFunctions{
       sqlPatternInfo = 
org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike(
           
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start,
  pattern.end,  pattern.buffer),
           
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(escape.start,
  escape.end,  escape.buffer));
-      charSequenceWrapper = new 
org.apache.drill.exec.expr.fn.impl.CharSequenceWrapper();
-      sqlPatternMatcher = 
org.apache.drill.exec.expr.fn.impl.SqlPatternFactory.getSqlPatternMatcher(sqlPatternInfo,
 charSequenceWrapper);
+      sqlPatternMatcher = 
org.apache.drill.exec.expr.fn.impl.SqlPatternFactory.getSqlPatternMatcher(sqlPatternInfo);
     }
 
     @Override
     public void eval() {
-      // Reusing same charSequenceWrapper, no need to pass it in.
-      charSequenceWrapper.setBuffer(input.start, input.end, input.buffer);
-      out.value = sqlPatternMatcher.match();
+      out.value = sqlPatternMatcher.match(input.start, input.end, 
input.buffer);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSqlPatterns.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSqlPatterns.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSqlPatterns.java
index d8c1410..2eecb54 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSqlPatterns.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestSqlPatterns.java
@@ -17,11 +17,100 @@
  */
 
 package org.apache.drill.exec.expr.fn.impl;
+import io.netty.buffer.DrillBuf;
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 public class TestSqlPatterns {
+  BufferAllocator allocator;
+  DrillBuf drillBuf;
+  CharsetEncoder charsetEncoder;
+  CharBuffer charBuffer;
+  ByteBuffer byteBuffer;
+
+  String wideString = 
"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
+      "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
+      "JhhjcxwoafBRyyEvQ6Pfhg8IqJ0afBpAZHhR2y4I11zbaJZqs3WG3H3aQHT" +
+      
"wcPHdBHnk65GdL3Njuoo0K4mcmN6lk7pWptHwTjkw59zTw834PZ8TWm5XiUnsi9JKy41MPqHcbO0nN"
 +
+      "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
+      
"yMNf6nncwABOOoC5EnqYBNoq29Mf54H5k2Xi8y1fh8ldtKcW9T4WsaXun9fKofegfhwY8wgfoG" +
+      
"eW2YNW3fdalIsggRzMEAXVDxj7oieReUGiT53uV2kcmcQRQLdUDUcOC1JEiSRpgZl38c1DDVRlz8Rbhi"
 +
+      "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
+      "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
+      "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
+      "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
+      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
+      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
+      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
+      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
+      
"TXIR4K0njrS4X4KrBQFxvuZey8tnUnm8oiJWdUFzdM4N0KioJsG8UzxRODxKh4e3GqxmZxsSwwL0nNnV1syiCCC"
 +
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      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
+      
"Whlarr6bRQeIwCXckALEVdGZBTPiqjYPBfk5H5wYXqkieh04tjSmnWytNebBNmGjTNgrqNVO7ftCbhh7wICOn"
 +
+      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
+      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
+      
"R58SXBXsalwNM9TmTeBMrc8Hghx9hDpai8agUclHTCoyK2hkEpKLlEJiXUKOE8JPugYE8yFVYF49UAjJUbsj6we3Ocii"
 +
+      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
+      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
+      
"2JkPOST2Vr35mNKoulUMqFeo0s1y5hcVY39a3mBMytwZn7HgPhEJScwZdWJd6E5tZ13evEmcn1A5YPBYbm91CdJFXhj"
 +
+      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
+      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
+      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
+      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"
 +
+      "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ";
+
+  @Before
+  public void setup() {
+    allocator = RootAllocatorFactory.newRoot(16384);
+    drillBuf = allocator.buffer(8192);
+    charsetEncoder = Charset.forName("UTF-8").newEncoder();
+  }
 
   @Test
   public void testSqlRegexLike() {
@@ -30,7 +119,7 @@ public class TestSqlPatterns {
     // Simple pattern should have meta (% and _) and escape characters removed.
 
     // A%B is complex
-    RegexpUtil.SqlPatternInfo  patternInfo = RegexpUtil.sqlToRegexLike("A%B");
+    RegexpUtil.SqlPatternInfo patternInfo = RegexpUtil.sqlToRegexLike("A%B");
     assertEquals("A.*B", patternInfo.getJavaPatternString());
     assertEquals(RegexpUtil.SqlPatternType.COMPLEX, 
patternInfo.getPatternType());
 
@@ -108,567 +197,259 @@ public class TestSqlPatterns {
 
   }
 
+  private void setDrillBuf(String input) {
+    drillBuf.clear();
+    charBuffer = CharBuffer.wrap(input);
+    try {
+      byteBuffer = charsetEncoder.encode(charBuffer);
+    } catch (CharacterCodingException e) {
+      throw new DrillRuntimeException("Error while encoding the pattern string 
", e);
+    }
+    drillBuf.setBytes(0, byteBuffer, byteBuffer.position(), 
byteBuffer.remaining());
+  }
+
   @Test
   public void testSqlPatternStartsWith() {
-    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH,"", "ABC");
+    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH, "", "ABC");
+    SqlPatternMatcher sqlPatternStartsWith = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    StringBuffer sb = new StringBuffer("ABCD");
-    SqlPatternMatcher sqlPatternStartsWith = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo, sb);
-    assertEquals(sqlPatternStartsWith.match(), 1);  // ABCD should match 
StartsWith ABC
+    setDrillBuf("ABCD");
+    assertEquals(1, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf));  // ABCD should match StartsWith ABC
 
-    sb.setLength(0);
-    sb.append("BCD");
-    assertEquals(sqlPatternStartsWith.match(), 0);  // BCD should not match 
StartsWith ABC
+    setDrillBuf("BCD");
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf));  // BCD should not match StartsWith ABC
 
-    sb.setLength(0);
-    sb.append("XYZABC");
-    assertEquals(sqlPatternStartsWith.match(), 0);  // XYZABC should not match 
StartsWith ABC
+    setDrillBuf("XYZABC");
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf));  // XYZABC should not match StartsWith ABC
 
     // null text
-    sb.setLength(0);
-    assertEquals(sqlPatternStartsWith.match(), 0); // null String should not 
match StartsWith ABC
+    setDrillBuf("");
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // null String should not match StartsWith ABC
 
     // pattern length > txt length
-    sb.append("AB");
-    assertEquals(sqlPatternStartsWith.match(), 0); // AB should not match 
StartsWith ABC
+    setDrillBuf("AB");
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // AB should not match StartsWith ABC
 
     // startsWith null pattern should match anything
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH,"", "");
-    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternStartsWith.match(), 1); // AB should match 
StartsWith null pattern
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH, "", "");
+    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+
+    setDrillBuf("AB");
+    assertEquals(1, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // AB should match StartsWith null pattern
 
     // null pattern and null text
-    sb.setLength(0);
-    assertEquals(sqlPatternStartsWith.match(), 1); // null text should match 
null pattern
+    setDrillBuf("");
+    assertEquals(1, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // null text should match null pattern
 
     // wide character string.
-    
sb.append("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
-        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
-        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
-        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
-        " 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
-        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
-        "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
-        "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
-        "PDHQEieFMddi4gKPOv4es1YX2aBo4RfYiTlUyXd6gGujVPgU2j" +
-        
"AAhcz6JqVC08O73gM9zOAM2l4PwN2TN3lBufkQUGyOzHtoTDjSdQ2DPXIks9A6ehIpn92n1UtdrJeMz"
 +
-        "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
-        "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
-        "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
-        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
-        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
-        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
-        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
-        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
-        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
-        "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" 
+
-        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
-        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
-        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
-        
"1SHRVlXm7Bx3bjJ79O3bGqjzxT1EZV39isegIyKx2H0zEUpnlXzzbusS0tusECmG3C3eGDOTs" +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"CTtiZv12uCj0WILSesMc5ct2tQcIvwnOHAuE6fw7lD8EgQ0emU4zxUIDowhTvJ46k27rXTctIX7HlBEZXInV9r49"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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"
 +
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH,"",
-        "b00dUrA0oa2i4ZEHg6zvPXPXlVQYB2BXe8T5gIEtvUDzcN6yUkIqyS07gaAy8k4");
-    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternStartsWith.match(), 1); // should match
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH,"",
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternStartsWith.match(), 0); // should not match
+    setDrillBuf(wideString);
 
-    // non ascii
-    sb.setLength(0);
-    sb.append("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH, "", 
"b00dUrA0oa2i4ZEHg6zvPXPXlVQYB2BXe8T5gIEtvUDzcN6yUkIqyS07gaAy8k4");
+    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should match
 
-    assertEquals(sqlPatternStartsWith.match(), 0); // should not match
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH, "", 
"AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
+    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should not match
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH,"", 
"¤EÀsÆW");
-    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternStartsWith.match(), 1); // should match
+    // non ascii
+    setDrillBuf("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    assertEquals(0, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should not match
 
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.STARTS_WITH, "", 
"¤EÀsÆW");
+    sqlPatternStartsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    setDrillBuf("¤EÀsÆW");
+    assertEquals(1, sqlPatternStartsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should match
   }
 
   @Test
   public void testSqlPatternEndsWith() {
     RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", "BCD");
-    StringBuffer sb = new StringBuffer("ABCD");
-    SqlPatternMatcher sqlPatternEndsWith = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo, sb);
+    SqlPatternMatcher sqlPatternEndsWith = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    assertEquals(sqlPatternEndsWith.match(), 1);  // ABCD should match 
EndsWith BCD
+    setDrillBuf("ABCD");
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf));  // ABCD should match EndsWith BCD
 
-    sb.setLength(0);
-    sb.append("ABC");
-    assertEquals(sqlPatternEndsWith.match(), 0);  // ABC should not match 
EndsWith BCD
+    setDrillBuf("ABC");
+    assertEquals(0, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf));  // ABC should not match EndsWith BCD
 
-    sb.setLength(0);
-    assertEquals(sqlPatternEndsWith.match(), 0);  // null string should not 
match EndsWith BCD
+    setDrillBuf("");
+    assertEquals(0, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf));  // null string should not match EndsWith BCD
 
-    sb.append("A");
-    assertEquals(sqlPatternEndsWith.match(), 0); // ABCD should not match 
EndsWith A
+    setDrillBuf("A");
+    assertEquals(0, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // ABCD should not match EndsWith A
 
-    sb.setLength(0);
-    sb.append("XYZBCD");
-    assertEquals(sqlPatternEndsWith.match(), 1);  // XYZBCD should match 
EndsWith BCD
+    setDrillBuf("XYZBCD");
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf));  // XYZBCD should match EndsWith BCD
 
     // EndsWith null pattern should match anything
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH,"", "");
-    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternEndsWith.match(), 1); // AB should match StartsWith 
null pattern
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", "");
+    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // AB should match StartsWith null pattern
 
     // null pattern and null text
-    sb.setLength(0);
-    assertEquals(sqlPatternEndsWith.match(), 1); // null text should match 
null pattern
+    setDrillBuf("");
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // null text should match null pattern
 
     // wide character string.
-    
sb.append("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
-        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
-        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
-        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
-        " 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
-        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
-        "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
-        "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
-        "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
-        "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
-        "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
-        "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
-        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
-        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
-        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
-        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
-        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
-        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
-        "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" 
+
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"i6Sy6nXOcUIOZWJ9BVJf4A27Pa4Pi7ZFznFnIdiQOrxCbb2ZCVkCftWsmcEMnXWXUkGOuA5JXo9YvGyPGq2wgO1wj"
 +
-        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
-        
"ULPRd358aPnsx2DOmN1UojjBI1hacijCtFCE8zGCa9M0L7aZbRUHe8lmlaqhx0Su6nPnPgfbJr6idfxTJHqCT4t8"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"lpSMt6BoFvjHYW1IpEyTlVlvNl5NzPPAn2119ttZTfXpifXfQtBGzlCNYTD6m1FvpmOydzqEq8YadgybW76HDtnBdU"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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"
 +
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH,"",
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternEndsWith.match(), 1); // should match
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH,"",
-        "atXzj4x3CgF6j1gn10aUJknF7KQLJ84D");
-    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternEndsWith.match(), 0); // should not match
+    setDrillBuf(wideString);
 
-    // non ascii
-    sb.setLength(0);
-    sb.append("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", 
"AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
+    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should match
+
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", "");
+    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    assertEquals(sqlPatternEndsWith.match(), 0); // should not match
+    setDrillBuf("");
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // null text should match null pattern
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH,"", "TÆU2~~");
-    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternEndsWith.match(), 1); // should match
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", 
"atXzj4x3CgF6j1gn10aUJknF7KQLJ84D");
+    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(0, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should not match
 
+    // non ascii
+    setDrillBuf("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    assertEquals(0, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should not match
+
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.ENDS_WITH, "", "TÆU2~~");
+    sqlPatternEndsWith = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternEndsWith.match(0, byteBuffer.limit(), 
drillBuf)); // should match
   }
 
   @Test
   public void testSqlPatternContains() {
-    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,".*ABC.*", "ABCD");
+    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, ".*ABC.*", 
"ABCD");
+    SqlPatternMatcher sqlPatternContains = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    StringBuffer sb = new StringBuffer("ABCD");
-    SqlPatternMatcher sqlPatternContains = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo, sb);
+    setDrillBuf("ABCD");
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf));  // ABCD should contain ABCD
 
-    assertEquals(1, sqlPatternContains.match());  // ABCD should contain ABCD
+    setDrillBuf("BC");
+    assertEquals(0, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf));  // BC cannot contain ABCD
 
-    sb.setLength(0);
-    sb.append("BC");
-    assertEquals(0, sqlPatternContains.match());  // ABCD should contain BC
+    setDrillBuf("");
+    assertEquals(0, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf));  // null string should not match contains ABCD
 
-    sb.setLength(0);
-    assertEquals(0, sqlPatternContains.match());  // null string should not 
match contains ABCD
+    setDrillBuf("DE");
+    assertEquals(0, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf));  // ABCD should not contain DE
 
-    sb.append("DE");
-    assertEquals(0, sqlPatternContains.match());  // ABCD should not contain DE
-
-    sb.setLength(0);
-    sb.append("xyzABCDqrs");
-    assertEquals(1, sqlPatternContains.match());  // xyzABCDqrs should contain 
ABCD
+    setDrillBuf("xyzABCDqrs");
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf));   // xyzABCDqrs should contain ABCD
 
     // contains null pattern should match anything
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,"", "");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternContains.match(), 1); //  should match
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, "", "");
+    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+
+    setDrillBuf("xyzABCDqrs");
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf)); //  should match
 
     // null pattern and null text
-    sb.setLength(0);
-    assertEquals(sqlPatternContains.match(), 1); // null text should match 
null pattern
+    setDrillBuf("");
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf)); // null text should match null pattern
 
     // wide character string.
-    
sb.append("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
-        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
-        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
-        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
-        " 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
-        
"UE8a5I3nYXdRppnm3MbRsLu4IxXIblh8kmAIG6n2yHwGhpWYkRI7cwl4dOB3bsxxtdaaTlZMMx6T" +
-        "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
-        "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
-        "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
-        "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
-        "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
-        "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
-        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
-        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
-        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
-        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
-        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
-        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
-        "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" 
+
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"cWXqwnsbEEejtlXH3Zr5BtxTzd3Bo08s8HxjIXF6Z0CPXcvQzDoemL8M2A1AIrnBkT7vIHgvMuH475M"
 +
-        
"TXIR4K0njrS4X4KrBQFxvuZey8tnUnm8oiJWdUFzdM4N0KioJsG8UzxRODxKh4e3GqxmZxsSwwL0nNnV1syiCCC"
 +
-        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
-        
"i6Sy6nXOcUIOZWJ9BVJf4A27Pa4Pi7ZFznFnIdiQOrxCbb2ZCVkCftWsmcEMnXWXUkGOuA5JXo9YvGyPGq2wgO1wj"
 +
-        
"qAKyqxhBVOL48L2D0PYU16Ursxe0ckoBYXJheQi2d1eIa0pTD78325f8jCHclqINvuvj0GZfJENlc1e"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"EMN2VHLtoHQDfXVOVDXnE1rK3cDJRMhCIvIRmywkA5T9GchtDVfek2qZq1H5wfe92RoXBseAuMoWtTCJiXOJraCxmj"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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"
 +
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,"",
-        
"tLsQ1gYWPF1geDalS5MdWfpDvF5MaeJMd2fK0m3jui7xY1IfuSxqZs7SEL6wUVGdWc5tsVroCMMy6Nqjdz5T4vW");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternContains.match(), 1);
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,"",
-        "ABCDEF");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternContains.match(), 0);
+    setDrillBuf(wideString);
 
-    // non ascii
-    sb.setLength(0);
-    sb.append("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, "", 
"tLsQ1gYWPF1geDalS5MdWfpDvF5MaeJMd2fK0m3jui7xY1IfuSxqZs7SEL6wUVGdWc5tsVroCMMy6Nqjdz5T4vW");
+    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), drillBuf));
 
-    assertEquals(sqlPatternContains.match(), 0); // should not match
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, "", "ABCDEF");
+    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(0, sqlPatternContains.match(0, byteBuffer.limit(), drillBuf));
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,"", "¶T¤¤¤ß");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternContains.match(), 1); // should match
+    // non ascii
+    setDrillBuf("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    assertEquals(0, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf)); // should not match
 
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, "", 
"¶T¤¤¤ß");
+    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternContains.match(0, byteBuffer.limit(), 
drillBuf)); // should match
   }
 
   @Test
   public void testSqlPatternConstant() {
-    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT,"ABC.*", "ABC");
-
-    StringBuffer sb = new StringBuffer("ABC");
-    SqlPatternMatcher sqlPatternContains = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo, sb);
+    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT, "ABC.*", "ABC");
+    SqlPatternMatcher sqlPatternConstant = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    assertEquals(1, sqlPatternContains.match());  // ABC should match ABC
+    setDrillBuf("ABC");
+    assertEquals(1, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf));  // ABC should match ABC
 
-    sb.setLength(0);
-    sb.append("BC");
-    assertEquals(0, sqlPatternContains.match());  // ABC not same as BC
+    setDrillBuf("BC");
+    assertEquals(0, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf));  // ABC not same as BC
 
-    sb.setLength(0);
-    assertEquals(0, sqlPatternContains.match());  // null string not same as 
ABC
+    setDrillBuf("");
+    assertEquals(0, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf));  // null string not same as ABC
 
-    sb.append("DE");
-    assertEquals(0, sqlPatternContains.match());  // ABC not same as DE
+    setDrillBuf("DE");
+    assertEquals(0, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf));  // ABC not same as DE
 
     // null pattern should match null string
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT,"", "");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    sb.setLength(0);
-    assertEquals(sqlPatternContains.match(), 1); // null text should match 
null pattern
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT, "", "");
+    sqlPatternConstant = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    // wide character string.
-    
sb.append("b00dUrA0oa2i4ZEHg6zvPXPXlVQYB2BXe8T5gIEtvUDzcN6yUkIqyS07gaAy8k4" +
-        
"ac6Bn1cxblsXFnkp8g8hiQkUMJPyl6l0jTdsIzQ4PkVCURGGyF0aduGqCXUaKp91gqkRMvL" +
-        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
-        
"hHhmrHdEb22QN20dXEHSygR7vrb2zZhhfWeJbXRsesuYDqdGig801IAS6VWRIdQtJ6gaRhCdNz" +
-        " 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
-        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
-        "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
-        "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
-        "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
-        "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
-        "JhhjcxwoafBRyyEvQ6Pfhg8IqJ0afBpAZHhR2y4I11zbaJZqs3WG3H3aQHT" +
-        
"wcPHdBHnk65GdL3Njuoo0K4mcmN6lk7pWptHwTjkw59zTw834PZ8TWm5XiUnsi9JKy41MPqHcbO0nN"
 +
-        "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
-        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
-        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
-        
"KUxMqNCPx6PABXCPocpfXJa0yBT0l3ssgMlDfKsxAHX6aEC86zk0CDmTqZPmBjLAoYaHA3" +
-        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
-        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
-        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
-        "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" 
+
-        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
-        
"bKT7SucjEZJ00WBF9FlJp6v8OcVvMBjRriaYYjVlOiLvVDQQ2NvYfbv5bLbEhkrJi5Nlg" +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"zTgrtT6fcxpAfcFeTct7FNd4BjzbNCgBrSspzhxnEFMZXuqBGaOS9d9qcuUulwF0lAWGBauWI57qyjXfQnQ"
 +
-        
"i6Sy6nXOcUIOZWJ9BVJf4A27Pa4Pi7ZFznFnIdiQOrxCbb2ZCVkCftWsmcEMnXWXUkGOuA5JXo9YvGyPGq2wgO1wj"
 +
-        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
-        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
-        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
-        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
-        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
-        
"YtBFj3a5LtAhTy5BnN2v1XlTQtk6MZ0Ej6g7sW96w9n2XV8wqdWGgjeKHaqH7Pn1XFw7IHvpVYK4wFvIGubp4bpms"
 +
-        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
-        
"CTtiZv12uCj0WILSesMc5ct2tQcIvwnOHAuE6fw7lD8EgQ0emU4zxUIDowhTvJ46k27rXTctIX7HlBEZXInV9r49"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"iuqmJS71Xq4j56K35TmCJCb4jAAbcGTGEHzcCP1HKVFfsNnLqwflvHwMYQMA3EumrMn1nXnETZFdZJRHlnO8dwgnT"
 +
-        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
-        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
-        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"
 +
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS,"", sb.toString());
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-
-    assertEquals(sqlPatternContains.match(), 1);
+    setDrillBuf("");
+    assertEquals(1, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf)); // null text should match null pattern
 
-    // non ascii
-    sb.setLength(0);
-    sb.append("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    // wide character string.
+    setDrillBuf(wideString);
 
-    assertEquals(sqlPatternContains.match(), 0); // should not match
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONTAINS, "", wideString);
+    sqlPatternConstant = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternConstant.match(0, byteBuffer.limit(), drillBuf));
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT,"", 
"¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
-    sqlPatternContains = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternContains.match(), 1); // should match
+    // non ascii
+    setDrillBuf("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    assertEquals(0, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf));  // should not match
 
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.CONSTANT, "", 
"¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    sqlPatternConstant = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternConstant.match(0, byteBuffer.limit(), 
drillBuf)); // should match
   }
 
   @Test
-  public void testSqlPatternNotSimple() {
-    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX,"A.*BC.*", "");
+  public void testSqlPatternComplex() {
+    RegexpUtil.SqlPatternInfo patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX, "A.*BC.*", "");
+    SqlPatternMatcher sqlPatternComplex = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo);
 
-    StringBuffer sb = new StringBuffer("ADEBCDF");
-    SqlPatternMatcher sqlPatternComplex = 
SqlPatternFactory.getSqlPatternMatcher(patternInfo, sb);
+    setDrillBuf("ABCDEF");
+    assertEquals(1, sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf)); 
 // ADEBCDF should match A.*BC.*
 
-    assertEquals(sqlPatternComplex.match(), 1);  // ADEBCDF should match 
A.*BC.*
+    setDrillBuf("BC");
+    assertEquals(0, sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf)); 
 // BC should not match A.*BC.*
 
-    sb.setLength(0);
-    sb.append("BC");
-    assertEquals(sqlPatternComplex.match(), 0);  // BC should not match A.*BC.*
+    setDrillBuf("");
+    assertEquals(sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf), 0); 
 // null string should not match
 
-    sb.setLength(0);
-    assertEquals(sqlPatternComplex.match(), 0);  // null string should not 
match
-
-    sb.append("DEFGHIJ");
-    assertEquals(sqlPatternComplex.match(), 0);  // DEFGHIJ should not match 
A.*BC.*
+    setDrillBuf("DEFGHIJ");
+    assertEquals(sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf), 0); 
// DEFGHIJ should not match A.*BC.*
 
     java.util.regex.Matcher matcher;
     matcher = java.util.regex.Pattern.compile("b00dUrA0.*").matcher("");
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX,"b00dUrA0.*42.*9a8BZ",
 "");
-    sb.setLength(0);
-    // wide character string.
-    
sb.append("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
-        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
-        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
-        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
-        " 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
-        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
-        "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
-        "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
-        "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
-        "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
-        "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
-        "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
-        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
-        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
-        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
-        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
-        
"lSnjhieVJ7H0FYjcsihjQryhyRwUZBGxWFuh0hI9rOv8h5jHKb549hOHPcIjSdLa6M048G" +
-        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
-        "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" 
+
-        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
-        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
-        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
-        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
-        
"FZbYTp5ZxtXCrudDSX3kaeLtCstfqAHGsjHkPd87aSNaJJjPaSaMmGo7zTJGUIX1VCA2KJP37USIAa5NGHtM"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"EMN2VHLtoHQDfXVOVDXnE1rK3cDJRMhCIvIRmywkA5T9GchtDVfek2qZq1H5wfe92RoXBseAuMoWtTCJiXOJraCxmj"
 +
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        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
-        
"iuqmJS71Xq4j56K35TmCJCb4jAAbcGTGEHzcCP1HKVFfsNnLqwflvHwMYQMA3EumrMn1nXnETZFdZJRHlnO8dwgnT"
 +
-        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
-        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
-        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"
 +
-        "AFyMJ4kLsONE52kZsJYYyDpWw9a8BZ");
-
-    sqlPatternComplex = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternComplex.match(), 1);
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX, 
"b00dUrA0.*42.*9a8BZ", "");
 
-    // non ascii
-    sb.setLength(0);
-    sb.append("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    // wide character string.
+    setDrillBuf(wideString);
 
-    assertEquals(sqlPatternComplex.match(), 0); // should not match
+    sqlPatternComplex = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf));
 
-    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX,".*»Ú®i¶T¤¤¤.*¼Ó®i.*ÆU2~~",
 "");
-    sqlPatternComplex = SqlPatternFactory.getSqlPatternMatcher(patternInfo, 
sb);
-    assertEquals(sqlPatternComplex.match(), 1); // should match
+    // non ascii
+    setDrillBuf("¤EÀsÆW°ê»Ú®i¶T¤¤¤ß3¼Ó®i¶TÆU2~~");
+    assertEquals(0, sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf)); 
// DEFGHIJ should not match A.*BC.*
 
+    patternInfo = new 
RegexpUtil.SqlPatternInfo(RegexpUtil.SqlPatternType.COMPLEX, 
".*»Ú®i¶T¤¤¤.*¼Ó®i.*ÆU2~~", "");
+    sqlPatternComplex = SqlPatternFactory.getSqlPatternMatcher(patternInfo);
+    assertEquals(1, sqlPatternComplex.match(0, byteBuffer.limit(), drillBuf)); 
// should match
   }
 
+  @After
+  public void cleanup() {
+    drillBuf.close();
+    allocator.close();
+  }
 }
+

http://git-wip-us.apache.org/repos/asf/drill/blob/df95709a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
index 4249af6..a8a69e1 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java
@@ -1113,6 +1113,155 @@ public class TestStringFunctions extends BaseTestQuery {
         .build()
         .run();
 
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'ab'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%ab'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'ab%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%ab%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'abc'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'abc%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%abc'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%abc%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'abcd'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like 'abcd%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%abcd'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%abcd%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like ''")
+        .unOrdered()
+        .baselineColumns("id")
+        .expectsEmptyResultSet()
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
+
+    testBuilder()
+        .sqlQuery(" SELECT  id FROM (" +
+            "VALUES('abc')) tbl(id)" +
+            "where id like '%%'")
+        .unOrdered()
+        .baselineColumns("id")
+        .baselineValues("abc")
+        .build()
+        .run();
   }
 
   @Test

Reply via email to