private CTEClause findCTEFromName(QB qb, String cteName, Map<String, CTEClause> aliasToCTEs) {
    StringBuilder qId = new StringBuilder();
    if (qb.getId() != null) {
      qId.append(qb.getId());
    }

    while (qId.length() > 0) {
      String nm = qId + ":" + cteName;
      CTEClause cte = aliasToCTEs.get(nm);
      if (cte != null) {
        return cte;
      }
      int lastIndex = qId.lastIndexOf(":");
      lastIndex = lastIndex < 0 ? 0 : lastIndex;
      qId.setLength(lastIndex);
    }
    return aliasToCTEs.get(cteName);
  }
Goes though the tabref tree and finds the alias for the table. Once found,
it records the table name-> alias association in aliasToTabs. It also makes
an association from the alias to the table AST in parse info.

@return the alias of the table
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java