private void writeColumns(DataOutputStream outStream, List<FieldSchema> columns) throws IOException {
    TextMetaDataTable tmd = new TextMetaDataTable();
    for (FieldSchema fieldSchema : columns) {
      // For show Columns operation, we just need the column name.
      tmd.addRow(fieldSchema.getName());
    }

    // In case the query is served by HiveServer2, don't pad it with spaces,
    // as HiveServer2 output is consumed by JDBC/ODBC clients.
    boolean isOutputPadded = !SessionState.get().isHiveServerQuery();
    outStream.writeBytes(tmd.renderTable(isOutputPadded));
  }
Operation process of showing the columns.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/column/show/ShowColumnsOperation.java