@Override
  public int cost(Stack<Node> stack) throws SemanticException {
    int numElems = (stack != null ? stack.size() : 0);
    if (numElems != pattern.length) {
      return -1;
    }
    for (int pos = numElems - 1; pos >= 0; pos--) {
      if(!stack.get(pos).getName().equals(pattern[pos])) {
        return -1;
      }
    }
    return numElems;
  }
This function returns the cost of the rule for the specified stack. Returns 1 if there is
an exact match with the entire stack, otherwise -1

If any proper substack of the stack matches it will return -1.  It only returns 1 if the
entire stack matches the rule exactly.

@param stack
         Node stack encountered so far
@return cost of the function
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/lib/RuleExactMatch.java