public static TableName getQualifiedTableName(ASTNode tabNameNode, String catalogName) throws SemanticException {
    if (tabNameNode.getType() != HiveParser.TOK_TABNAME || (tabNameNode.getChildCount() != 1
        && tabNameNode.getChildCount() != 2 && tabNameNode.getChildCount() != 3)) {
      throw new SemanticException(ASTErrorUtils.getMsg(
          ErrorMsg.INVALID_TABLE_NAME.getMsg(), tabNameNode));
    }

    if (tabNameNode.getChildCount() == 3) {
      final String dbName = unescapeIdentifier(tabNameNode.getChild(0).getText());
      final String tableName = unescapeIdentifier(tabNameNode.getChild(1).getText());
      final String tableMetaRef = unescapeIdentifier(tabNameNode.getChild(2).getText());
      return HiveTableName.fromString(tableName, catalogName, dbName, tableMetaRef);
    }

    if (tabNameNode.getChildCount() == 2) {
      final String dbName = unescapeIdentifier(tabNameNode.getChild(0).getText());
      final String tableName = unescapeIdentifier(tabNameNode.getChild(1).getText());
      if (dbName.contains(".") || tableName.contains(".")) {
        throw new SemanticException(ASTErrorUtils.getMsg(
            ErrorMsg.OBJECTNAME_CONTAINS_DOT.getMsg(), tabNameNode));
      }
      return HiveTableName.ofNullable(tableName, dbName);
    }
    final String tableName = unescapeIdentifier(tabNameNode.getChild(0).getText());
    if (tableName.contains(".")) {
      throw new SemanticException(ASTErrorUtils.getMsg(
          ErrorMsg.OBJECTNAME_CONTAINS_DOT.getMsg(), tabNameNode));
    }
    return HiveTableName.ofNullable(tableName);
  }
Get the name reference of a DB table node.
@param tabNameNode
@param catalogName the catalog of the DB/object
@return a {@link TableName}, not null. The catalog will be missing from this.
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java