@Override
  public int execute() throws HiveException {
    Table tbl = context.getDb().getTable(desc.getTabName());
    List<String> parts;
    if (!tbl.isPartitioned()) {
      context.getTask().setException(new HiveException(ErrorMsg.TABLE_NOT_PARTITIONED, desc.getTabName()));
      return ErrorMsg.TABLE_NOT_PARTITIONED.getErrorCode();
    } else if (desc.getCond() != null || desc.getOrder() != null) {
      parts = getPartitionNames(tbl);
    } else if (desc.getPartSpec() != null) {
      parts = context.getDb().getPartitionNames(tbl, desc.getPartSpec(), desc.getLimit());
    } else {
      parts = context.getDb().getPartitionNames(tbl, desc.getLimit());
    }

    // write the results in the file
    try (DataOutputStream outStream = ShowUtils.getOutputStream(new Path(desc.getResFile()), context)) {
      ShowPartitionsFormatter formatter = ShowPartitionsFormatter.getFormatter(context.getConf());
      formatter.showTablePartitions(outStream, parts);
    } catch (Exception e) {
      throw new HiveException(e, ErrorMsg.GENERIC_ERROR, "show partitions for table " + desc.getTabName());
    }

    return 0;
  }
Operation process of showing the partitions of a table.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/partition/show/ShowPartitionsOperation.java