private void getMmBucketing(StringBuilder query) {
    if (sourceTab != null) {
      boolean isFirst;
      List<String> buckCols = sourceTab.getSd().getBucketCols();
      if (!buckCols.isEmpty()) {
        query.append("CLUSTERED BY (").append(StringUtils.join(buckCols, ",")).append(") ");
        List<Order> sortCols = sourceTab.getSd().getSortCols();
        if (!sortCols.isEmpty()) {
          query.append("SORTED BY (");
          isFirst = true;
          for (Order sortCol : sortCols) {
            if (!isFirst) {
              query.append(", ");
            }
            isFirst = false;
            query.append(sortCol.getCol()).append(" ").append(DirectionUtils.codeToText(sortCol.getOrder()));
          }
          query.append(") ");
        }
        query.append("INTO ").append(sourceTab.getSd().getNumBuckets()).append(" BUCKETS");
      }
    }
  }
Part of Create operation. Copy source table bucketing for insert-only compaction.
ql/src/java/org/apache/hadoop/hive/ql/txn/compactor/CompactionQueryBuilderForInsertOnly.java