@Override
  protected void analyzeCommand(TableName tableName, Map<String, String> partitionSpec, ASTNode command)
      throws SemanticException {
    AbstractAlterTableDesc desc;
    switch (command.getChild(0).getType()) {
    case HiveParser.TOK_NOT_CLUSTERED:
      desc = new AlterTableNotClusteredDesc(tableName, partitionSpec);
      break;
    case HiveParser.TOK_NOT_SORTED:
      desc = new AlterTableNotSortedDesc(tableName, partitionSpec);
      break;
    case HiveParser.TOK_ALTERTABLE_BUCKETS:
      ASTNode buckets = (ASTNode) command.getChild(0);
      List<String> bucketCols = getColumnNames((ASTNode) buckets.getChild(0));
      List<Order> sortCols = new ArrayList<Order>();
      int numBuckets = -1;
      if (buckets.getChildCount() == 2) {
        numBuckets = Integer.parseInt(buckets.getChild(1).getText());
      } else {
        sortCols = getColumnNamesOrder((ASTNode) buckets.getChild(1));
        numBuckets = Integer.parseInt(buckets.getChild(2).getText());
      }
      if (numBuckets <= 0) {
        throw new SemanticException(ErrorMsg.INVALID_BUCKET_NUMBER.getMsg());
      }

      desc = new AlterTableClusteredByDesc(tableName, partitionSpec, numBuckets, bucketCols, sortCols);
      break;
    default:
      throw new SemanticException("Invalid operation " + command.getChild(0).getType());
    }

    addInputsOutputsAlterTable(tableName, partitionSpec, desc, desc.getType(), false);
    rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), desc)));

    setAcidDdlDesc(getTable(tableName), desc);
  }
Analyzer for table cluster sort commands.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/storage/cluster/AlterTableClusterSortAnalyzer.java