public static Properties getSchemaWithoutCols(StorageDescriptor sd,
                                                Map<String, String> parameters, String databaseName, String tableName,
                                                List<FieldSchema> partitionKeys) {
    Properties schema = new Properties();
    String inputFormat = sd.getInputFormat();
    if (inputFormat == null || inputFormat.length() == 0) {
      inputFormat = org.apache.hadoop.mapred.SequenceFileInputFormat.class
          .getName();
    }
    schema.setProperty(
        org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.FILE_INPUT_FORMAT,
        inputFormat);
    String outputFormat = sd.getOutputFormat();
    if (outputFormat == null || outputFormat.length() == 0) {
      outputFormat = org.apache.hadoop.mapred.SequenceFileOutputFormat.class
          .getName();
    }
    schema.setProperty(
        org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.FILE_OUTPUT_FORMAT,
        outputFormat);

    schema.setProperty(
        org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_NAME,
        databaseName + "." + tableName);

    if (sd.getLocation() != null) {
      schema.setProperty(
          org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_LOCATION,
          sd.getLocation());
    }
    int bucket_cnt = sd.getNumBuckets();
    if (bucket_cnt > 0) {
      schema.setProperty(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.BUCKET_COUNT,
          Integer.toString(bucket_cnt));
    }

    if (sd.getBucketCols() != null && sd.getBucketCols().size() > 0) {
      schema.setProperty(
          org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.BUCKET_FIELD_NAME,
        Joiner.on(",").join(sd.getBucketCols()));
    }
    if (sd.getSerdeInfo() != null) {
      for (Map.Entry<String,String> param : sd.getSerdeInfo().getParameters().entrySet()) {
        schema.put(param.getKey(), (param.getValue() != null) ? param.getValue() : StringUtils.EMPTY);
      }

      if (sd.getSerdeInfo().getSerializationLib() != null) {
        schema.setProperty(ColumnType.SERIALIZATION_LIB, sd .getSerdeInfo().getSerializationLib());
      }
    }

    if (partitionKeys != null) {
      String partString = StringUtils.EMPTY;
      String partStringSep = StringUtils.EMPTY;
      String partTypesString = StringUtils.EMPTY;
      String partTypesStringSep = StringUtils.EMPTY;
      for (FieldSchema partKey : partitionKeys) {
        partString = partString.concat(partStringSep);
        partString = partString.concat(partKey.getName());
        partTypesString = partTypesString.concat(partTypesStringSep);
        partTypesString = partTypesString.concat(partKey.getType());
        if (partStringSep.length() == 0) {
          partStringSep = "/";
          partTypesStringSep = ":";
        }
      }
      if (partString.length() > 0) {
        schema
            .setProperty(
                org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_PARTITION_COLUMNS,
                partString);
        schema
            .setProperty(
                org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_PARTITION_COLUMN_TYPES,
                partTypesString);
      }
    }

    if (parameters != null) {
      for (Map.Entry<String, String> e : parameters.entrySet()) {
        // add non-null parameters to the schema
        String key = e.getKey();
        if (!StatsSetupConst.COLUMN_STATS_ACCURATE.equals(key) &&
            !hive_metastoreConstants.DDL_TIME.equals(key) &&
            !StatsSetupConst.TOTAL_SIZE.equals(key) &&
            !StatsSetupConst.RAW_DATA_SIZE.equals(key) &&
            !StatsSetupConst.NUM_FILES.equals(key) &&
            !StatsSetupConst.ROW_COUNT.equals(key) && e.getValue() != null) {
          schema.setProperty(e.getKey(), e.getValue());
        }
      }
    }

    return schema;
  }
Get partition level schema from table level schema.
This function will use the same column names, column types and partition keys for
each partition Properties. Their values are copied from the table Properties. This
is mainly to save CPU and memory. CPU is saved because the first time the
StorageDescriptor column names are accessed, JDO needs to execute a SQL query to
retrieve the data. If we know the data will be the same as the table level schema
and they are immutable, we should just reuse the table level schema objects.

@param sd The Partition level Storage Descriptor.
@param parameters partition level parameters
@param tblSchema The table level schema from which this partition should be copied.
@return the properties
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java