private int costPatternWithORWildCardChar(Stack<Node> stack) throws SemanticException {
    int numElems = (stack != null ? stack.size() : 0);

    // No elements
    if (numElems == 0) {
      return -1;
    }

    // These DS are used to cache previously created String
    Map<Integer,String> cachedNames = new HashMap<Integer,String>();
    int maxDepth = numElems;
    int maxLength = 0;

    // For every pattern
    for (String pattern : patternORWildChar) {
      int patLen = pattern.length();

      // If the stack has been explored already till that level,
      // obtained cached String
      if (cachedNames.containsKey(patLen)) {
        if (pattern.contentEquals(cachedNames.get(patLen))) {
          return patLen;
        }
      } else if (maxLength >= patLen) {
        // We have already explored the stack deep enough, but
        // we do not have a matching
        continue;
      } else {
        // We are going to build the name
        StringBuilder name = new StringBuilder(patLen + numElems);
        if (maxLength != 0) {
          name.append(cachedNames.get(maxLength));
        }
        for (int pos = maxDepth - 1; pos >= 0; pos--) {
          String nodeName = stack.get(pos).getName() + "%";
          name.insert(0, nodeName);

          // We cache the values
          cachedNames.put(name.length(), name.toString());
          maxLength = name.length();
          maxDepth--;

          if (name.length() >= patLen) {
            if (pattern.contentEquals(name)) {
              return patLen;
            }
            break;
          }
        }
        
      }
    }
    return -1;
  }
This function returns the cost of the rule for the specified stack when the pattern
matched for has only OR wildcard character in it. The function expects patternORWildChar
to be not null.
@param stack
         Node stack encountered so far
@return cost of the function
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/lib/RuleRegExp.java