List of usage examples for com.google.common.hash HashFunction hashUnencodedChars
HashCode hashUnencodedChars(CharSequence input);
From source file:io.prestosql.plugin.hive.statistics.MetastoreHiveStatisticsProvider.java
@VisibleForTesting static List<HivePartition> getPartitionsSample(List<HivePartition> partitions, int sampleSize) { checkArgument(sampleSize > 0, "sampleSize is expected to be greater than zero"); if (partitions.size() <= sampleSize) { return partitions; }// w ww . j a v a2s. c o m List<HivePartition> result = new ArrayList<>(); int samplesLeft = sampleSize; HivePartition min = partitions.get(0); HivePartition max = partitions.get(0); for (HivePartition partition : partitions) { if (partition.getPartitionId().compareTo(min.getPartitionId()) < 0) { min = partition; } else if (partition.getPartitionId().compareTo(max.getPartitionId()) > 0) { max = partition; } } result.add(min); samplesLeft--; if (samplesLeft > 0) { result.add(max); samplesLeft--; } if (samplesLeft > 0) { HashFunction hashFunction = murmur3_128(); Comparator<Map.Entry<HivePartition, Long>> hashComparator = Comparator.<Map.Entry<HivePartition, Long>, Long>comparing( Map.Entry::getValue).thenComparing(entry -> entry.getKey().getPartitionId()); partitions.stream().filter(partition -> !result.contains(partition)) .map(partition -> immutableEntry(partition, hashFunction.hashUnencodedChars(partition.getPartitionId()).asLong())) .sorted(hashComparator).limit(samplesLeft).forEachOrdered(entry -> result.add(entry.getKey())); } return unmodifiableList(result); }