private Partition convertPartitionSpecToMetaPartition(Table table,
      AlterTableAddPartitionDesc.PartitionDesc partitionSpec) throws HiveException {
    Path location = partitionSpec.getLocation() != null ? new Path(table.getPath(), partitionSpec.getLocation()) : null;
    if (location != null) {
      // Ensure that it is a full qualified path (in most cases it will be since tbl.getPath() is full qualified)
      location = new Path(Utilities.getQualifiedPath(context.getConf(), location));
    }

    Partition partition = org.apache.hadoop.hive.ql.metadata.Partition.createMetaPartitionObject(
        table, partitionSpec.getPartSpec(), location);

    if (partitionSpec.getPartParams() != null) {
      partition.setParameters(partitionSpec.getPartParams());
    }
    if (partitionSpec.getInputFormat() != null) {
      partition.getSd().setInputFormat(partitionSpec.getInputFormat());
    }
    if (partitionSpec.getOutputFormat() != null) {
      partition.getSd().setOutputFormat(partitionSpec.getOutputFormat());
    }
    if (partitionSpec.getNumBuckets() != -1) {
      partition.getSd().setNumBuckets(partitionSpec.getNumBuckets());
    }
    if (partitionSpec.getCols() != null) {
      partition.getSd().setCols(partitionSpec.getCols());
    }
    if (partitionSpec.getSerializationLib() != null) {
      partition.getSd().getSerdeInfo().setSerializationLib(partitionSpec.getSerializationLib());
    }
    if (partitionSpec.getSerdeParams() != null) {
      partition.getSd().getSerdeInfo().setParameters(partitionSpec.getSerdeParams());
    }
    if (partitionSpec.getBucketCols() != null) {
      partition.getSd().setBucketCols(partitionSpec.getBucketCols());
    }
    if (partitionSpec.getSortCols() != null) {
      partition.getSd().setSortCols(partitionSpec.getSortCols());
    }
    if (partitionSpec.getColStats() != null) {
      partition.setColStats(partitionSpec.getColStats());

      ColumnStatistics statistics = partition.getColStats();
      if (statistics != null && statistics.getEngine() == null) {
        statistics.setEngine(org.apache.hadoop.hive.conf.Constants.HIVE_ENGINE);
      }
      // Statistics will have an associated write Id for a transactional table. We need it to update column statistics.
      partition.setWriteId(partitionSpec.getWriteId());
    }
    return partition;
  }
Operation process of adding a partition to a table.
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/partition/add/AlterTableAddPartitionOperation.java