@Override
  public void analyzeInternal(ASTNode root) throws SemanticException {
    ctx.setResFile(ctx.getLocalTmpPath());

    ASTNode tableTypeExpr = (ASTNode) root.getChild(0);

    TableName tableName = getQualifiedTableName((ASTNode)tableTypeExpr.getChild(0));
    // if database is not the one currently using validate database
    if (tableName.getDb() != null) {
      db.validateDatabaseExists(tableName.getDb());
    }
    Table table = getTable(tableName);

    // process the second child, if exists, node to get partition spec(s)
    Map<String, String> partitionSpec = getPartitionSpec(db, tableTypeExpr, tableName);
    if (partitionSpec != null) {
      // validate that partition exists
      PartitionUtils.getPartition(db, table, partitionSpec, true);
    }

    // process the third child node,if exists, to get partition spec(s)
    String columnPath = getColumnPath(tableTypeExpr, tableName, partitionSpec);

    boolean showColStats = false;
    boolean isFormatted = false;
    boolean isExt = false;
    if (root.getChildCount() == 2) {
      int descOptions = root.getChild(1).getType();
      isFormatted = descOptions == HiveParser.KW_FORMATTED;
      isExt = descOptions == HiveParser.KW_EXTENDED;
      // in case of "DESCRIBE FORMATTED tablename column_name" statement, colPath will contain tablename.column_name.
      // If column_name is not specified colPath will be equal to tableName.
      // This is how we can differentiate if we are describing a table or column.
      if (columnPath != null && isFormatted) {
        showColStats = true;
      }
    }

    inputs.add(new ReadEntity(table));

    DescTableDesc desc = new DescTableDesc(ctx.getResFile(), tableName, partitionSpec, columnPath, isExt, isFormatted);
    Task<?> task = TaskFactory.get(new DDLWork(getInputs(), getOutputs(), desc));
    rootTasks.add(task);

    task.setFetchSource(true);
    String schema = showColStats ? DescTableDesc.COLUMN_STATISTICS_SCHEMA : DescTableDesc.SCHEMA;
    setFetchTask(createFetchTask(schema));
  }
Analyzer for table describing commands.

A query like this will generate a tree as follows
  "describe formatted default.maptable partition (b=100) id;"
TOK_TABTYPE
  TOK_TABNAME --&gt; root for tablename, 2 child nodes mean DB specified
    default
    maptable
  TOK_PARTSPEC  --&gt; root node for partition spec. else columnName
    TOK_PARTVAL
      b
      100
  id           --&gt; root node for columnName
formatted
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/DescTableAnalyzer.java