private static UDFLikePattern matcher(String pattern) {
      UDFLikePattern lastType = NONE;
      int length = pattern.length();
      char lastChar = 0;

      for (int i = 0; i < length; i++) {
        char n = pattern.charAt(i);
        if (n == '_' && lastChar != '\\') { // such as "a_bc"
          return COMPLEX;
        } else if (n == '%') {
          if (i == 0) { // such as "%abc"
            lastType = END;
          } else if (i < length - 1) {
            if (lastChar != '\\') { // such as "a%bc"
              lastType = CHAINED;
            }
          } else {
            if (lastChar != '\\') {
              if (lastType == END) { // such as "%abc%"
                lastType = MIDDLE;
              } else if (lastType != CHAINED) {
                lastType = BEGIN; // such as "abc%"
              }
            }
          }
        }
        lastChar = n;
      }
      return lastType;
    }
Evaluate LIKE filter on a batch for a vector of strings.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/FilterStringColLikeStringScalar.java