private void parseSimplePattern(String likePattern) {
    int length = likePattern.length();
    int beginIndex = 0;
    int endIndex = length;
    char lastChar = 'a';
    String strPattern = new String();
    type = PatternType.NONE;

    for (int i = 0; i < length; i++) {
      char n = likePattern.charAt(i);
      if (n == '_') { // such as "a_b"
        if (lastChar != '\\') { // such as "a%bc"
          type = PatternType.COMPLEX;
          return;
        } else { // such as "abc\%de%"
          strPattern += likePattern.substring(beginIndex, i - 1);
          beginIndex = i;
        }
      } else if (n == '%') {
        if (i == 0) { // such as "%abc"
          type = PatternType.END;
          beginIndex = 1;
        } else if (i < length - 1) {
          if (lastChar != '\\') { // such as "a%bc"
            type = PatternType.COMPLEX;
            return;
          } else { // such as "abc\%de%"
            strPattern += likePattern.substring(beginIndex, i - 1);
            beginIndex = i;
          }
        } else {
          if (lastChar != '\\') {
            endIndex = length - 1;
            if (type == PatternType.END) { // such as "%abc%"
              type = PatternType.MIDDLE;
            } else {
              type = PatternType.BEGIN; // such as "abc%"
            }
          } else { // such as "abc\%"
            strPattern += likePattern.substring(beginIndex, i - 1);
            beginIndex = i;
            endIndex = length;
          }
        }
      }
      lastChar = n;
    }

    strPattern += likePattern.substring(beginIndex, endIndex);
    simplePattern.set(strPattern);
  }
Parses the likePattern. Based on it is a simple pattern or not, the
function might change two member variables. {@link #type} will be changed
to the corresponding pattern type; {@link #simplePattern} will record the
string in it for later pattern matching if it is a simple pattern.
<p>
Examples: <blockquote>

<pre>
parseSimplePattern("%abc%") changes {@link #type} to PatternType.MIDDLE
and changes {@link #simplePattern} to "abc"
parseSimplePattern("%ab_c%") changes {@link #type} to PatternType.COMPLEX
and does not change {@link #simplePattern}
</pre>

</blockquote>

@param likePattern
         the input LIKE query pattern
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFLike.java