@Override
  public int execute() throws HiveException {
    Map<String, String> partitionSpecs = desc.getPartitionSpecs();
    Table destTable = desc.getDestinationTable();
    Table sourceTable = desc.getSourceTable();

    List<Partition> partitions = context.getDb().exchangeTablePartitions(partitionSpecs, sourceTable.getDbName(),
        sourceTable.getTableName(), destTable.getDbName(), destTable.getTableName());
    for (Partition partition : partitions) {
      // Reuse the partition specs from dest partition since they should be the same
      context.getWork().getInputs().add(new ReadEntity(new Partition(sourceTable, partition.getSpec(), null)));

      DDLUtils.addIfAbsentByName(new WriteEntity(new Partition(sourceTable, partition.getSpec(), null),
          WriteEntity.WriteType.DELETE), context);

      DDLUtils.addIfAbsentByName(new WriteEntity(new Partition(destTable, partition.getSpec(), null),
          WriteEntity.WriteType.INSERT), context);
    }

    return 0;
  }
Operation process of exchanging some partitions between tables.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/partition/exchange/AlterTableExchangePartitionsOperation.java