private Optional<Partition> loadPartitionByName(HivePartitionName partitionName)
     throws Exception {
   requireNonNull(partitionName, "partitionName is null");
   try {
     return retry()
         .stopOn(NoSuchObjectException.class)
         .stopOnIllegalExceptions()
         .run(
             "getPartitionsByNames",
             stats
                 .getGetPartitionByName()
                 .wrap(
                     () -> {
                       try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
                         return Optional.of(
                             client.getPartitionByName(
                                 partitionName.getHiveTableName().getDatabaseName(),
                                 partitionName.getHiveTableName().getTableName(),
                                 partitionName.getPartitionName()));
                       }
                     }));
   } catch (NoSuchObjectException e) {
     return Optional.empty();
   } catch (TException e) {
     throw new PrestoException(HIVE_METASTORE_ERROR, e);
   }
 }
  private Map<HivePartitionName, Optional<Partition>> loadPartitionsByNames(
      Iterable<? extends HivePartitionName> partitionNames) throws Exception {
    requireNonNull(partitionNames, "partitionNames is null");
    checkArgument(!Iterables.isEmpty(partitionNames), "partitionNames is empty");

    HivePartitionName firstPartition = Iterables.get(partitionNames, 0);

    HiveTableName hiveTableName = firstPartition.getHiveTableName();
    String databaseName = hiveTableName.getDatabaseName();
    String tableName = hiveTableName.getTableName();

    List<String> partitionsToFetch = new ArrayList<>();
    for (HivePartitionName partitionName : partitionNames) {
      checkArgument(
          partitionName.getHiveTableName().equals(hiveTableName),
          "Expected table name %s but got %s",
          hiveTableName,
          partitionName.getHiveTableName());
      partitionsToFetch.add(partitionName.getPartitionName());
    }

    List<String> partitionColumnNames =
        ImmutableList.copyOf(
            Warehouse.makeSpecFromName(firstPartition.getPartitionName()).keySet());

    try {
      return retry()
          .stopOn(NoSuchObjectException.class)
          .stopOnIllegalExceptions()
          .run(
              "getPartitionsByNames",
              stats
                  .getGetPartitionsByNames()
                  .wrap(
                      () -> {
                        try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) {
                          ImmutableMap.Builder<HivePartitionName, Optional<Partition>> partitions =
                              ImmutableMap.builder();
                          for (Partition partition :
                              client.getPartitionsByNames(
                                  databaseName, tableName, partitionsToFetch)) {
                            String partitionId =
                                FileUtils.makePartName(
                                    partitionColumnNames, partition.getValues(), null);
                            partitions.put(
                                HivePartitionName.partition(databaseName, tableName, partitionId),
                                Optional.of(partition));
                          }
                          return partitions.build();
                        }
                      }));
    } catch (NoSuchObjectException e) {
      // assume none of the partitions in the batch are available
      return stream(partitionNames.spliterator(), false)
          .collect(toMap(identity(), (name) -> Optional.empty()));
    } catch (TException e) {
      throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
  }
  @Override
  public Optional<Map<String, Partition>> getPartitionsByNames(
      String databaseName, String tableName, List<String> partitionNames) {
    Iterable<HivePartitionName> names =
        transform(
            partitionNames, name -> HivePartitionName.partition(databaseName, tableName, name));

    ImmutableMap.Builder<String, Partition> partitionsByName = ImmutableMap.builder();
    Map<HivePartitionName, Optional<Partition>> all = getAll(partitionCache, names);
    for (Entry<HivePartitionName, Optional<Partition>> entry : all.entrySet()) {
      if (!entry.getValue().isPresent()) {
        return Optional.empty();
      }
      partitionsByName.put(entry.getKey().getPartitionName(), entry.getValue().get());
    }
    return Optional.of(partitionsByName.build());
  }
 @Override
 public Optional<Partition> getPartition(
     String databaseName, String tableName, String partitionName) {
   HivePartitionName name = HivePartitionName.partition(databaseName, tableName, partitionName);
   return get(partitionCache, name);
 }