private void addExtendedTableData(DataOutputStream out, Table table, Partition partition) throws IOException {
    if (partition != null) {
      out.write(("Detailed Partition Information").getBytes(StandardCharsets.UTF_8));
      out.write(Utilities.tabCode);
      out.write(partition.getTPartition().toString().getBytes(StandardCharsets.UTF_8));
      out.write(Utilities.tabCode);
      out.write(Utilities.newLineCode); // comment column is empty
    } else {
      out.write(("Detailed Table Information").getBytes(StandardCharsets.UTF_8));
      out.write(Utilities.tabCode);
      String tableDesc = HiveStringUtils.escapeJava(table.getTTable().toString());
      out.write(tableDesc.getBytes(StandardCharsets.UTF_8));
      out.write(Utilities.tabCode);
      out.write(Utilities.newLineCode); // comment column is empty
    }
  }
Formats DESC TABLE results to text format.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/formatter/TextDescTableFormatter.java