public static String getPartitionName(Path tablePath, Path partitionPath, Set<String> partCols,
                                        Map<String, String> partitionColToTypeMap) {
    String result = null;
    Path currPath = partitionPath;
    LOG.debug("tablePath:" + tablePath + ", partCols: " + partCols);

    while (currPath != null && !tablePath.equals(currPath)) {
      // format: partition=p_val
      // Add only when table partition colName matches
      String[] parts = currPath.getName().split("=");
      if (parts.length > 0) {
        if (parts.length != 2) {
          LOG.warn(currPath.getName() + " is not a valid partition name");
          return result;
        }

        // Since hive stores partitions keys in lower case, if the hdfs path contains mixed case,
        // it should be converted to lower case
        String partitionName = parts[0].toLowerCase();
        // Do not convert the partitionValue to lowercase
        String partitionValue = parts[1];
        if (partCols.contains(partitionName)) {
          if (result == null) {
            result = partitionName + "="
                    + getNormalisedPartitionValue(partitionValue, partitionColToTypeMap.get(partitionName));
          } else {
            result = partitionName + "="
                    + getNormalisedPartitionValue(partitionValue, partitionColToTypeMap.get(partitionName))
                    + Path.SEPARATOR + result;
          }
        }
      }
      currPath = currPath.getParent();
      LOG.debug("currPath=" + currPath);
    }
    return result;
  }
Get the partition name from the path.

@param tablePath
         Path of the table.
@param partitionPath
         Path of the partition.
@param partCols
         Set of partition columns from table definition
@return Partition name, for example partitiondate=2008-01-01
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreServerUtils.java