static List<String> getPartitionsSample(List<String> partitions, int sampleSize) {
        checkArgument(sampleSize > 0, "sampleSize is expected to be greater than zero");

        if (partitions.size() <= sampleSize) {
            return partitions;
        }

        List<String> result = new ArrayList<>();
        int left = sampleSize;
        String min = partitions.get(0);
        String max = partitions.get(0);
        for (String partition : partitions) {
            if (partition.compareTo(min) < 0) {
                min = partition;
            } else if (partition.compareTo(max) > 0) {
                max = partition;
            }
        }

        result.add(min);
        left--;
        if (left > 0) {
            result.add(max);
            left--;
        }

        if (left > 0) {
            HashFunction hashFunction = Hashing.murmur3_128();
            Comparator<Map.Entry<String, Long>> hashComparator = Map.Entry.<String, Long>comparingByValue()
                    .thenComparing(Map.Entry::getKey);

            partitions.stream()
                    .filter(partition -> !result.contains(partition))
                    .map(partition -> immutableEntry(partition, hashFunction.hashUnencodedChars(partition).asLong()))
                    .sorted(hashComparator)
                    .limit(left)
                    .forEachOrdered(entry -> result.add(entry.getKey()));
        }
        return Lists.newArrayList(result);
    }
@Test
    public void testSamplePartitoins() {
        List<String> partitionNames = Lists.newArrayList("k=1", "k=2", "k=3", "k=4", "k=5");
        List<String> sampledPartitions = HiveStatisticsProvider.getPartitionsSample(partitionNames, 3);
        Assert.assertEquals(3, sampledPartitions.size());
        Assert.assertTrue(sampledPartitions.contains("k=1"));
        Assert.assertTrue(sampledPartitions.contains("k=5"));
    }