public static List<String> getPartitionNames(Table table, Map<String, String> partSpecMap,
      boolean latestSpecOnly) throws SemanticException {
    Expression expression = IcebergTableUtil.generateExpressionFromPartitionSpec(
        table, partSpecMap, latestSpecOnly);
    PartitionsTable partitionsTable = (PartitionsTable) MetadataTableUtils.createMetadataTableInstance(
        table, MetadataTableType.PARTITIONS);

    try (CloseableIterable<FileScanTask> fileScanTasks = partitionsTable.newScan().planFiles()) {
      return FluentIterable.from(fileScanTasks)
          .transformAndConcat(task -> task.asDataTask().rows())
          .transform(row -> {
            StructLike data = row.get(IcebergTableUtil.PART_IDX, StructProjection.class);
            PartitionSpec spec = table.specs().get(row.get(IcebergTableUtil.SPEC_IDX, Integer.class));
            return Maps.immutableEntry(
                IcebergTableUtil.toPartitionData(
                    data, Partitioning.partitionType(table), spec.partitionType()),
                spec);
          }).filter(e -> {
            ResidualEvaluator resEval = ResidualEvaluator.of(e.getValue(),
                expression, false);
            return e.getValue().isPartitioned() &&
              resEval.residualFor(e.getKey()).isEquivalentTo(Expressions.alwaysTrue()) &&
              (e.getValue().specId() == table.spec().specId() || !latestSpecOnly);

          }).transform(e -> e.getValue().partitionToPath(e.getKey())).toSortedList(
            Comparator.naturalOrder());

    } catch (IOException e) {
      throw new SemanticException(
          String.format("Error while fetching the partitions due to: %s", e));
    }
  }
Returns a list of partition names satisfying the provided partition spec.
@param table Iceberg table
@param partSpecMap Partition Spec used as the criteria for filtering
@param latestSpecOnly when True, returns partitions with the current spec only, else - any specs
@return List of partition names
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java