@Override
  protected void doAlteration(Table table, Partition partition) throws HiveException {
    if (partition != null) {
      if (partition.getBucketCount() == desc.getNumberOfBuckets()) {
        return;
      }
      partition.setBucketCount(desc.getNumberOfBuckets());
    } else {
      if (table.getNumBuckets() == desc.getNumberOfBuckets()) {
        return;
      }
      table.setNumBuckets(desc.getNumberOfBuckets());
    }
  }
Operation process of setting the number of buckets.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/storage/cluster/AlterTableIntoBucketsOperation.java