protected boolean isAliased(ASTNode n) {
    switch (n.getType()) {
      case HiveParser.TOK_TABREF:
        return findTabRefIdxs(n)[0] != 0;
      case HiveParser.TOK_TABNAME:
        return false;
      case HiveParser.TOK_SUBQUERY:
        assert n.getChildCount() > 1 : "Expected Derived Table to be aliased";
        return true;
      default:
        throw raiseWrongType("TOK_TABREF|TOK_TABNAME", n);
    }
  }
This allows us to take an arbitrary ASTNode and turn it back into SQL that produced it without
needing to understand what it is (except for QuotedIdentifiers).
ql/src/java/org/apache/hadoop/hive/ql/parse/MergeSemanticAnalyzer.java