### Question:
HiveEndpoint { public PartitionsAndStatistics getPartitions(Table table, String partitionPredicate, int maxPartitions) throws TException { try (CloseableMetaStoreClient client = metaStoreClientSupplier.get()) { List<Partition> partitions = null; if (Strings.isNullOrEmpty(partitionPredicate)) { partitions = client.listPartitions(table.getDbName(), table.getTableName(), (short) maxPartitions); } else { partitions = client.listPartitionsByFilter(table.getDbName(), table.getTableName(), partitionPredicate, (short) maxPartitions); } List<String> partitionNames = getPartitionNames(table.getPartitionKeys(), partitions); List<String> columnNames = getColumnNames(table); Map<String, List<ColumnStatisticsObj>> statisticsByPartitionName = client .getPartitionColumnStatistics(table.getDbName(), table.getTableName(), partitionNames, columnNames); if (statisticsByPartitionName != null && !statisticsByPartitionName.isEmpty()) { log.debug("Retrieved column stats entries for {} partitions of table {}.{}", statisticsByPartitionName.size(), table.getDbName(), table.getTableName()); } else { log.debug("No partition column stats retrieved for table {}.{}", table.getDbName(), table.getTableName()); } return new PartitionsAndStatistics(table.getPartitionKeys(), partitions, statisticsByPartitionName); } } @Autowired  HiveEndpoint(String name, HiveConf hiveConf, Supplier<CloseableMetaStoreClient> metaStoreClientSupplier); String getName(); HiveConf getHiveConf(); String getMetaStoreUris(); Supplier<CloseableMetaStoreClient> getMetaStoreClientSupplier(); Database getDatabase(String database); Optional<Table> getTable(CloseableMetaStoreClient client, String database, String table); TableAndStatistics getTableAndStatistics(String database, String tableName); abstract TableAndStatistics getTableAndStatistics(TableReplication tableReplication); PartitionsAndStatistics getPartitions(Table table, String partitionPredicate, int maxPartitions);  }### Answer:
@Test public void getPartitions() throws Exception { List<Partition> filteredPartitions = Arrays.asList(partitionOneTwo); when(metaStoreClient.listPartitionsByFilter(DATABASE, TABLE, PARTITION_PREDICATE, (short) MAX_PARTITIONS)) .thenReturn(filteredPartitions); when(metaStoreClient.getPartitionColumnStatistics(DATABASE, TABLE, PARTITION_NAMES, COLUMN_NAMES)) .thenReturn(partitionStatsMap); PartitionsAndStatistics partitionsAndStatistics = hiveEndpoint.getPartitions(table, PARTITION_PREDICATE, MAX_PARTITIONS); assertThat(partitionsAndStatistics.getPartitions(), is(filteredPartitions)); assertThat(partitionsAndStatistics.getStatisticsForPartition(partitionOneTwo), is(partitionColumnStatistics)); }
@Test public void getPartitionsWithoutFilter() throws Exception { when(metaStoreClient.listPartitions(DATABASE, TABLE, (short) MAX_PARTITIONS)).thenReturn(partitions); when(metaStoreClient.getPartitionColumnStatistics(DATABASE, TABLE, PARTITION_NAMES, COLUMN_NAMES)) .thenReturn(partitionStatsMap); PartitionsAndStatistics partitionsAndStatistics = hiveEndpoint.getPartitions(table, null, MAX_PARTITIONS); assertThat(partitionsAndStatistics.getPartitions(), is(partitions)); }
@Test public void getPartitionsNoStats() throws Exception { List<Partition> filteredPartitions = Arrays.asList(partitionOneTwo); when(metaStoreClient.listPartitionsByFilter(DATABASE, TABLE, PARTITION_PREDICATE, (short) MAX_PARTITIONS)) .thenReturn(filteredPartitions); when(metaStoreClient.getPartitionColumnStatistics(DATABASE, TABLE, PARTITION_NAMES, COLUMN_NAMES)) .thenReturn(Collections.<String, List<ColumnStatisticsObj>> emptyMap()); PartitionsAndStatistics partitionsAndStatistics = hiveEndpoint.getPartitions(table, PARTITION_PREDICATE, MAX_PARTITIONS); assertThat(partitionsAndStatistics.getPartitions(), is(filteredPartitions)); assertThat(partitionsAndStatistics.getStatisticsForPartition(partitionOneTwo), is(nullValue())); }